Do I need the 'w' component in my Vector class?
- by bobobobo
Assume you're writing matrix code that handles rotation, translation etc for 3d space.
Now the transformation matrices have to be 4x4 to fit the translation component in.
However, you don't actually need to store a w component in the vector do you?
Even in perspective division, you can simply compute and store w outside of the vector, and perspective divide before returning from the method.
For example:
// post multiply vec2=matrix*vector
Vector operator*( const Matrix & a, const Vector& v )
{
Vector r ;
// do matrix mult
r.x = a._11*v.x + a._12*v.y ...
real w = a._41*v.x + a._42*v.y ...
// perspective divide
r /= w ;
return r ;
}
Is there a point in storing w in the Vector class?