FollowSplineAnimator
FollowSplineAnimator
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
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
So let's say that anim is my ISceneNodeAnimator and anms my IAnimatedMeshSceneNode.
I use this but obviously it's wrong.
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);
Yes you are right.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.
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 !!!
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.
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.
-
- Posts: 49
- Joined: Sun Dec 10, 2006 6:23 pm
I may have an Idea that might work
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?
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?
-
- Posts: 7
- Joined: Fri Nov 24, 2006 6:13 pm
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
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
-
- Posts: 49
- Joined: Sun Dec 10, 2006 6:23 pm
for more help
here is a post on the issue in further detail
So I can create an invisible object-attach to it the same spline animator as Sydney and then use this
(in java of course )
with targetPos the position of the invisible object,right???
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);
}
with targetPos the position of the invisible object,right???
Java rules!!!
-
- Posts: 7
- Joined: Fri Nov 24, 2006 6:13 pm
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!
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!
Well the faceTarget doesn't work correctly for me with this simple spline
I am trying to fix it.
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));
Java rules!!!
MasterBaker I tried your method but sth goes wrong:
Can you help?
Thanks
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);
Thanks
Java rules!!!