Author Topic: Matrix Multiplication  (Read 849 times)

hailstone

  • Local Moderator
  • Battle Machine
  • ********
  • Posts: 1,568
    • View Profile
Matrix Multiplication
« on: 8 May 2010, 08:05:27 »
I was having a look at the matrix multiplication and noticed there's a Vec<T> being created without being used. Also there may be unneeded conversions if T is an int since it will only return a Vec4f which is a Vec4<float>.

Quote from: math.h
Vec4<T> operator * (const Vec4<T> &v) const{
      Vec4<T> rv;
      
      return Vec4f(
         data[0]*v.x + data[1]*v.y + data[2]*v.z + data[3]*v.w,
         data[4]*v.x + data[5]*v.y + data[6]*v.z + data[7]*v.w,
         data[8]*v.x + data[9]*v.y + data[10]*v.z + data[11]*v.w,
         data[12]*v.x + data[13]*v.y + data[14]*v.z + data[15]*v.w);
   }

I imagine rv was previously being returned then the person writing it changed their mind. I'm not sure if it's worth modifying.
Glest Advanced Engine - Admin/Programmer
https://sourceforge.net/projects/glestae/

zombiepirate

  • Guest
Re: Matrix Multiplication
« Reply #1 on: 8 May 2010, 15:52:46 »
You may as well change it. It's not really hurting anything now but It looks a bit sloppy to keep it. The operator in Matrix3 has the same thing too.

silnarm

  • Local Moderator
  • Behemoth
  • ********
  • Posts: 1,373
    • View Profile
Re: Matrix Multiplication
« Reply #2 on: 9 May 2010, 09:38:46 »
Quote from: math.h
Vec4<T> operator * (const Vec4<T> &v) const{
      Vec4<T> rv;
      
      return Vec4f(
         data[0]*v.x + data[1]*v.y + data[2]*v.z + data[3]*v.w,
         data[4]*v.x + data[5]*v.y + data[6]*v.z + data[7]*v.w,
         data[8]*v.x + data[9]*v.y + data[10]*v.z + data[11]*v.w,
         data[12]*v.x + data[13]*v.y + data[14]*v.z + data[15]*v.w);
   }
I imagine rv was previously being returned then the person writing it changed their mind. I'm not sure if it's worth modifying.

Yeah, I'd say it was once something like:
Code: [Select]
Vec4<T> operator * (const Vec4<T> &v) const{
Vec4<T> rv = Vec4f(
data[0]*v.x + data[1]*v.y + data[2]*v.z + data[3]*v.w,
data[4]*v.x + data[5]*v.y + data[6]*v.z + data[7]*v.w,
data[8]*v.x + data[9]*v.y + data[10]*v.z + data[11]*v.w,
data[12]*v.x + data[13]*v.y + data[14]*v.z + data[15]*v.w);
// output for debug...
return rv;
}

In any case, as they aren't actually used, those operators could probably be removed... If you need to do any matrix multiplication, you should do it through OpenGL anyway, to make the most of whatever hardware is available.
Glest Advanced Engine - Code Monkey

Timeline | Downloads