OpenGL Coord System Beginner Question

Hi. I’m a very new beginner to OpenGL, and I was wondering how to use glLoadMatrix()with glFrustum() to use real coordinates to set up the screen so my cubes stay cubes instead of changing to rectangles. I want to do this by having my coordinate system (0,0,0)-(640,480,800).

I also want to be able to convert the depth of a point -lets say (40, 40, 15)- to a 2D coordinate -like that point being (50, 50)-, and I want a 3D coordinate from a 2D coordinate at a specific z value, like to find the max (x,y,z) that still is visable on the screen - (640,480).

I’m pretty desprate to using a forum to find out how this is done, so any websites you can find will be very useful. The biggest thing that troubles me is setting up the coordinate system. The other things I know well enough. I have LaMothe OpenGL book if you know of anything in there that could be of help. Sorry for being such a beginner and about not wanting to convert my programming to OpenGL’s native coordinate system.

You can specify/set up any coordinate system you like. I suggest you find some information on how “viewing” works in a 3d world. Here is a link to the opengl programming guide. Check out chapter 3.
http://www.dcc.unicamp.br/~lmarcos/courses/mc603/redbook/

After that, download and play with nate robbins projection and transformation tutorials. They are great! http://www.xmission.com/~nate/tutors.html

not wanting to convert my programming to OpenGL’s native coordinate system.

The only thing “native” with OpenGL’s coordinate system is that it by default is a right handed coord.sys. and has the camera facing down the z axis at the origin. With some transformations you can change this to whatever you want.

Thanks, roffe, for the link. I hate being a beginner in C++ when my mathmatics work using the console or qbasic (scientific calculator basic as well). I still have a problem setting up the projection matrix and understanding matrix’s, based on them being constants, while I want to use them with variables.

I am basically trying to set up a Cad like enviroment in which each pixel is being taken into account, and each decrease of z results in viewpoint square being reduced by one pixel wide on each side to a single pixel being z = 1. I want artificial depth from my qbasic programs math to work inside opengl. Scaling and zooming is the only way I want of making depth.

What I want is |z/(MaxZ * MaxX), 0, 0, 0|
|0, z/(MaxZ * MaxY), 0, 0|
|0, 0, z, 0|
|0, 0, 0, 1|
but the values in the matrix must be constants, thus each call to glVertex3d(…) needs each value calculated before sending the param’s though. I have taken calculus, so this shouldn’t boggle my mind to much, it’s just using constants rather than variables that doesn’t make sense to me yet. If you know of a link that deals with matrix’s, and what each value in a matrix represents, I would be most greatful.

GLfloat Matrix =
{2.0f / MaxX, 0.0f, 0.0f, -1.0f,
0.0f, 2.0f / MaxY, 0.0f, -1.0f,
0.0f, 0.0f, 0.0f, -1 / MaxZ,
0.0f, 0.0f, -1.0f, MaxZ};

// thus,
// NewX = (x * 2 / MaxX - 1.0f) *
// ((MaxZ - z) / MaxZ);
// NewY = (y * 2 / MaxY - 1.0f) *
// ((MaxZ - z) / MaxZ);
// NewZ = -(MaxZ - z) / MaxZ;

I want to use this with glMatrixMode(GL_PROJECTION); glLoadMatrix(Matrix);, but I haven’t had a computer that has C++ on it, so if anyone can figure out for me if this works / how to correct it, I would be most greatful.