Results 1 to 3 of 3

Thread: Moving a light when changing the viewpoint

  1. #1
    Member Contributor
    Join Date
    Jan 2010
    Japan - Greece

    Moving a light when changing the viewpoint

    I have been reading the blue book and I have a problem. I can't reproduce the example of moving the viewpoint and with it moving a light.

    This is my projection transformation:

    Code :
        glViewport(0,0,canvasWidth,canvasHeight);//set the current viewport
    	glMatrixMode(GL_PROJECTION);//Reset the projection matrix

    lightPosition is set at 0.0,0.0,0.0,1.0 so that it is at the origin and considering that the viewpoint moves with the translations and rotations and so would the light.
    The problem is that this does not happen. The light seems to be stationary. Whenever I translate the viewpoint and look at my objects from other angles/views the light seems stationary and it definetely does not originate from the viewpoint(eye of the user).

    Any tips on how to do it? I must have completely misunderstood something. Thanks in advance
    My Blog

  2. #2
    Senior Member Regular Contributor Rosario Leonardi's Avatar
    Join Date
    Aug 2008

    Re: Moving a light when changing the viewpoint

    The light final position is computer with the modelview matrix active at the moment of the GL_LIGHTPOSITION
    so the pattern is this:
    Code :
    setup projection matrix
    setup camera position
    glLight(GL_LIGHT0, GL_POSITION, lPosition)
    setup object matrix
    render object 1
    and so on...
    ~ ~ I tell you, realtime 3D is made of blood, sweat and screams! ~ ~

  3. #3
    Member Contributor
    Join Date
    Jan 2010
    Japan - Greece

    Re: Moving a light when changing the viewpoint

    Oh thanks, now I understand. I corrected my light problem now, thanks.

    I have one more question though and this one is about the camera. I was rotating my view by doing translations and rotations on the projection matrix.

    I read that this is very wrong and it should be avoided. So now I moved my camera position setup to modelview matrix. But how should I setup my camera?

    GluLookAt seems nice but it does not offer any way to rotate, right? I could calculate my own rotated camera x,y,z coords and use these at GluLookAt? Would that be wise?

    Or is the better choice to just translate and rotate the whole scene and keep my view at the origin, hence giving the illusion of moving the camera?
    My Blog

Similar Threads

  1. Fixed light and moving spot light with the mouse
    By Jorcelangelo in forum OpenGL: Basic Coding
    Replies: 0
    Last Post: 04-18-2012, 09:56 PM
  2. Changing a viewpoint of an object without cam move
    By heavenssake007 in forum OpenGL: Basic Coding
    Replies: 7
    Last Post: 01-21-2009, 01:21 AM
  3. Light always coming from viewpoint.
    By paros in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 12-08-2008, 01:55 AM
  4. changing viewpoint
    By jenny in forum OpenGL: Basic Coding
    Replies: 4
    Last Post: 08-15-2002, 08:36 PM
  5. Replies: 1
    Last Post: 03-11-2001, 01:55 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
Proudly hosted by Digital Ocean