Follow Cam for Ageia PhysX

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
Slaine
Posts: 120
Joined: Fri May 04, 2007 12:28 pm

Follow Cam for Ageia PhysX

Post by Slaine »

Hi there, I'm having trouble setting up a chase/follow cam for Irrlicht using Ageia PhysX, I've tried several different methods but all with the same problem, the camera shakes, or jitters? And I think it's to do with the targeting onto the PhysX node?

I have tried searching on here but hardly any results? :?

Here is the latest code I've tried:

Code: Select all

void 
FollowCamera::Update() 
{
    if(!cam || !m_pTargetNode) return;
   
    irr::core::vector3df currTargetPos = m_pTargetNode->getPosition();

    //if too far away, move camera closer
    irr::core::vector3df camToTarg = currTargetPos - cam->getPosition() ;
   
    //leash is only in the X-Z plane, so only count distance using X and Z
    irr::core::vector2df xzDist( camToTarg.X, camToTarg.Z );
   
    if(xzDist.getLength() > m_leash) { //need to move closer
        //camToTarg = irr::core::vector3df( xzDist.X, 0, xzDist.Y);
        //camToTarg = camToTarg.normalize() * m_speed;
		irr::core::vector3df camToTargOrig = irr::core::vector3df( xzDist.X, 0, xzDist.Y);
         camToTarg = camToTargOrig.normalize() * (camToTargOrig.getLength() - m_leash);
       
        //set X-Z position
        cam->setPosition( cam->getPosition() + camToTarg ); //move closer
		cam->updateAbsolutePosition();
       
        //set Y position
        irr::f32 h_tolerance = m_height / 10;  //the ammount of leway given to how close we need to be to the right height
        irr::f32 h_delta = cam->getPosition().Y - currTargetPos.Y + m_height; //distance from prefered height position
        if( cam->getPosition().Y < ( currTargetPos.Y + m_height) - h_tolerance) {
               
                cam->setPosition( irr::core::vector3df( cam->getPosition().X, cam->getPosition().Y + h_delta/2, cam->getPosition().Z) );
				cam->updateAbsolutePosition();
        }else if( cam->getPosition().Y > ( currTargetPos.Y + m_height) + h_tolerance ) {
                cam->setPosition( irr::core::vector3df( cam->getPosition().X, cam->getPosition().Y - h_delta/2, cam->getPosition().Z) );
				cam->updateAbsolutePosition();
        }
    }
   
    cam->setTarget( currTargetPos ); //look at Target position
    lastTargetPos = currTargetPos;
}
Many Thanks.
Post Reply