Updating position vector
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.
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.
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.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement