Sign in to follow this  

Rocket's orientation

This topic is 2960 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

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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
Share on other sites
Quote:
Original post by lightbringer
Is 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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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. :)

Share this post


Link to post
Share on other sites

This topic is 2960 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this