Hey everyone! Haven't been here in quite a while!
I'm using a custom matrix class that I fill out in my camera class. I want to pass that to DirectX to use. However, it isn't working. It's possible I'm looking in the wrong direction or something like that, but I need to at least affirm that it isn't me passing my matrix to D3D that's the problem.
I've already written my OpenGL code using glLoadMatrix and it works great. And yes, I did transpose the matrix before sending it to DX.
All I'm doing right now is drawing a Triangle to the screen...
Here's some code:
template <class T>
class matrix4x4
{
public:
T m[16];
matrix4x4();
matrix4x4(T m0, T m1, T m2, T m3,
T m4, T m5, T m6, T m7,
T m8, T m9, T m10, T m11,
T m12, T m13, T m14, T m15);
matrix4x4(const matrix4x4<T> &other);
void identity();
void transpose();
// Other functions
}
Draw code:
matrix4x4<double> top;
top = m_stack.top();
top.transpose();
matrix4x4<float> mat = (matrix4x4<float>)top;
m_d3dDevice->SetTransform( D3DTS_VIEW, reinterpret_cast<D3DMATRIX*> (&mat.m) );
MyVertex* arrVertices = new MyVertex[3];
arrVertices[0].color = c1;
arrVertices[0].vertex = vec3<float>(0.0, height, 0.0);
arrVertices[1].color = c2;
arrVertices[1].vertex = vec3<float>(-width/2.0, 0.0, 0.0);
arrVertices[2].color = c3;
arrVertices[2].vertex = vec3<float>(width/2.0, 0.0, 0.0);
m_d3dDevice->SetFVF( D3DFVF_XYZ|D3DFVF_DIFFUSE );
m_d3dDevice->DrawPrimitiveUP( D3DPT_TRIANGLELIST, 1, arrVertices, sizeof( MyVertex ));
I did a check with the following code (which does output the triangle) and set the eyelocation to the same location of my camera. The up vector is the same etc.
// Create and set the view matrix
D3DXVECTOR3 eyeLocation( 0, 0, 20.0f );
D3DXVECTOR3 lookAt( 0, 0, 0 );
D3DXVECTOR3 up( 0.0f, 1.0f, 0.0f ); // World's up vector
D3DXMatrixLookAtLH( &matrix, &eyeLocation, &lookAt, &up );
And the matrices are pretty much the same...
[Edited by - -justin- on October 25, 2008 9:17:05 PM]