Independent Camera Rotation

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
TrueVincent
Posts: 2
Joined: Sun Dec 03, 2006 9:14 pm

Independent Camera Rotation

Post by TrueVincent »

Is there a way to rotate the camera independently like the FPS camera. I tried using the setRotation() function, but it didn't work.
TheC
Posts: 93
Joined: Fri May 05, 2006 7:50 am

Post by TheC »

I use the FPS camera, but disable controls :)
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

Using setTarget() is the general way of rotation a camera. the vector3df passed to setTarget is the point in 3D space at which you want your camera to point. So if you want to rotate the camera just imagine it's inside a sphere and calculate the point on the sphere you wish to look at according to the desired rotation.
Image Image Image
TrueVincent
Posts: 2
Joined: Sun Dec 03, 2006 9:14 pm

Post by TrueVincent »

I used the fps camera with some luck, it does rotate the camera, but only to 180 degrees. After it hits 180 degrees, it stops rotating.
Oziriz
Posts: 22
Joined: Wed Oct 12, 2005 6:44 pm

Post by Oziriz »

I'm currently working on reflections for Villain, so I just wrote a code like this for the rendertarget camera to "look" in a "bounced" direction, all the calculations are working and stuff, you need to tweak it a bit for your own use, but very little still:

Code: Select all

curPos = device->getCursorControl()->getPosition();
if (curPos.X != scrSize.X/2 || curPos.Y != scrSize.Y/2){
    camPos2D.X = camPos2D.X + (curPos.X - scrSize.X/2);
    camPos2D.Y = camPos2D.Y + (curPos.Y - scrSize.Y/2);
    if (camPos2D.Y <= 653) { camPos2D.Y = 652; } else if (camPos2D.Y >= 905) { camPos2D.Y = 905; }
    device->getCursorControl()->setPosition(position2d<s32>(scrSize.X/2, scrSize.Y/2));
}
CarPos = curtarget->getPosition();
camera->setTarget(vector3df(CarPos.X - 400*(-cos(-camPos2D.X/203.72)), CarPos.Y +200*tan(camPos2D.Y/203.72), CarPos.Z - 400*sin(camPos2D.X/203.72)));

The variables are as follows:
CarPos (vector3df) - Car position (in your case player position)
curtarget (vector3df) - Current target, in your case this would be the player, even if he's not a target precisely
camPos2D (position2d<s32>) - Current position of the camera
curPos (position2d<s32>) - Current cursor position on screen
scrSize (position2d<s32>) - Resolution

All you need to do is set the camera position where the head of the player should be (every frame), get those variables set and all should work. Hope it works out for you. :wink:

- Oziriz
Post Reply