Taking a look around at all the 3rd person camera classes, I have decided to make an easier way to implement a 3rd person camera, just by changing some code, and adding some in. Firstly, change the camera to a normal camera, like this:
Code: Select all
camera = sm->addCameraSceneNode(0, core::vector3df(0.0f,0.0f,0.0f) , core::vector3df(0.0f,0.0f,0.0f), -1);
Code: Select all
float direction;
float zdirection;
Code: Select all
direction(0), zdirection(0)
Code: Select all
void moveCameraControl();
Code: Select all
void CGame::moveCameraControl()
{
core::position2d<f32> cursorPos = device->getCursorControl()->getRelativePosition();
scene::ICameraSceneNode* camera = device->getSceneManager()->getActiveCamera();
core::vector3df cameraPos = camera->getAbsolutePosition();
float change_x = ( cursorPos.X - 0.5 ) * 256.0f;
float change_y = ( cursorPos.Y - 0.5 ) * 256.0f;
direction += change_x;
zdirection -= change_y;
if( zdirection <- 90 )
zdirection = -90;
else
if( zdirection > 90 )
zdirection = 90;
device->getCursorControl()->setPosition( 0.5f, 0.5f );
core::vector3df playerPos = [PLAYERNODE]->getPosition();
float xf = playerPos.X - cos( direction * PI / 180.0f ) * 64.0f;
float yf = playerPos.Y - sin( zdirection * PI / 180.0f ) * 64.0f;
float zf = playerPos.Z + sin( direction * PI / 180.0f ) * 64.0f;
camera->setPosition( core::vector3df( xf, yf, zf ) );
camera->setTarget( core::vector3df( playerPos.X, playerPos.Y+25.0f, playerPos.Z ) );
[PLAYERNODE]->setRotation( core::vector3df( 0, direction, 0 ) );
}
Code: Select all
moveCameraControl();
NOTE: Here i use "zdirection" instead of "ydirection" because I got this code from a GameMaker 6.1 Game I wrote, and I forgot to change it
Any questions, just ask.