Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 3 additions & 10 deletions Core/Libraries/Source/WWVegas/WWMath/matrix4.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
#include "WWLib/win.h"
#include <d3d8types.h>
#include <d3dx8math.h>
#include <string.h>

/***********************************************************************************************
* Matrix4x4::Multiply -- Multiply two Matrix4x4's together *
Expand Down Expand Up @@ -180,18 +181,10 @@ void Matrix4x4::Multiply(const Matrix4x4 & a,const Matrix3D & b,Matrix4x4 * res)
#undef ROWCOL4
}

// Compares the bits of the elements, so 0.0f and -0.0f differ and identical NaNs are equal.
int operator == (const Matrix4x4 & a, const Matrix4x4 & b)
{
unsigned* m1=(unsigned*)&a;
unsigned* m2=(unsigned*)&b;
unsigned res=0;
for (int i=0;i<4;++i) {
res|=*m1++^*m2++;
res|=*m1++^*m2++;
res|=*m1++^*m2++;
res|=*m1++^*m2++;
}
return !res;
return memcmp(&a, &b, sizeof(Matrix4x4)) == 0;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do other math 3d types do not compare like this?

For example Matrix3D:

WWINLINE bool operator == (const Matrix3D &A, const Matrix3D &B)
{
   for (int i = 0; i < 3; i++) {
      for (int j = 0; j < 4; j++) {
         if (A[i][j] != B[i][j]) return false;
      }
   }
   return true;
}

Would that act different when using memcmp?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it differs in two cases:

  • 0.0f vs -0.0f: float != says equal, memcmp says different.
  • NaN: float != says a NaN never equals anything, even itself. memcmp says two NaNs with the same bits are equal.

For all other values they agree.

The original Matrix4x4 code already compared bits (it read the floats as unsigned), so this PR keeps that behavior and only removes the pointer casts. Matrix3D and Matrix3x3 have always compared float values. My guess is the bit compare was there to keep float compares out of the D3D transform cache in DX8Wrapper::_Set_DX8_Transform. That is the only use I found, and it is disabled with #if 0.

}

int operator != (const Matrix4x4 & a, const Matrix4x4 & b)
Expand Down
Loading