Calculate x angle orientation from x and z position

Started by
2 comments, last by nick5454 19 years, 10 months ago
I have a jet that will soon travel to another position. everything works fine as long as the x angle is not 0 I use direct3d so x is right, y is up, z forward my calc was vec1 is source vec2 is destination newvec = vec2 - vec1 newvec = normalize(newvec) so y = newvec.y * (PI/2) that works fine and when the x angle is not 0 it works great 2 but when want him to go to a negative z( towards the screen) he doesnt because x is already 0. So it doesnt work so x = newvec.x * ( PI/2) * ( newvec.z/abs(newvec.z) ) I though multiplying x by a -1 or 1 would spin my jet around in the right direction. Please help. Its my last hurdle in this space fight simulation. Or at least that I can see. Nick
Advertisement
Perhaps you should stick to standard maths rather than inviting your own laws of maths .

if you have vec1 source, vec2 destination...

direction = vec2-vec1
normalise(direction)

you can move your "jet" like so:

position += direction*speed*frametime

where direction was calculated above, speed is the speed that your "jet" should travel at (in units/sec) and frametime is the amount of time passed since the last frame (in seconds).
Well I''m not reinbventing the wheel. it still moves according to its Look orientation. But when I tell the jet "Hey fly to this x,y,z) coordinate I have to know the exact orientation. so I get the x angle. But the x depends on whether hes going -z or +z, so I need to add 180 to his degree to determine the correct flow.

It doesnt have anything to do with actually moving it, just the orientation
What SpaceDude probably mean is that you use stranges formulas to get the displacement and not reinventing the wheel since what you use seems incorect (why *(Pi/2) for example ?). He told you the formulas you need though. To get the angle between two vectors you can use arctan but you don''t need it in that case ...

This topic is closed to new replies.

Advertisement