Sign in to follow this  
-justin-

OpenGL Sending a custom matrix to DirectX's SetTransform [ Resolved]

Recommended Posts

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]

Share this post


Link to post
Share on other sites
Quote:
Original post by sirob
Quote:
Original post by -justin-
However, it isn't working.
Define "not working".


Sorry, was quickly writing this so I didn't explain very well.


All I see is my background color, no triangle is being drawn to the screen. Or rather, I don't see a triangle where I'm expecting to see one.

And as I said, the matrix I'm producing is identical to the one D3DX produces when given the same information. So that's why I feel it's the setTransform function that isn't performing the way I want...

Share this post


Link to post
Share on other sites
The problem is likely that you're transposing, as it's not needed (or wanted).

OpenGL is right handed, while D3D is left handed.
D3D is row major, while OpenGL is column major.
The two cancel out such that matrices are stored identically between the two APIs.

Share this post


Link to post
Share on other sites
Quote:
Original post by Namethatnobodyelsetook
The problem is likely that you're transposing, as it's not needed (or wanted).

OpenGL is right handed, while D3D is left handed.
D3D is row major, while OpenGL is column major.
The two cancel out such that matrices are stored identically between the two APIs.


Thanks for the advice. I had thought I had tried that. Musta been at a different time. Interesting... always thought I had to take the transpose for D3D to get OGL and vice-versa. Thanx alot!

Anyway, it works! Well sorta. Still trying to work out the coordinate system bugs. When I try to turn right, I turn left... when I try to walk forward I walk backward.

[Edited by - -justin- on October 25, 2008 9:04:37 PM]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this