#### Archived

This topic is now archived and is closed to further replies.

# How do I match heading to speed vector?

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

## Recommended Posts

Imagine a spacecraft controlled by a joystick. Each time I process the input I unpdate it''s heading. I can access the heading data in yaw/pitch/roll, rotation matrix, quaternion.. whatever. What I want is to set a speed vector for the ship that will be in the same direction it''s heading. Should I just compute the speed''s ''direction'' using sin() and cos() with the yaw and pitch angles? or is there a more elegant way to get both the vector and the rotation matrix in one go? Thanks, RL There aren''t any stupid questions, Only stupid people.

##### Share on other sites
quote:
There aren''t any stupid questions,
Only stupid people.

yuo are obviusly one of the stupid people
simply use trigenometry
i know how to do it

##### Share on other sites
Never claimd I was smart...

hang on, yes I DID!!

Yoda, if you would have actually READ my post you''d have seen that I wanted a way to extract the vector WITHOUT using trigo.

I ran into an article once describing how to extract vectors out of view matrices... (I think it was in regards to particle-to-screen alignment). Due to the fact that I already have the rotation to calculate (the trigo is embedded in it!!) I want to save a few 100''s (possibly even 1000''s) sine cosine calcs per move.

Anyways, If you have nothing smart to say, don''t say notin''

Cheers,
RL

There aren''t any stupid questions,
Only stupid people.

##### Share on other sites
Your object-to-world transformation matrix is defined as:

| Right Vector |
| Up Vector |
| At Vector |
| Position |

so if you define your matrix as:

struct Matrix{    Vector right;    Vector up;    Vector at;    Vector pos;};

then to move the object do:
Matrix m;m.pos += m.at * distance; // move forwardsm.pos += m.right * strafe; // strafe the objectVector speed = m.at * linear_speed;

Simple.

Skizz

##### Share on other sites
To whom it may concern...

To extract heading (or up/right) from a given rotation, and assuming using D3D matrices. Just get the mat._31, mat._32 ,mat._33 elements (for heading).

Someone in these forums actually gave me a link that explains this recently. It sucks having holes in your memory

Cheers,
RL

There aren''t any stupid questions,
Only stupid people.

1. 1
2. 2
frob
16
3. 3
4. 4
5. 5

• 20
• 13
• 14
• 76
• 22
• ### Forum Statistics

• Total Topics
632139
• Total Posts
3004369

×