FollowSplineAnimator

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Panos
Posts: 14
Joined: Wed Jan 17, 2007 6:00 pm

FollowSplineAnimator

Post by Panos »

Hi guys!!!

I am new with Irrlicht(I use jirr) and I have a problem with FollowSplineSimulator.

I give the pts tha Sydney must go and the animator works fine but when Sydney reaches the end of my path goes back again and again.

What can I do???

Thanks
zeno60
Posts: 342
Joined: Sun May 21, 2006 2:48 am
Location: NC, USA
Contact:

Post by zeno60 »

Store your last point in a vector, then use an update to test your models getPosition(). Use a distance formulate to check if the distance from model to point is < 1.0 or some value, if so, remove the animator?
Panos
Posts: 14
Joined: Wed Jan 17, 2007 6:00 pm

Post by Panos »

So let's say that anim is my ISceneNodeAnimator and anms my IAnimatedMeshSceneNode.

I use this but obviously it's wrong.

Code: Select all

vector3df a = new vector3df(40,0,100);
anim=smgr.createFollowSplineAnimator(0,vec,0.3f,0.5f);
anms.addAnimator(anim);
anim.drop();
vector3df b = anms.getPosition();
if(b.getDistanceFrom(a)<= 1.0f)
   anms.removeAnimator(anim);

zeno60
Posts: 342
Joined: Sun May 21, 2006 2:48 am
Location: NC, USA
Contact:

Post by zeno60 »

Sort of, but the b.getDistanceFrom(a) <= 1.0f will have to be updated with each device loop.

Not used Jirr so i'm not sure how that works, but you should have a main loop with your begin() and end() etc. Put:

if(b.getDistanceFrom(a)<= 1.0f)
anms.removeAnimator(anim);

Within this loop somewhere.
Panos
Posts: 14
Joined: Wed Jan 17, 2007 6:00 pm

Post by Panos »

zeno60 wrote:Sort of, but the b.getDistanceFrom(a) <= 1.0f will have to be updated with each device loop.

Not used Jirr so i'm not sure how that works, but you should have a main loop with your begin() and end() etc. Put:

if(b.getDistanceFrom(a)<= 1.0f)
anms.removeAnimator(anim);

Within this loop somewhere.
Yes you are right.

I placed the check in device.run loop and it works.

I have another question.

Is it possible to make the camera position follow a spline animator and make the camera look at another spline too???

Thanks !!!
zeno60
Posts: 342
Joined: Sun May 21, 2006 2:48 am
Location: NC, USA
Contact:

Post by zeno60 »

It should be, but will take a bit more work, but I have done something similar:

I had my camera on a simple line animator, and its target on a bigger line animator.

First set up an invisible object, like a cubeSceneNode (testSceneNode?) and make it invisible. Then add your main animator to this object which will be where you want your camera to look at.

Now set your camera up on its own animator to have the camera move, then again in the device loop, use the camera's setTarget() method to point to the position of the invisible box (box->getPosition()) and combined with the distance thing above, should work out.
Panos
Posts: 14
Joined: Wed Jan 17, 2007 6:00 pm

Post by Panos »

Everything seems to work fine but I have one more problem.

I want Sydney face the direction she moves.How can it be done?Using a rotation animator???

Thanks again zeno60
Java rules!!!
harukiblue
Posts: 49
Joined: Sun Dec 10, 2006 6:23 pm

I may have an Idea that might work

Post by harukiblue »

OK this might work!

you could create another invisible object on the same spline as sydney, but just slightly ahead of her (in the direction of the spline you would like her to face) then in the update loop to get the vector position of the invisible box, and use this to calculate the rotation vector for the ISceneNode->setRotation(const core::vector3df & rotation ). I am not sure how you would calculate the rotation vector from sydney's current vector position and the invisible box's object currect vector posistion. I am sure someone could help us though! Anyone good at vector math?
MasterBaker
Posts: 7
Joined: Fri Nov 24, 2006 6:13 pm

Post by MasterBaker »

Simple solution similar to the one suggested by harukiblue - with no vector knowledge whatsoever needed!

1 - Create an empty scene node.
2 - Assign your spline animator to the empty scene node.
3 - Create a CameraSceneNode.
4 - Create Sydney and assign the cameraSceneNode as her parent. From now on Sydney will follow the camera wherever it goes!
5 - Assign your spline animator to the camera - but with a slight delay, so that the empty scene node goes ahead first.
6 - Now the magic trick : Use the cameraSceneNode's "setTarget" function to make the camera (and sydney) "look" at the empty scene node that's moving ahead of them.

Voilà! sydney will be pointed in the right direction. You could use the same spline twice, or two splines if you want a more precise control.

I Saw this in another thread here. Now this might not be the most efficient way to do this, but hey, it works for me!

cheers!

MasterBaker
harukiblue
Posts: 49
Joined: Sun Dec 10, 2006 6:23 pm

for more help

Post by harukiblue »

here is a post on the issue in further detail
Panos
Posts: 14
Joined: Wed Jan 17, 2007 6:00 pm

Post by Panos »

So I can create an invisible object-attach to it the same spline animator as Sydney and then use this

Code: Select all

void faceTarget(irr::core::vector3df targetPos) {
  core::vector3df nodePos = targetPos - myNode->getPosition();
  myRotation.Y = atan(nodePos.Z/nodePos.X) * (180.0f / irr::core::PI);
  if((targetPos.X - myNode->getPosition().X) > 0) {
    myRotation.Y = 90 - myRotation.Y;
  } else if((targetPos.X - myNode->getPosition().X) < 0) {
    myRotation.Y = -90 - myRotation.Y;
  }
  myRotation.Y -= 90;
  myNode->setRotation(myRotation);
} 
(in java of course :) )

with targetPos the position of the invisible object,right???
Java rules!!!
MasterBaker
Posts: 7
Joined: Fri Nov 24, 2006 6:13 pm

Post by MasterBaker »

Yup, that should work.

If i get the chance i'll run both methods to see which one is the most efficient - probably the faceTarget one will be better than the camerascenenode...

I'm also having a problem you don't have : In my case my real camera follows sydney (instead of sydney following an empty scene node). This has an unpleasant side effect : When my spline turns too sharply (say, a 90 degrees turn) my camera gets very up close and personnal with sydney! I'll need to find a way to keep the distance between the camera and sydney fixed on the spline.

To be continued!
Panos
Posts: 14
Joined: Wed Jan 17, 2007 6:00 pm

Post by Panos »

I will try both solutions to see which one works better...then I will post the results... :wink:
Java rules!!!
Panos
Posts: 14
Joined: Wed Jan 17, 2007 6:00 pm

Post by Panos »

Well the faceTarget doesn't work correctly for me with this simple spline

Code: Select all

		vec2.push_front(new vector3df(0, 0,200));
		vec2.push_front(new vector3df(-200, 0,0));
		vec2.push_front(new vector3df(0, 0,-200));
		vec2.push_front(new vector3df(200, 0,0));
I am trying to fix it.
Java rules!!!
Panos
Posts: 14
Joined: Wed Jan 17, 2007 6:00 pm

Post by Panos »

MasterBaker I tried your method but sth goes wrong:

Code: Select all

		ISceneNode n = smgr.addEmptySceneNode();
		n.addAnimator(smgr.createFollowSplineAnimator(0,vecciv,0.2f,0.2f));
		ICameraSceneNode tmp = smgr.addCameraSceneNode(null);
		
		IAnimatedMeshSceneNode anms = smgr.addAnimatedMeshSceneNode(smgr.getMesh("media/civil/tris.md2"));
		anms.setParent(tmp);
		anms.setMaterialFlag(E_MATERIAL_FLAG.EMF_LIGHTING, false);
		anms.setMD2Animation("walk");
		anms.setMaterialTexture(0, driver.getTexture("media/civil/civi.jpg"));
		tmp.addAnimator(smgr.createFollowSplineAnimator(15,vecciv,0.2f,0.2f));
		tmp.setTarget(n.getPosition());
		
		smgr.addCameraSceneNode(null,new vector3df(0,0,300), new vector3df(0,0,0), -1);
Can you help?

Thanks
Java rules!!!
Post Reply