Rocket's orientation

Started by
7 comments, last by norbip 14 years, 5 months ago
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.
Advertisement
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).

Interested in Fractals? Check out my App, Fractal Scout, free on the Google Play store.

Is it 2D or 3D?

How are you storing orientations/rotations for the tank and the turret?
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.
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.
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?
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)
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).
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. :)

This topic is closed to new replies.

Advertisement