Page 1 of 2

Motion trail

Posted: Tue Apr 20, 2004 12:33 pm
by Luke923
While I was researching something else, I came across a really CHEAP way to create a really, really simple motion trail. Below is the code for said trail:

Code: Select all

if(TPlayer->bJumping || TPlayer->bRunning)//if we run & jump, show a motion trail
{
     for(u16 b = 1; b < 5; b++)//5 is the number of trailers created
     {
          SceneMgr->getMeshManipulator()->setVertexColorAlpha
	(PlayerMesh->getMesh(TPlayer->MeshNode->getFrameNr()),(s32)255/(b*5));
	TPlayer->MeshNode->render();
     }
}
else     //set the Alpha back to full if you're not running or jumping
     SceneMgr->getMeshManipulator()->setVertexColorAlpha
          (PlayerMesh->getMesh(TPlayer->MeshNode->getFrameNr()),255);
The way the code works is by making multiple calls to IAnimatedSceneNode->render(), while each time decrementing the vertex alpha. Place this immediately following beginScene() for best results.

Honestly, I personally have little to no use for it, but I think it is pretty cool. Plus, I figured someone out there might get some use out of it. The code may require some tweaking, but the basics are here for a decent motion trail. However, don't expect anything like Gaussian Blur.

Anyways, have fun with it, y'all, and feel free to ask if you have any questions.

Posted: Fri Jul 02, 2004 11:25 pm
by Evil Mr Sock
What is TPlayer?

Posted: Sun Aug 22, 2004 11:20 am
by Peter Müller
I think it's his player class, defined with typedef form CPlayer;

Posted: Mon Aug 23, 2004 1:43 am
by cmoibenlepro
interesting. :wink:

I wanted to create this effect... I will try your code but I don't fully understand it...

what's TPlayer exactly?

Can you post full source?

Posted: Tue Feb 20, 2007 8:39 am
by m_krzywy
we don't have u're player class i'm also interested in this effect :)

Posted: Wed Feb 21, 2007 7:48 am
by messen
Hi,

I think TPlayer is

Code: Select all

class TPlayer : public ISceneNode
{
public:
 bool bJumping;
 bool bRunning;
.
.
.
};
The render() is in the ISceneNode class.

Posted: Mon Mar 19, 2007 10:37 am
by jingquan
Do you have any idea how to do this in .NET? I really want this feature badly.

Posted: Wed May 09, 2007 6:01 am
by nomis
Hi there,

I'm trying to implement this into my game but can't seem to get it working, we currently have:

create the object and the mesh

Code: Select all

	IAnimatedMesh* bananaMesh = smgr->getMesh("files/models/banana.ms3d");
	bananaNode = smgr->addAnimatedMeshSceneNode( bananaMesh );

	IMesh* bmesh = smgr->getMesh("files/models/apple.ms3d");
when boost is on, create instances and do alpha to create blur

Code: Select all

		if(boostOn)//if we boost, show a motion trail
		{
			 for(u16 b = 1; b < 5; b++)//5 is the number of trailers created
			 {
				smgr->getMeshManipulator()->setVertexColorAlpha(smgr->getMesh(0),(s32)255/(b*5));
				bananaNode->render();
			 }
		}
		else     //set the Alpha back to full if you're not boosting
			 smgr->getMeshManipulator()->setVertexColorAlpha(smgr->getMesh(0),255); 
I'm getting the following error:
main.cpp(312) : error C2440: 'initializing' : cannot convert from 'class irr::scene::IAnimatedMesh *' to 'class irr::scene::IMesh *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
main.cpp(425) : error C2664: 'setVertexColorAlpha' : cannot convert parameter 1 from 'class irr::scene::IAnimatedMesh *' to 'class irr::scene::IMesh *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
main.cpp(430) : error C2664: 'setVertexColorAlpha' : cannot convert parameter 1 from 'class irr::scene::IAnimatedMesh *' to 'class irr::scene::IMesh *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
We can't figure out how to create an iMesh that is not animated so we can set the alpha etc..

Or alternatively is there a way to set the alpha on an animated mesh?


Thank you for your time,

Nomis.

Posted: Wed May 09, 2007 6:21 am
by Dances
just remove the word animated from all of the calls for that mesh and you should have the equivalent non animated calls.

Posted: Wed May 09, 2007 7:15 am
by nomis
Dances wrote:just remove the word animated from all of the calls for that mesh and you should have the equivalent non animated calls.
I've tried that:

Code: Select all

IMesh* bmesh = smgr->getMesh("files/models/apple.ms3d");

Code: Select all

if(boostOn)//if we boost, show a motion trail
		{
			 for(u16 b = 1; b < 5; b++)//5 is the number of trailers created
			 {
				smgr->getMeshManipulator()->setVertexColorAlpha(smgr->getMesh(1),(s32)255/(b*5));
				bmesh->render();
			 }
		}
		else     //set the Alpha back to full if you're not boosting
			 smgr->getMeshManipulator()->setVertexColorAlpha(smgr->getMesh(1),255); 

still the same errors :(

Code: Select all

Compiling...
main.cpp
main.cpp(312) : error C2440: 'initializing' : cannot convert from 'class irr::scene::IAnimatedMesh *' to 'class irr::scene::IMesh *'
        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
main.cpp(425) : error C2664: 'setVertexColorAlpha' : cannot convert parameter 1 from 'class irr::scene::IAnimatedMesh *' to 'class irr::scene::IMesh *'
        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
main.cpp(426) : error C2039: 'render' : is not a member of 'IMesh'
        c:\irrlicht-1.2\include\imesh.h(19) : see declaration of 'IMesh'
main.cpp(430) : error C2664: 'setVertexColorAlpha' : cannot convert parameter 1 from 'class irr::scene::IAnimatedMesh *' to 'class irr::scene::IMesh *'
        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast

Posted: Wed May 09, 2007 2:07 pm
by BlindSide
Just cast it to an animated mesh (IAnimatedMesh* bmesh), or call bmesh as an animated mesh.

Posted: Wed May 09, 2007 2:43 pm
by nomis
The error message says "cannot convert from 'class irr::scene::IAnimatedMesh *' to 'class irr::scene::IMesh *'" so we need to make it a non animated mesh >_< i'm just not sure how.. have tried everything.

Posted: Thu May 10, 2007 9:19 am
by SirLino
well, there's a IAnimatedMesh::getMesh(frame : int) or sth like that. could help ;)

Posted: Tue May 15, 2007 6:37 am
by m_krzywy
bump :) wanna some motion trail too :)

Posted: Thu Jul 19, 2007 4:02 am
by koller202
i error too

help me please !
________
New Jersey Medical Marijuana Dispensary