Results 1 to 4 of 4

Thread: Lighting & Transformations

  1. #1
    Guest

    Lighting & Transformations

    Hi all..
    Ok. Here's my problem:
    I'm doing sort of a game whice includes space flight, asteroids, starships, space station etc... Anyway, I'm got my asteroids and my camera (pseudo code soon to come) and I'm trying to add a directional light but it rotates according to the asteroids which is quite annoying... What I want is to have the light at a fixed direction and the rest - rotating (btw: the camera can also move...).

    so here's the code (of the drawing routine);

    glLoadIdentity();
    glRotate(camera rotation (x,y,z));
    glTranslate(-camera position);
    glLightfv(LightPosition) //which is 1,0,0,0
    for(i=0 i<number_of_asteroids i++)
    {
    glPushMaterix();
    glTranslate(asteroid position);
    glRotate(asteroid rotation (x,y,z));
    DrawAsteroid();
    glPopMatrix();
    }

    thanks in advance
    Shahar.

  2. #2
    Senior Member OpenGL Guru Relic's Avatar
    Join Date
    Apr 2000
    Posts
    2,450

    Re: Lighting & Transformations

    The light's position is transfomed by the modelview matrix like a vertex.
    Do this and the light position is fixed:
    glLoadIdentity();
    glLightfv(LightPosition);
    glRotate(camera rotation (x,y,z));
    glTranslate(-camera position);

  3. #3
    Guest

    Re: Lighting & Transformations

    I've tried it already.. It simply won't work The asteroids rotate and the light also rotates with them instead of staying fixed. Probably because the light is multiplied by the Matrix when the actual drawing occurs ???? (a wild theory...)
    Still I'm stuck.
    Thanks
    Shahar

  4. #4
    Senior Member OpenGL Guru Relic's Avatar
    Join Date
    Apr 2000
    Posts
    2,450

    Re: Lighting & Transformations

    Take little steps and try it with a simple working example (e.g. from the redbook samples) to figure it out.
    If that's working on your implementation, than do it the same way in your program and all is well.

    If you don't be that patient, just check all places where you put the light position into your program and fix the matrix at that point to contain the identity. If that's not making the light completely static, than something else is broken in your program.

Similar Threads

  1. How to introduce Specular and Diffuse lighting into Bumped lighting
    By Liable in forum OpenGL: Advanced Coding
    Replies: 3
    Last Post: 12-06-2004, 05:48 PM
  2. Hardware Transformations vs Software Transformations
    By killersquirrelz in forum OpenGL: Advanced Coding
    Replies: 5
    Last Post: 12-05-2004, 04:43 AM
  3. lighting back facing triangles _without_ using two sided lighting
    By Nicolas Lelong in forum OpenGL: Advanced Coding
    Replies: 5
    Last Post: 02-07-2003, 03:05 AM
  4. About lighting (not OpenGL lighting, but general lighting)
    By Anonymous Coward in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 04-04-2001, 09:10 AM
  5. Replies: 1
    Last Post: 08-30-2000, 10:54 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