seems when i use the static functions (I've followed the MSDN example on static libs and the have a class with static members), I get linker unresolved errors to Matrix3x3::Identity(), and the like.
I've used the chili matrix from the Thrust series
Code: Select all
////////////////////////////////////////////////////
// Matrix 3X3
/////////////////////////////////////////////////////
class Matrix3x3
{
public:
// added these after first linker error
Matrix3x3() = default;
Matrix3x3(float e0, float e1, float e2, float e3, float e4,
float e5, float e6, float e7, float e8 )
{
elements[0][0] = e0;
elements[0][1] = e1;
elements[0][2] = e2;
elements[1][0] = e3;
elements[1][1] = e4;
elements[1][2] = e5;
elements[2][0] = e6;
elements[2][1] = e7;
elements[2][2] = e8;
}
Matrix3x3& operator =(const Matrix3x3& rhs);
Matrix3x3& operator *=(const float rhs);
Matrix3x3 operator *(const float rhs) const;
Matrix3x3 operator *(const Matrix3x3& rhs) const;
Matrix3x3& operator *=(const Matrix3x3& rhs);
static Matrix3x3 Identity();
static Matrix3x3 Rotation(float theta);
static Matrix3x3 Scaling(float factor);
static Matrix3x3 Translation(const Vector2D offset);
Vector2D operator *(const Vector2D rhs) const;
public:
// [ row ][ col ]
float elements[3][3];
};
Code: Select all
/////////////////////////////////////////////////////
// Matrix 3x3
////////////////////////////////////////////////////////
Matrix3x3 & Matrix3x3::operator=(const Matrix3x3 & rhs)
{
memcpy(elements, rhs.elements, sizeof(elements));
return *this;
}
Matrix3x3 & Matrix3x3::operator*=(const float rhs)
{
for (auto& row : elements)
{
for (float& e : row)
{
e *= rhs;
}
}
return *this;
}
Matrix3x3 Matrix3x3::operator*(const float rhs) const
{
Matrix3x3 result = *this;
return result *= rhs;
}
Matrix3x3 Matrix3x3::operator*(const Matrix3x3 & rhs) const
{
Matrix3x3 result;
for (int j = 0; j < 3; j++)
{
for (int k = 0; k < 3; k++)
{
float sum = 0.0f;
for (int i = 0; i < 3; i++)
{
sum += elements[j][i] * rhs.elements[i][k];
}
result.elements[j][k] = sum;
}
}
return result;
}
Matrix3x3 & Matrix3x3::operator*=(const Matrix3x3 & rhs)
{
return *this = *this * rhs;
}
Vector2D Matrix3x3::operator*(const Vector2D rhs) const
{
Vector2D result;
result.x = elements[0][0] * rhs.x + elements[0][1] * rhs.y + elements[0][2];
result.y = elements[1][0] * rhs.x + elements[1][1] * rhs.y + elements[1][2];
return result;
}
Matrix3x3 Matrix3x3::Identity()
{
Matrix3x3 i = { 1.0f,0.0f,0.0f,0.0f,1.0f,0.0f,0.0f,0.0f,1.0f };
return i;
}
Matrix3x3 Matrix3x3::Rotation(float theta)
{
const float cosTheta = cos(theta);
const float sinTheta = sin(theta);
//. tried fucking around here with no success
Matrix3x3 r = { cosTheta,-sinTheta,0.0f,sinTheta,cosTheta,0.0f,0.0f,0.0f,1.0f };
return Matrix3x3(cosTheta, -sinTheta, 0.0f, sinTheta, cosTheta, 0.0f, 0.0f, 0.0f, 1.0f);
}
Matrix3x3 Matrix3x3::Scaling(float factor)
{
Matrix3x3 s = { factor,0.0f,0.0f,0.0f,factor,0.0f,0.0f,0.0f,1.0f };
return s;
}
Matrix3x3 Matrix3x3::Translation(const Vector2D offset)
{
Matrix3x3 t = { 1.0f,0.0f,offset.x,0.0f,1.0f,offset.y,0.0f,0.0f,1.0f };
return t;
}
Code: Select all
#ifdef _DEBUG
#pragma comment(lib,"lib2D_d.lib")
#else
#pragma comment(lib,"lib2D_r.lib")
#endif