Hi,
I have a node and a camera (FPS, receiver disabled).
the camera rotates around the node (like moon around earth).
I have the positions and the angle of the cam to the node.
Now I want to set the rotation of the cam, so that it looks straight to the node !!!
I don't want to use setTarget, I want to calculate the angle(s) !!!
thx, Acki
cam rotations
cam rotations
while(!asleep) sheep++;
IrrExtensions:
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
IrrExtensions:
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
Hi,I have the positions and the angle of the cam to the node.
I am not sure I understand the problem. You say you have the angles. Why can't you use 'camera->setRotation' ?
If you want to calculate the angles relative to the x, y, z axis you can do the following:
Calculate the vector nodeposition (n) minus camera position (c). This gives you a directional vector: R(Xr, Yr, Zr) = (Xn - Xc, Yn - Yc, Zn - Zc)
Rotation about x axis = arctan(Zr / Yr)
Rotation about y axis = arctan(Zr / Xr)
Rotation about z axis = arctan(Yr / Xr)
In C++ it is best to write this as atan2(Xr, Yr) (X and Y are swapped !)
These angles can be used in the 'camera->setRotation' function.
In case the camera behaves 'strangely' you are propably witnessing the gimbal lock problem.
I am sure there are other solutions, for instance using the matrix4 class
Well, I want to create a camera like in Splinter Cell.
The cam rotation around the y axis works.
The cam rotation around the x axis works.
But both together screws the movement up !!!
The cam rotation around the y axis works.
The cam rotation around the x axis works.
But both together screws the movement up !!!
Code: Select all
void setCamera(bool recalc){
// move the camera
static ICursorControl* curs = device->getCursorControl();
static s32 scrCenterX = driver->getScreenSize().Width / 2;
static s32 scrCenterY = driver->getScreenSize().Height / 2;
static position2d<s32> mp;
static s32 moveX, moveY;
static float camDist2, gTob = 3.14156 / 180.0, bTog = 180.0 / 3.14156;
static vector3df posCam(0, 5, -5), rotCam(0, 0, 0), rotPivot(0, 0, 0);
// get mouse movements
mp = curs->getPosition();
moveX = scrCenterX - mp.X;
moveY = scrCenterY - mp.Y;
// move mouse back to center of screen
curs->setPosition(position2d<s32>(scrCenterX, scrCenterY));
if(moveX){
// rotate camera around world Y axis of player center
rotPivot.Y += moveX;
if(rotPivot.Y >= 360.0) rotPivot.Y -= 360.0;
if(rotPivot.Y < 0.0) rotPivot.Y += 360.0;
recalc = true;
}
if(moveY){
rotPivot.X -= moveY;
if(rotPivot.X > 80.0) rotPivot.X = 80.0;
if(rotPivot.X < 10.0) rotPivot.X = 10.0;
recalc = true;
}
if(recalc){
camDist2 = cos(rotPivot.X * gTob) * camDistanz;
posCam.Y = sin(rotPivot.X * gTob) * camDistanz;
posCam.X = cos(rotPivot.Y * gTob) * camDist2;
posCam.Z = sin(rotPivot.Y * gTob) * camDist2;
// here seems to be the error !?!?!
rotCam.Y = atan2(-posCam.X, -posCam.Z) * bTog;
rotCam.X = atan2(posCam.Y, posCam.X) * bTog;
}
// get the player position
vector3df posPlayer = player->getPosition();
Cam->setPosition(posPlayer + posCam);
Cam->setRotation(rotCam);
}
while(!asleep) sheep++;
IrrExtensions:
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
IrrExtensions:
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
-
- Posts: 16
- Joined: Mon Apr 11, 2005 2:32 pm
- Location: LEEDS, England
- Contact:
Sounds like a case of Gimbal lock to me. I've not used them (yet), but it should be possible to create a quaternion-based camera and transform the orientations from the quat to use in your camera. There's a tutorial on GameDev.net that might help you.Acki wrote:Well, I want to create a camera like in Splinter Cell.
The cam rotation around the y axis works.
The cam rotation around the x axis works.
But both together screws the movement up !!!
Well, I now created a second camera (inactive) set the position to the first cam.
Then I set the target of the 2nd cam and get their rotation for the first cam...
The problem is, if I use the setTarget on the first cam and poth (cam and node) are moving the cam is flipping up and down....
Then I set the target of the 2nd cam and get their rotation for the first cam...
The problem is, if I use the setTarget on the first cam and poth (cam and node) are moving the cam is flipping up and down....
while(!asleep) sheep++;
IrrExtensions:
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
IrrExtensions:
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
This seems strange:
I would expect Y and Z as parameters:
Code: Select all
rotCam.X = atan2(posCam.Y, posCam.X) * bTog;
Code: Select all
rotCam.X = atan2(posCam.Y, posCam.Z) * bTog;
No, Y and X are correct !!!
It calculates the up/down look of the cam...
It depends on the coordinate system of Irrlicht:
for example 3DSMax uses this system:
It calculates the up/down look of the cam...
It depends on the coordinate system of Irrlicht:
Code: Select all
Y
Z
| /
| /
| /
| /
|/____________ X
Code: Select all
Z
Y
| /
| /
| /
| /
|/____________ X
while(!asleep) sheep++;
IrrExtensions:
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
IrrExtensions:
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java