Page 1 of 1

3rd Person view

Posted: Tue Jun 21, 2005 5:57 pm
by Daniel
Can someone please show me how to add/use a 3rd person camera view on a character?

Posted: Wed Jun 22, 2005 10:40 am
by after-life
1) use setTarget to set your player as the target the camera is looking at
2) then: use sin,cos stuff to set the height, ...
3) make it so that in the event receiver it can rotate the camera and zoom in/out
4) update the camera location every time the player moves or the camera is rotated (do 1 and 2)


AND CHECK THE FORUM

Posted: Wed Jun 22, 2005 10:00 pm
by mrweet
virtual void irr::scene::ICameraSceneNode::setTarget ( const core::vector3df & pos ) [pure virtual]

It says your supposed to replace the pos with what you want the camera to look at. What would you put in there though?

Posted: Thu Jun 23, 2005 5:53 am
by after-life
here is some code:

Code: Select all

position2d<f32> RelMousePos = device->getCursorControl()->getRelativePosition();         
if(RelMousePos.X >= 0.8)
{
    float rotation = (RelMousePos.X-0.8)*10;
    fAngleX += rotation;
    if(fAngleX >= 360)
         fAngleX = 0;
}
if(RelMousePos.X <= 0.2)
{             
float rotation = (0.2-RelMousePos.X)*10;
fAngleX -= rotation;
if(fAngleX <= 0)
    fAngleX = 360;
}
if(RelMousePos.Y >= 0.8)
{
    float rotation = (RelMousePos.Y-0.8)*10;
    fAngleY -= rotation;
    if(fAngleY <= 20)
        fAngleY = 20;
}
if(RelMousePos.Y <= 0.2)
{
    float rotation = (0.2-RelMousePos.Y)*10;
    fAngleY += rotation;
    if(fAngleY >= 75)
         fAngleY = 75;
}

vector3df CameraPos;
ICameraSceneNode* camera = smgr->getActiveCamera();
float fXZDistance = CameraDistance*cos(PI*(fAngleY/180));
CameraPos.Y = playerpos.Y + CameraDistance*sin(PI*(fAngleY/180));
CameraPos.X = playerpos.X + cos(PI*(fAngleX/180))*fXZDistance;
CameraPos.Z = playerpos.Z + sin(PI*(fAngleX/180))*fXZDistance;
camera->setPosition(CameraPos);
camera->setTarget(vector3df(playerpos.X,playerpos.Y,playerpos.Z));
CameraDistance is a float which shoul be adjustable by scrolling (im not going to explain that part).
All the rest should be obvious.
You can adjust a few things (the rotation and stuff) for example: the camera is now facing the feet of the player, you can adjust it by doing:

camera->setTarget(vector3df(playerpos.X,playerpos.Y+20,playerpos.Z));