Advertisement

Caluclating a characters heading

Started by March 16, 2010 12:34 PM
17 comments, last by Zakwayda 14 years, 8 months ago
This is the problem. the rendering is being done by another guy, who isnt going to be around much over the next week.
So given the orientation how do i caluclate the heading? Is there a formula, or some algorithm?
Quote: So given the orientation how do i caluclate the heading? Is there a formula, or some algorithm?
How to compute the forward direction vector depends on how the orientation is represented, so...how is the orientation represented? A matrix? A quaternion? Euler angles? Spherical angles? A set of basis vectors? A single 'heading' angle?

If you can tell us that, we can tell you how to get the forward direction vector.
Advertisement
heading=normalize(velocity)

or,

heading=normalize(destination-current_position)

Orientation is a single heading angle.
Quote: Original post by kiniport
heading=normalize(velocity)

or,

heading=normalize(destination-current_position)
Depending on what exactly is meant by 'heading' (which I'm not sure the OP has clarified), it's not a given that an object's heading vector will be aligned with its velocity vector.

That said, the problem as presented isn't really very clear, so who knows, maybe the answer you've given is exactly what the OP is looking for...
Quote: Orientation is a single heading angle.
Ok, then if by 'heading' you mean 'forward direction vector', it would be computed as follows (assuming +z is up - you'll need to adjust accordingly if another axis is considered to be the 'up' axis):
forward.x = cos(heading_angle);forward.y = sin(heading_angle);forward.z = 0;
Is that what you're looking for?
Advertisement
Yes that is what im looking for. Sorry i didnt make it clearer. You're a hero mate. Really appreciate it.
Im just wondering what the maths behind these adjustments is. I ask cos, here you are saying z is the up. In mine the y will be up and im wondering how i work out what sin/cos to use?
Quote: Original post by discodowney
Im just wondering what the maths behind these adjustments is. I ask cos, here you are saying z is the up. In mine the y will be up and im wondering how i work out what sin/cos to use?
Check out the Wikipedia article on the unit circle for more info.

As for adjusting for y up, you simply need to swap and/or negate the sine and cosine terms as appropriate to get the results that you want. However, if the simulation is basically 2-d with 3-d graphics, I'd recommend making z up, as it'll make things easier overall.

This topic is closed to new replies.

Advertisement