Archived

This topic is now archived and is closed to further replies.

em5

vector coordinate rotation

Recommended Posts

em5    122
Im writing a 3d shoot em up and got a really hard time with the math. My problem is that when I rotate the ship I need to recalculate the posiotion of the gun muzzle. I would have been piece of cake if OpenGL didnt rotate the other axises when rotating. So next rotation, the other axises are way off, making the math axtemely complex. I have managed to find the formula for Y and Z rotation through trail and error: x = M_X * cosf(yrot) * cosf(zrot) + M_Y * -sinf(zrot) * cosf(yrot) + M_Z * sinf(yrot) y = M_X * sinf(zrot)+ M_Y * cosf(zrot) z = M_X * -sinf(yrot) * cosf(zrot)+ M_Y * sinf(yrot) * sinf(zrot) + M_Z * cosf(yrot), M_X, M_Y, M_Z are the start posision of the gun muzzle. Ive been reading and trying out stuff for weeks now. Nothing Ive found on the net has been of any help at all. The only working formula I used is the one I made myself. Ive must have got the wrong idea somewhere. I would really appreciate some guidance.

Share this post


Link to post
Share on other sites
Krylloan    142
I assume you are using glRotate?
You mighe be better off calculating the matrix yourself, then using glLoadMatrix.
This way, you don''t need to do any sin/cos operations if your positions are in rectangular co-ordinates (eg x, y, z).

The matrix may look something like:
x y z w
x: y z x 0
y: z x y 0
z: x y z 0
w: 0 0 0 1
(Assuming your x, y and z are normalised)
- some values might be negative, this was just an example.

Though if the gun is attached to your ship then you _probably_ shouldn''t be rotating it at all, just draw it after a glLoadIdentity.

Share this post


Link to post
Share on other sites
em5    122
hrmm... I didnt understand much of that... sorry. I think u missed somthing too: "Though if the gun is attached to your ship then you _probably_ shouldn''t be rotating it at all, just draw it after a glLoadIdentity." The problem are the shots. They cant be attached to the ship, they need there own co-ordinates, or I wont be able to check if they hit something.

Really thanks for trying to help me out. Maybe u''d get a clearer picture of the problem if u get to see the game for yourself. Here, check it out: ftp://em5.mine.nu/Zweihänder.exe Please dont spread it around, cuz I dont own the copyright of the music. Its borrowed from Einhänder (Playstation).

Okey, use up,down,right,left arrow to move the ship. CTRL,SPACE to shot. hold C to see the collition shperes. W,A,S,D to rotate the ship (useless to the game, its just for testing).

Now u see when the ship goes up and down it rotates on Z. I want it to rotate on X instead cuz the Z rotation looks strange.

Feel free to have a glance at the ship sourcecode ftp://em5.mine.nu/Zweihander.h

Share this post


Link to post
Share on other sites