Advertisement Jump to content
Sign in to follow this  
neuromouse

OpenGL glOrtho - a beginner question

This topic is 1770 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi,

 

I am duplicating this question from opengl.org.

 

I know technically openGL does not have a camera. I am a total beginner, but if I understand correctly, I can move the "camera" or my "eye" with function gluLookAt. But: gluLookAt looks at a scene from one specific point (it uses a perspective). Since I am using glOrtho, I do not have a specific point from where to look at. I project a scene to a square, so all I need to define my "camera" is not a one-point "eye" but a square in space, and a direction from which I need to project the scene to that square. So if I have a direction defined with a vector, and I have a rectangle to which I want to project - how do I do that?

 

 

Here's a quick sketch of what I want to achieve. I have a rectangle defined with X1, X2, X3 and X4 - and a vector of direction in which I want to view. I only want to view in that direction, not interested in what's behind a "camera". The only problem here is I do not have a "camera" but rather a "screen" or "canvas" on which I want to project.

 

Here's what's a normal projection with glOrtho looks like:
 

lu5s.png

Here's what I want to do:
lb1v.png

Any help will be really appreciated.

Share this post


Link to post
Share on other sites
Advertisement

gluLookAt does nothing more than apply an equivalent rotation and translation. If you can describe the orientation and location of the plane by some parameters to gluLookAt, then you're set.

 

For example, if the center of the plane is located at (px, py, pz) with a normal pointing towards the direction (nx, ny, nz), then you should be able to locate the view point with something like gluLookAt(px, py, pz, px+nx, py+ny, pz+nz, ux, uy, uz) where the vector (ux,uy,uz) orients the plane (you may want to orient the up vector along, for example, the point X3-X1).

 

The orthographic projection is then set up with width and height corresponding to the distance between X1 and X2, and X1 and X3, respectively. Make the projection symmetric if the point (px, py, pz) is at the center of the plane.

 

You can also replace the call to gluLookAt with the equivalent rotation and translation yourself if you know your linear algebra. The vector X=(X2-X1), Y=(X3-X1) and Z=X cross Y, or some variant thereof, defines the coordinate system as seen from the projection plane. A translation to shift by (px, py, pz) the coordinate system is also necessary.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!