School me on perspective implementation, please...
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
(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...
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.
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)...
Re: School me on perspective implementation, please...
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.
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.
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)