Jump to content
• Advertisement

#### Archived

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

# vector coordinate rotation

This topic is 5556 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

## Recommended Posts

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

##### Share on other sites
Advertisement
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

##### Share on other sites
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

##### Share on other sites

• Advertisement
• Advertisement

• ### Popular Contributors

1. 1
Rutin
46
2. 2
3. 3
4. 4
5. 5
JoeJ
18
• Advertisement

• 13
• 10
• 12
• 10
• 13
• ### Forum Statistics

• Total Topics
632998
• Total Posts
3009802
• ### Who's Online (See full list)

There are no registered users currently online

×

## Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!