Motion trail

A forum to store posts deemed exceptionally wise and useful
Luke923
Posts: 59
Joined: Wed Nov 05, 2003 5:26 am

Motion trail

Post 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.
"Object-oriented programming is an exceptionally bad idea which could only have originated in California."
- E.W. Dijkstra
Evil Mr Sock
Posts: 37
Joined: Fri Jul 02, 2004 5:36 pm
Location: Albany, NY
Contact:

Post by Evil Mr Sock »

What is TPlayer?
------------------------------------------
A monkey poured coffee in my boots.
------------------------------------------
Peter Müller
Posts: 292
Joined: Sun Mar 14, 2004 5:28 pm
Location: Germany
Contact:

Post by Peter Müller »

I think it's his player class, defined with typedef form CPlayer;
http://www.games-forge.de - Die Community für Nachwuchsprogrammierer
cmoibenlepro
Posts: 237
Joined: Thu May 27, 2004 3:18 pm
Location: Canada

Post 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?
m_krzywy
Posts: 133
Joined: Sat Nov 04, 2006 2:05 pm

Post by m_krzywy »

we don't have u're player class i'm also interested in this effect :)
messen
Posts: 25
Joined: Tue Aug 29, 2006 2:51 pm
Location: Agalon
Contact:

Post 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.
jingquan
Posts: 222
Joined: Sun Aug 20, 2006 4:10 am
Contact:

Post by jingquan »

Do you have any idea how to do this in .NET? I really want this feature badly.
nomis
Posts: 14
Joined: Wed May 09, 2007 5:54 am

Post 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.
Dances
Posts: 454
Joined: Sat Jul 02, 2005 1:45 am
Location: Canada
Contact:

Post by Dances »

just remove the word animated from all of the calls for that mesh and you should have the equivalent non animated calls.
nomis
Posts: 14
Joined: Wed May 09, 2007 5:54 am

Post 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
BlindSide
Admin
Posts: 2821
Joined: Thu Dec 08, 2005 9:09 am
Location: NZ!

Post by BlindSide »

Just cast it to an animated mesh (IAnimatedMesh* bmesh), or call bmesh as an animated mesh.
nomis
Posts: 14
Joined: Wed May 09, 2007 5:54 am

Post 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.
SirLino
Posts: 3
Joined: Thu Sep 22, 2005 7:09 pm
Location: Minden, Westf. (DE)
Contact:

Post by SirLino »

well, there's a IAnimatedMesh::getMesh(frame : int) or sth like that. could help ;)
m_krzywy
Posts: 133
Joined: Sat Nov 04, 2006 2:05 pm

Post by m_krzywy »

bump :) wanna some motion trail too :)
koller202
Posts: 143
Joined: Tue May 08, 2007 4:53 am
Location: Thailand

Post by koller202 »

i error too

help me please !
________
New Jersey Medical Marijuana Dispensary
Last edited by koller202 on Thu Feb 17, 2011 1:11 am, edited 1 time in total.
Post Reply