# 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 on other sites
Quote:
 Original post by -justin-However, it isn't working.
Define "not working".

##### 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 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 on other sites
Quote:
 Original post by NamethatnobodyelsetookThe 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]

## Create an account

Register a new account

• ### Forum Statistics

• Total Topics
627701
• Total Posts
2978702
• ### Similar Content

• A friend of mine and I are making a 2D game engine as a learning experience and to hopefully build upon the experience in the long run.

-What I'm using:
C++;. Since im learning this language while in college and its one of the popular language to make games with why not.     Visual Studios; Im using a windows so yea.     SDL or GLFW; was thinking about SDL since i do some research on it where it is catching my interest but i hear SDL is a huge package compared to GLFW, so i may do GLFW to start with as learning since i may get overwhelmed with SDL.
-Questions
Knowing what we want in the engine what should our main focus be in terms of learning. File managements, with headers, functions ect. How can i properly manage files with out confusing myself and my friend when sharing code. Alternative to Visual studios: My friend has a mac and cant properly use Vis studios, is there another alternative to it?

• Both functions are available since 3.0, and I'm currently using glMapBuffer(), which works fine.
But, I was wondering if anyone has experienced advantage in using glMapBufferRange(), which allows to specify the range of the mapped buffer. Could this be only a safety measure or does it improve performance?
Note: I'm not asking about glBufferSubData()/glBufferData. Those two are irrelevant in this case.
• By xhcao
Before using void glBindImageTexture(    GLuint unit, GLuint texture, GLint level, GLboolean layered, GLint layer, GLenum access, GLenum format), does need to make sure that texture is completeness.
• By cebugdev
hi guys,
are there any books, link online or any other resources that discusses on how to build special effects such as magic, lightning, etc. in OpenGL? i mean, yeah most of them are using particles but im looking for resources specifically on how to manipulate the particles to look like an effect that can be use for games,. i did fire particle before, and I want to learn how to do the other 'magic' as well.
Like are there one book or link(cant find in google) that atleast featured how to make different particle effects in OpenGL (or DirectX)? If there is no one stop shop for it, maybe ill just look for some tips on how to make a particle engine that is flexible enough to enable me to design different effects/magic
let me know if you guys have recommendations.
• By dud3
How do we rotate the camera around x axis 360 degrees, without having the strange effect as in my video below?
Mine behaves exactly the same way spherical coordinates would, I'm using euler angles.
Tried googling, but couldn't find a proper answer, guessing I don't know what exactly to google for, googled 'rotate 360 around x axis', got no proper answers.

References:
Code: https://pastebin.com/Hcshj3FQ
The video shows the difference between blender and my rotation:

• 21
• 14
• 12
• 10
• 12