Page 1 of 1

Camera problem

Posted: Sat Jul 23, 2005 1:49 am
by alejolp
Greetings!!

I'm having a really annoying problem with a camera. I'm trying to do a really simple third person "game", but the camera seems to be "failing". I tried the the third person camera from the FAQ ( this one ) but it is more than what i need, so i reduced it to:

Code: Select all

void followingCamera::Update() {
  core::vector3df currTargetPos = m_pTargetNode->getPosition();
  m_cam->setPosition( currTargetPos + rotacion );
  m_cam->setTarget( currTargetPos ); //look at Target position
}


Where "rotacion" is a vector to set the rotation and height of the camera:

Code: Select all

void followingCamera::Rotate(irr::f64 angle) {
  rotacion = core::vector3df(m_leash, m_height, 0); 
  rotacion.rotateXZBy( angle, core::vector3df(0, 0, 0) );
}
Simple. The camera always follows the Target Node in a fixed distance. Every frame, the followingCamera::Update() is called to update the camera position. Then, to update the position of the target object i call the setPosition method:

Code: Select all

  core::vector3df newPos = target->getPosition() + 
      core::vector3df(( keys[KEY_KEY_S] ? 30.0f : -30.0f), 0, 0);
  target->setPosition( newPos ); 
The rendering loop looks like this:

Code: Select all

while(device->run())
{
  // Check Keys

  g_cam->Update(); 

  driver->beginScene(true, true, video::SColor(255,113,113,133));
  smgr->drawAll();
  driver->endScene();

  Sleep(250); // Limit to ~4 FPS
}
And produces something like this:

Click here

But when i move the target node (the one the camera follows), for 1 frame the camera get this position:

Click here

I've no idea what's going on, it seems that the camera target gets updated in the next frame, but the cam position remains the same for that frame and gets update in the other frame, producing a "bounce" effect.

From here you can download a Windows EXE (Irrlicht 0.11, the DLL is not in the rar):

http://www.angra.alejolp.com.ar/IRR/Pru ... -NoDLL.rar


Thanks in advance,
Alejandro.

Posted: Sat Jul 23, 2005 6:51 am
by Midnight
Could be a bug in Irrlicht..or in your code.

If you show me the source I "may" be able to tell you more.

sry no quick fix for ya.

Good Luck!

Posted: Sat Jul 23, 2005 3:37 pm
by DexteR
// Might wanna try this, I also use 3rd Person cam on my game
// Hope it will help.

--------------------------------------------------------------------

Code: Select all

 
.
.
.
.


   vector3df zNullVector  	(0,0,0); 
   vector3df zCAM_Trans	( zCAM_Distance ,0 ,0 );
   //
   zCAM_Trans.rotateXYBy	( -zCAM_AngleZ, zNullVector );
   zCAM_Trans.rotateXZBy	(  zCAM_AngleY, zNullVector );
   //
   zCAM_Active->setTarget	( zCAM_Target->getPosition() );
   zCAM_Active->setPosition	( zCAM_Target->getPosition()+zCAM_Trans);


}//End of routine ZAnimateCam3P

Posted: Sat Jul 23, 2005 7:40 pm
by alejolp
Thanks for the answers!

I replaced the setPosition call to a nicer and smoother way of moving the node using FlyStraightAnimator (but commented out to show my original problem). The code is right here and as you can see is a real mess; sorry about that.

Code guide in lines:
118, Cam::Update() definition.
129, Cam::Rotate(f64) def
392, SceneNode::setPosition call
409, the Cam::Update() call.
439, Sleep() call to limit FPS. At high FPS the problem becomes difficult to spot.


Good luck :D