Independent Camera Rotation
-
- Posts: 2
- Joined: Sun Dec 03, 2006 9:14 pm
Independent Camera Rotation
Is there a way to rotate the camera independently like the FPS camera. I tried using the setRotation() function, but it didn't work.
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.
-
- Posts: 2
- Joined: Sun Dec 03, 2006 9:14 pm
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:
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.
- Oziriz
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.
- Oziriz