Lights moving with camera

Lights moving with camera

Post by Finley Le » Sat, 30 May 1998 04:00:00



I'm having a problem where the lights in my scene are moving with the
camera.  It's my understanding the the position vector of the light source
is transformed by the GL_MODELVIEW matrix at the time that it is set.  I'm
loading identity into GL_MODELVIEW to prevent any transformation from taking
place:

glMatrixMode( GL_MODELVIEW ) ;
glPushMatrix() ;
glLoadIdentity() ;
col[0] = 0.0 ;
col[1] = 0.0 ;
col[2] = 2.0 ;
col[3] = 1.0 ;
glLightfv( nLightID, GL_POSITION, col ) ;
glPopMatrix() ;

My camera is orbiting the origin around the y-axis, and the light appears to
be doing the same.  Any ideas why this might be ocurring?

Thanks for any help,
--
Finley Lee
Programming Entity
Alien Skin Software, LLC

Web: http://www.alienskin.com

 
 
 

Lights moving with camera

Post by Oleg Letsins » Sun, 31 May 1998 04:00:00


On Fri, 29 May 1998 17:02:12 -0400, "Finley Lee"


>I'm having a problem where the lights in my scene are moving with the
>camera.  It's my understanding the the position vector of the light source
>is transformed by the GL_MODELVIEW matrix at the time that it is set.  I'm
>loading identity into GL_MODELVIEW to prevent any transformation from taking
>place:

... And you're getting exactly what you've asked for. You set fixed
light position - in the _camera_ coordinate system. If you want the
light source to have fixed coordinates in your scene's coordinate
system, you should do the following:
1) glMatrixMode(GL_MODELVIEW)
2) glLoadIdentity();
3) Position the scene.
4) glPushMatrix()
5) set your light's position in the scene's coordinate system
6) glPopMatrix();
7) Draw your scene.

-------------------------------------------------
 Oleg Letsinsky, Ulter Systems, Inc.


 
 
 

Lights moving with camera

Post by Steve Bake » Tue, 02 Jun 1998 04:00:00



> I'm having a problem where the lights in my scene are moving with the
> camera.

A common problem. Position the lights each frame *AFTER* you
have put the inverse camera position into the MODELVIEW matrix
and all will be well.

--

Steve Baker                (817)619-8776 (Vox/Vox-Mail)
Raytheon Systems Inc.      (817)619-4028 (Fax)


 
 
 

1. Weird OpenGL problem (Lights move with camera and shouldn't)

Okay, I'm having some kind of weird OpenGL problem that's got me a tad
confuzzled..

I've got an object oriented 3D engine (the source is far too large to post
here) where the lighting is acting a little funky.

The problem is that the lights are moving with the camera and I'm not
exactly sure what I'm doing wrong.  I think I'm following the red book
exactly and I can't find any example programs with dynamic lights that I can
compare to.  If I compare the code, it should be working just fine, if I
compare it to the example where the lights stay stationary.

The camera is set up like this:
void GLVRCamera::ResetGL()
{
 if (activeCamera == true ) {
   // Set the projection matrix
  glMatrixMode(GL_PROJECTION);
  // Set the projection matrix to the identity
  glLoadIdentity();
  // Set our prespective
  gluPerspective(fov, aspect, zNear, zFar);
  // Load our camera matrix
  glMatrixMode(GL_MODELVIEW);
  glLoadIdentity();
  viewMatrix.MulGL(GL_MODELVIEW);
 }
and that's executed once when the camera is activated and once whenever the
camera moves, where viewMatrix is of my matrix class that holds the
transforms for viewing and the fov,aspect,zNear, and zFar are class
variables that are set.

The code for the light is set up like this:
void GLVRLight::Enable(void)
{
 // spotlight properties removed for the sake of brevity
 glMatrixMode(GL_MODELVIEW);
 glPushMatrix();
 glLoadIdentity();
 glLightfv(lightnum,GL_POSITION,posGL);
 glLightfv(lightnum,GL_SPOT_DIRECTION,orientGL);
 glEnable(lightnum);
 glPopMatrix();
and that is only executed once.  It does the same thing no matter if it is
called before or after the camera is initilized.  posGL and orientGL are
both arrays that are contained within the class and lightnum is a GL Enum
that contains the light number.

From what I understand, the glLightfv uses the GL_MODELVIEW matrix when it
is set to determine where the light is supposed to be.  But the GL_MODELVIEW
matrix is the identity matrix.  I also tried doing the same thing to the
GL_PROJECTION matrix and that also gave me the exact same results.  I tried
resetting the position of the lights for every frame and that didn't help,
either.

Am I just not RTFMing this right?  When I had all of the camera transforms
in the GL_PROJECTION matrix, it didn't do this to me, but that caused some
other problems.  Is there some kind of enable or other gl call that I need
to make?

The current set of enables that I call is this:
 glDepthFunc(GL_LESS);
 glEnable(GL_DEPTH_TEST);
 glShadeModel(GL_SMOOTH);
 glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER,1);

This is under Windows 98 with the latest ELSA drivers for an ELSA Erazor III
(nVidia TNT2 card).

Thanks in advance for the help.

2. Mapping problems with Lightwave

3. Light blockers moving when the camera moves

4. converting 3 gray planes to color

5. Moving camera with moving objects in Inventor

6. viewing rendered animations

7. how to copy a canvas

8. Convenient matrix notation for moving a raytracer camera?

9. PoV-Ray 3.1: Acceleration/deceleration of a moving camera/object's speed

10. POV: Moving the camera

11. Moving camera help

12. writing out frames, just moving the camera