Game Development Reference
In-Depth Information
The Mat4 × 4 Transform Matrix Class
It can be convenient to wrap DirectX
'
s D3DXMATRIX structure into a C++ class:
class Mat4x4 : public D3DXMATRIX
{
public:
// Modifiers
inline void SetPosition(Vec3 const &pos)
{
m[3][0] = pos.x;
m[3][1] = pos.y;
m[3][2] = pos.z;
m[3][3] = 1.0f;
}
inline void SetPosition(Vec4 const &pos)
{
m[3][0] = pos.x;
m[3][1] = pos.y;
m[3][2] = pos.z;
m[3][3] = pos.w;
}
// Accessors and Calculation Methods
inline Vec3 GetPosition() const
{
return Vec3(m[3][0], m[3][1], m[3][2]);
}
inline Vec4 Xform(Vec4 &v) const
{
Vec4 temp;
D3DXVec4Transform(&temp, &v, this);
return temp;
}
inline Vec3 Xform(Vec3 &v) const
{
Vec4 temp(v), out;
D3DXVec4Transform(&out, &temp, this);
return Vec3(out.x, out.y, out.z);
}
inline Mat4x4 Inverse() const
{
Mat4x4 out;
Search WWH ::




Custom Search