School me on perspective implementation, please...

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

School me on perspective implementation, please...

LordSmoke
I have made much progress in my JOGL/OpenGL programming. At this point, I can create, plot, color, animate various geometric models, but I am a bit stuck on implementing perspective. Models are built, colored, scaled, translated to fit in -1,1 x,y with aspect-correction.

I understand the geometry, the algebra, the matrix algebra, etc. of perspective projection. I am just not sure what to do with this information. Right now, I have the following transformations applied to raw vertex coordinates

AspectMx * AnimationMx * ViewMx * ModelMx * vertexDataVec

(there are others, but they are all identity at this point)

The ModelMx places the vertices (for, say, a unit cube) into world space
The ViewMx scales, translates the model into -1/1 x,y.
The AnimationMx spins it around using an FPSAnimator.
The AspectMx adjusts for the window shape

So, do I need a matrix to map my vertices further into a specified frustum? Do I then build a perspective matrix based on that frustum. Something like I am doing currently...

AspectMx * PerspectiveMx * FrustumMx * AnimationMx * ViewMx * ModelMx * vertexDataVec

Or are there some other context functions I should call. I see some fixed-pipeline code using something like glu.perspective (don't think that is relevant), and I see functions in FloatUtil for makePerspective, makeOrtho, makeFrustum, makeLookAt. Just not sure where to go with this.

Oh, I have written my own "working" perspective mx, but the model seems significantly smaller than that produce by my orthogonal projection matrix, which is really no different than no projection at this point.

TIA, LS

Also, not sure who, if anyone, cares or can do anything about it, but "googling" "jogl float util" brings up a first hit from 2004, v. 2.1.4 with deprecated functions using FloatBuffers. The more useful second entry is to the 2.3.1 version.

Heck, here's a pic (perspective on - it should really nearly fill the window)...
Reply | Threaded
Open this post in threaded view
|

Re: School me on perspective implementation, please...

gouessej
Administrator
When you use the fixed pipeline, the projection is already managed for you by glFrustum/gluPerspective and glOrtho. When using the programmable pipeline, you can emulate the fixed pipeline with some JOGL build-in utilities (PMVMatrix, FixedFuncUtil, ...) or do it by yourself (optionally with our utilities to manipulate the matrices as float arrays). Of course, you can use a dedicated matrix to store the projection.
Julien Gouesse | Personal blog | Website
Reply | Threaded
Open this post in threaded view
|

Re: School me on perspective implementation, please...

elect
In reply to this post by LordSmoke
In your shader you should do something like this

in vec3 position;
gl_Position = proj * (view * (model * vec4(position)))


AspectMX belongs to proj

AnimationMx to model

calculate view with makeLookAt and proj with makePerspective (for perspective projection) or makeOrtho (for orthographic)

I suggest you to study this chapter of one of the best tutorial out there.

If interested, I did a jogl port here
Reply | Threaded
Open this post in threaded view
|

Re: School me on perspective implementation, please...

LordSmoke
In reply to this post by gouessej
Thanks so much for the insights and links.

I think I understand enough to proceed, but I just have make some adjustments for the projections of data scaled for the middle of the frustum being projected onto the near plane.

I would think it should not matter where I chose to do the animation - rotate the data in world coordinates or in the view space. For my purposes, I generally scale my data initially just to fit within the view volume to be rendered. I will be adding mouse controls later for scale, translation, rotation of the view area.

Alas, other responsibilities demand my attention, so I won't be able to follow up on this this afternoon.

Again, thanks, LS

Reply | Threaded
Open this post in threaded view
|

Re: School me on perspective implementation, please...

LordSmoke
In reply to this post by LordSmoke
Got it, folks. Thanks! The major source of my problems were a) random and occasional confusion about the column-major storage of matix data, but more importantly, b) a typo, I think, on page 228 of the OpenGL Programming Guide 2013 - they seem to have left off the minus sign in element [3,4], -2*zFar*zNear/(zFar-zNear)
Reply | Threaded
Open this post in threaded view
|

Re: School me on perspective implementation, please...

jmaasing
Reply | Threaded
Open this post in threaded view
|

Re: School me on perspective implementation, please...

LordSmoke
Yes, thanks. Those are what I used to check my own calculations and understand better what was going on.