"3D"

Started by
3 comments, last by Ulfie 19 years, 10 months ago
The OpenGL 2D screen could easily be transformed into a 2-dimensional coordinate system where the lower left corner was (min, min) and the upper right was (max, max) Given such a coordinate system, if I wanted to put a pixel at (x,y) it would be easy. But say I wanted to draw the same thing (so that it looked identical) in 3D. Which transformations would I have to do to the modelview matrix etc to be able to put a pixel at (x, y, 0) in 3D and achieve the same result?
Advertisement
I''m not exactly sure what you are asking...

The "2D" mode in OpenGL is called Ortho view, and you''ll see lots of posts about it in the forums. But ortho isn''t really 2D, it''s just a way of doing what you described - dropping the Z component and letting place stuff in an xy coordinate system. You could switch to ortho view, place your stuff, and then switch back to regular mode and do whatever you want.

If however, you are trying to remain in 3D view the whole time, and just place stuff using some sort of xy coordinate system, it just doesn''t work that way. Since you have a moveable camera, and a "world" that can be rotated, translated, etc., there is just no way to say "place the object at (x,y) in respect to my current camera position" (or at least, I''m not aware of such a thing).
-Todd"Windows dectected that your mouse has moved. Please reboot for the changes to take effect"
There is a function called glOrtho that sets up the necessary projection matrix for you. After calling this function with the right arguments, you can place objects on the screen with the same x,y combination you described. Of course, the z component is still there, but it''s usually 0, or it can even be 1 or 2 to give the object depth information (which object is on top of others) I think.
You can still scale with glScale and translate with glTranslate. I''m not sure what happens when you try to do a rotation though.
Ok I''ll try to specify, I was a bit unclear!

Given that the camera is at (0,0 Z) looking att (0,0,0),
how would you transform the modelview matrix and/or Z so that
the point with the WORLD coordinate (-SCRW/2, SCRH/2, 0) would have the SCREEN coordinate (0,0) i.e. be at the upper left corner of the screen, the point with the WORLD coordinate (SCRW/2, SCRH/2, 0) would have the SCREEN coordinate (SCRW,0) i.e. be at the upper right corner of the screen, and so on?

I would be using this in a "2D" platformer, and I think it would be good because you get really easy depth culling and scrolling , for example for backgrounds. Plus, it would make the incorporation of "real" 3D objects in the level easier. The reason for the need for a conversion between coordinate systems as of above is that I would like a level in the game to look just like it does in my 2D level editor.
Translate everything in the negative z direction (into the screen) by scrh/2tan(yfov/2) or something like that?

This topic is closed to new replies.

Advertisement