I figured out shading but I can't seem to figure out my light position.
Now I have a figure which is rotating -- and my light continues to rotate with it!
Here is the basic flow of what I do:
//Begin initialization
#1 Set ModelView and load identityMatrix
#2 Set Projection Mode and load identityMatrix and establish my view
#3 Set ModelView, load identity Matrix, push
#4 preform a roation and then translation.
#5 Save Model Matrix as View1.
#6 Pop Matrix.
//End initialization
#6.5 Clear buffers....
//Establish light position
#7 Set ModelView, Push, load IdentityMatrix
#8 Establish positional light at (5,5,5)
#9 Pop
// End establish light position
//Begin to draw model
#10 Set ModelView, Push
#11 Load View1 Matrix
#12 Draw...
#13 Rotate arround y axis
#14 Save View1
#15 Pop
// End draw model
#16 goto #6.5
My model looks great. The problem is that the light source is rotating -- or at least moving.
I have checked to ensure that I am pushing and poping by checking the ModelMatrix stack depth at each stage and indeed the seem to be correct. I have tried only establishing the light source once by putting it between steps #2 and #3. (after setting perspective and before setting up View1).
I also tried putting right before step 12 -- which resulted in screwing with my perspective.
Here is the code where I set the light:
public void insertLight() {
gl.glMatrixMode(GL.GL_MODELVIEW);
gl.glLoadIdentity();
gl.glPushMatrix();
gl.glDisable( GL.GL_LIGHT1 );
gl.glLightfv(GL.GL_LIGHT1, GL.GL_POSITION, lightpos, 0);
// gl.glLightfv(GL.GL_LIGHT1, GL.GL_POSITION, lightdir, 0); // Directional light also rotates....
gl.glLightfv( GL.GL_LIGHT1, GL.GL_AMBIENT, colorWhite, 0);
gl.glLightfv( GL.GL_LIGHT1, GL.GL_DIFFUSE, colorGray, 0);
gl.glLightfv( GL.GL_LIGHT1, GL.GL_SPECULAR, colorLightYellow, 0);
//gl.glEnable( GL.GL_LIGHT0 );
gl.glEnable( GL.GL_LIGHT1 );
printDepth("Setting Lights");
gl.glPopMatrix();
}
I suppose my next step is to draw an object at the light's coordinates and try to see if it is really rotating.

New Topic/Question
Reply




MultiQuote






|