Updating position vector

Started by
1 comment, last by kVandaele 19 years, 6 months ago
Additional visualisation info I'm currently using a class to represent ships, the class having the following member vars: D3DXVECTOR3 m_Dir; D3DXVECTOR3 m_Up; D3DXVECTOR3 m_Pos; float m_fVel; while this is directx code, D3DXVECTOR3 is really just a vector with x, y, and z variables. m_Dir = directional vecotr, safe to assume it's normalised m_Up = up vector, not necessary here (i think) m_Pos = positional vector m_fVel = velocity value As you can see from the link, i tried to work this out in 2D first. Aside from having little clue as of yet how to do this in 3D, my end result was 4 square roots, each killing performance... Worse yet, this is an operation that would have to be done each frame -on nearly every single object- so speed is quite important.
Advertisement
1. Normalize your direction vector.
2. Calculate the distance moved in per frame (speed * frames per second).
3. New position = old position + (direction * distance moved)

The normalization shouldn't really need any square roots if it starts normalized, and you rotate it properly. Otherwise it will require one square root.
i was having problems with step 2, figuring out -if say velocity was 10- how much that would be in terms of x, y, and z...

riiiiiiiiight... since the direction vector is normalised that's no problem at all...

This topic is closed to new replies.

Advertisement