Advertisement

Direct3D ortho view

Started by January 18, 2001 02:38 PM
6 comments, last by KalvinB 24 years ago
How do I set up an ortho view in DX 7 with Direct3D? Ben
Jeah this question would interest me too. Please help.
Advertisement
Open up the DirectX SDK Help files. Search for ''orthogonal''. The first result you see should be ''D3DMatrixOrtho'' which is probably what you need. There are some other results there which may help too.
Thanks.
Thanks!

Ben
This is a basic OrthoPerspective function using the Orthogonal perspective matrix defined by OpenGL... This will work with any ol'' API.

void OrthoProjection(Matrix_t *mi, float left, float right,
float top, float bot, float zNear, float zFar) {

float *m;

// If there are any invalid values, return the identity.
// I figure this is the matrix that would hurt the least.
if((left == right) || (top == bottom) || (zNear == zFar)) {

MatrixIdentity(mi);

return;
} // ends if

m = (float *)mi

// zero out matrix
memset(m, 0, sizeof(Matrix_t));

// fill in ortho-projection orientation values.
m[M_11] = 2.0f / (right - left);
m[M_22] = 2.0f / (top - bottom);
m[M_33] = -2.0f / (far - near);
m[M_44] = 1.0f;

// fill in translation portion
m[M_41] = -(right + left) / (right - left);
m[M_42] = -(top + bottom) / (top - bottom);
m[M_43] = -(zFar + zNear) / (zFar - zNear);

} // ends OrthoProjection.

Hope this helps.... I''m going to be using this with my system since I want all the math to be the same regardless of the API I choose to use.

Danny Piron
Advertisement
I thought that OpenGL and Direct3D used different co-ordinate systems (left/righthandedness) as different matrix systems (row-major/column-major) which might interfere with your code... I could be wrong though.
I performed a simple test to see if OpenGL and Direct3D store their matrices in the same way. I simply called glTranslate on a ModelView matrix set to identity, then I used glGetMatrix (or whatever the function is, I can''t remember right now)... I then printed out the matrix row by row. I found that the translation components are positioned in the last row as is the case with Direct3D. Like this...

float matrix[16];

glLoadIdentity();
glTranslate(1, 2, 3);
glGetMatrixf(GL_MODELVIEWMATRIX, matrix);
printMatrix(matrix);

// yields the following output.
1.0 0.0 0.0 0.0
0.0 1.0 0.0 0.0
0.0 0.0 1.0 0.0
1.0 2.0 3.0 1.0

Interestingly enough, all OpenGL documentation I''ve encountered represent the matrices as a transpose of this with the translation vector as the final column.

This topic is closed to new replies.

Advertisement