Jump to content

  • Log In with Google      Sign In   
  • Create Account


glOrtho - a beginner question


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
1 reply to this topic

#1 neuromouse   Members   -  Reputation: 101

Like
0Likes
Like

Posted 15 March 2014 - 05:32 AM

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.



Sponsor:

#2 Brother Bob   Moderators   -  Reputation: 7781

Like
3Likes
Like

Posted 15 March 2014 - 06:22 AM

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.






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS