Do I need the 'w' component in my Vector class?

Posted by bobobobo on Game Development See other posts from Game Development or by bobobobo
Published on 2011-06-24T20:16:29Z Indexed on 2011/06/25 0:33 UTC
Read the original article Hit count: 206

Filed under:
|
|

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?

© Game Development or respective owner

Related posts about math

Related posts about vector