# Rocket's orientation

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

## Recommended Posts

Hi, I'm developing a simple tank game and I've encountered a problem (probably its simple, but i got stuck). There is a tank with a rotatable turret and cannon. The cannon's direction is already calculated. The problem is: I don't know the axes and the angle for rotating the ammo (which isn't a simple sphere). By default the ammo is drawn around the z axis, pointing upwards. Thanks is advance.

##### Share on other sites
Depends how your storing transformations, ff you know the direction (as a vector) that your turret is pointing then you can cross product that with an "up" vector to get a right vector, then cross product the right vector with the direction to get the true up (cross product order does matter but I'm not too sure on the correct order at the moment).

Once you have those 3 vectors (normalized) you can create an orthogonal matrix (with the vectors being rows) which represents the orientation your ammo should be. You mention by default ammo points up so you might need to add some rotation prior to adding the orientation you worked out (so the ammo points downt he correct axis whatever that may be).

##### Share on other sites
Is it 2D or 3D?

How are you storing orientations/rotations for the tank and the turret?

##### Share on other sites
If you have the orientation of the cannon (which I'm assuming you do, since you presumably need it for rendering), you should be able to use that as the initial orientation for the projectile.

##### Share on other sites
Quote:
 Original post by lightbringerIs it 2D or 3D? How are you storing orientations/rotations for the tank and the turret?

3d. i'm storing three angles. one for the tank's rotation around z, one for the turret's rotation around z, and the last one is for the turret (around y, since its a cylinder drawn along z by default too).
i'm using spherical coordinates to calculate the direction of the cannon.

Nanoha: thanks i'll try that.

jyk: yes, but when it will fly i won't be able to use that.

##### Share on other sites
Quote:
 jyk: yes, but when it will fly i won't be able to use that.
Is that because it'll be changing orientation as it moves?

##### Share on other sites
Quote:
Original post by jyk
Quote:
 jyk: yes, but when it will fly i won't be able to use that.
Is that because it'll be changing orientation as it moves?

yes. (my ammo is made from a cylinder and a cone, not a simple sphere)

##### Share on other sites
Quote:
 yes. (my ammo is made from a cylinder and a cone, not a simple sphere)
If the projectile just changes its pitch (y rotation in your case) as it moves, you could just stick with spherical coordinates and update its y rotation over time. Or, you could convert the initial spherical coordinates to matrix, quaternion, or axis-angle form and go from there (which representation would be optimal really just depends on the circumstances).

##### Share on other sites
my solution:
z(0,0,1) (up vector)
axis = z x cannondir (cannondir is normalized & calculated with spherical coords)
angle = z * cannondir (scalar prod)

and im storing the axis-angle for the ammo.

thank you. :)

1. 1
Rutin
23
2. 2
3. 3
JoeJ
20
4. 4
5. 5

• 32
• 41
• 23
• 13
• 13
• ### Forum Statistics

• Total Topics
631742
• Total Posts
3001987
×

## Important Information

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!