camera face forward during an animator

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.
liger13
Posts: 119
Joined: Tue Jul 18, 2006 4:17 am

camera face forward during an animator

Post by liger13 »

Iam currently using the following code to create a camera and have it fly through my scene:

Code: Select all

	scene::ICameraSceneNode * mainCam = smgr->addCameraSceneNode(0, vector3df(0,0,0), vector3df(0,0,0));	
	
	core::array<irr::core::vector3df> camPath; 
	camPath.push_back(core::vector3df(500, -60, 630));
	camPath.push_back(core::vector3df(640, -60, 285));
	camPath.push_back(core::vector3df(430, -60, 80));
	camPath.push_back(core::vector3df(130, -60, -105));
	camPath.push_back(core::vector3df(-270, -60, -90));
	camPath.push_back(core::vector3df(-430, -60, 220));
	camPath.push_back(core::vector3df(-220, -60, 603));
	camPath.push_back(core::vector3df(220, -60, 640));
	camPath.push_back(core::vector3df(500, -60, 630));

	if (mainCam)
	{	
		scene::ISceneNodeAnimator * anim = smgr->createFollowSplineAnimator(0,camPath,.3,1);
		mainCam->addAnimator(anim);
		anim->drop();
	}
the problem is, is that it continually looks at the position 0,0,0.
I want to be able to have the camera face forward, towards the next point in the spline. is there a way todo this?
JonLT
Posts: 152
Joined: Thu Mar 15, 2007 5:47 pm
Location: Denmark

Post by JonLT »

you could continuously check where the camera is and set the camera target to be the next point in the spline. This will make the camera look in the direction of the next point. Something like this:

Code: Select all

s32 pointCount = 0;
if(cam->getPosition() == camPath[pointCount])
{
  cam->setTarget(camPath[pointCount+1];
  pointCount++;
}
This code has to be in the main loop. Exept the declaration of pointCount.
I don't know if the camera ever actually has exactly the same position as the path point? Try it out if it doesn't work, then the if line is the one tou need to look at (I guess).

Hope that helped! :)
Halan
Posts: 447
Joined: Tue Oct 04, 2005 8:17 pm
Location: Germany, Freak City
Contact:

Post by Halan »

maybe its possible to write an animator for the target?

greets,
halan
liger13
Posts: 119
Joined: Tue Jul 18, 2006 4:17 am

Post by liger13 »

thnx for the reply, ill try those ideas out.


edit:
JonLT,
i cant seem to get this to work well. even if i set the tightness of the spline to 0, that if statement wont fire. i then went to calculate the amount times the mainLoop needed to go in order to change the target position. The result of this created rigid transitions.


halan,
Although i see no way in irrlicht todo this, i suppose one could manually create another spline and manually shift through it in the mainLoop. but i am totaly new to calculating splines so any help in that area would be apreciated.
JonLT
Posts: 152
Joined: Thu Mar 15, 2007 5:47 pm
Location: Denmark

Post by JonLT »

no i didn't really expect it to work. How about comparing the current possition to a previous position? Something like this:

Code: Select all

while(device->run())
{
  vector3df prevPos = cam->getPosition();

  driver->beginScene(.....);
  smgr->drawAll();
  driver->endScene();

  vector3df currPos = cam->getPosition();
  cam->setTarget(currPos - prevPos);
}
You might need to play a little aound with it, perhaps it should be
(prevPos - currPos) in stead?
liger13
Posts: 119
Joined: Tue Jul 18, 2006 4:17 am

Post by liger13 »

(correct me if im wrong) but that wouldnt work, because if u subtracted one from the other, they are so close that it would still come around to about (0,0,0). If one was able to get a vector from the camera's current position, towards its last position, then u could just flip it. Maybe that would work, but im very new to vectors so im not sure.
Dorth
Posts: 931
Joined: Sat May 26, 2007 11:03 pm

Post by Dorth »

...
...
...
Seriously...
Just place a dummy node on the same path animator, but make it go more or less ahead of your camera, depending on how much you want it to anticipate turns, then each turn update the camera's target position to the dummy node's position...

(I know I abuse of "..." in this post, but this whole thread is leaving me quite perplexed ;) )
liger13
Posts: 119
Joined: Tue Jul 18, 2006 4:17 am

Post by liger13 »

but make it go more or less ahead of your camera
and thats what has me perplexed...
omar shaaban
Posts: 616
Joined: Wed Nov 01, 2006 6:26 pm
Location: Cairo,Egypt
Contact:

Post by omar shaaban »

liger13 wrote:
but make it go more or less ahead of your camera
and thats what has me perplexed...
ya :lol:
anyway if u want your camera to move and look forward then all u have to do is to set the target forward to the camera position .
so the camera target will be like that:

Code: Select all

vector3df * campos=maincam->getpostion();
//camera movement code>>
campos.Z+=10
campos.X+=10
maincam->setpostion(campos)
test it :wink:
Dorth
Posts: 931
Joined: Sat May 26, 2007 11:03 pm

Post by Dorth »

That is assuming the path is always facing the same direction, which is not the case.

Remember this?:
core::array<irr::core::vector3df> camPath;
camPath.push_back(core::vector3df(500, -60, 630));
camPath.push_back(core::vector3df(640, -60, 285));
camPath.push_back(core::vector3df(430, -60, 80));
camPath.push_back(core::vector3df(130, -60, -105));
camPath.push_back(core::vector3df(-270, -60, -90));
camPath.push_back(core::vector3df(-430, -60, 220));
camPath.push_back(core::vector3df(-220, -60, 603));
camPath.push_back(core::vector3df(220, -60, 640));
camPath.push_back(core::vector3df(500, -60, 630));

Just create a dummy node, apply the same path BUT change the startTime to whatever offset suits your need. THEN, each update loop, update the target to the dummy position.

Warning: If you let the animator loop and the end point is not the start point, the camera will jerk at the end of the path. You may thus want to create another path just for the dummy.

Warning 2: If it doesn't loop, then it will also likely do a weird effect toward the end. Again, creating another path should solve it (or stop the animation before the time left in it is as small as the offset by which you modified the dummy.
liger13
Posts: 119
Joined: Tue Jul 18, 2006 4:17 am

Post by liger13 »

BUT change the startTime
U dont have to repeat your self over and over. I just cant find a "startTime" change method? maybe i missed something obvious.

I tried to:

Code: Select all

dummyAnim->animateNode(cameraTargetDummy, 5000);
but im guessing it doesnt just run the animator for the "5000" millisecs to displace the node.
Dorth
Posts: 931
Joined: Sat May 26, 2007 11:03 pm

Post by Dorth »

Oy, what's the first argument of this function:

Code: Select all

scene::ISceneNodeAnimator * anim = smgr->createFollowSplineAnimator(0,camPath,.3,1); 
liger13
Posts: 119
Joined: Tue Jul 18, 2006 4:17 am

Post by liger13 »

:shock: .... i cant beleive... it... :shock:
thnx, not quite sure how i missed that...
omar shaaban
Posts: 616
Joined: Wed Nov 01, 2006 6:26 pm
Location: Cairo,Egypt
Contact:

Post by omar shaaban »

missed what!? this code iss written above in your code so how did u messed it!?
Dances
Posts: 454
Joined: Sat Jul 02, 2005 1:45 am
Location: Canada
Contact:

Post by Dances »

Omar, you avatar is suiting. You are such a troll.
Post Reply