Camera problem

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.
Post Reply
alejolp
Posts: 3
Joined: Sat Jul 23, 2005 12:28 am

Camera problem

Post 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.
<< Insert Signature Here >>
Midnight
Posts: 1772
Joined: Fri Jul 02, 2004 2:37 pm
Location: Wonderland

Post 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!
DexteR
Posts: 15
Joined: Mon Jul 18, 2005 1:52 am
Location: @ Kernel32.DLL

Post 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
AnimaKomix: A Half-3D Packer & Animator
http://www.freewebs.com/project_z/
alejolp
Posts: 3
Joined: Sat Jul 23, 2005 12:28 am

Post 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
<< Insert Signature Here >>
Post Reply