Light moving

Light moving

Post by Alessandro Benedett » Fri, 20 Aug 1999 04:00:00



This is the display code of my simple game (it's the beginning). I want to
leave the light in a point but when I move the player the light seem to move
too. How can I resolve my problem?

-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
GLfloat position [] = {0.0, 80.0, 80.0, 1.0};

void display (void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

glLoadIdentity();
    glLightfv(GL_LIGHT0, GL_POSITION, position);
    glRotatef(vola, 1.0, 0.0, 0.0);
    glRotatef(angle, 0.0, 1.0, 0.0);

    glTranslatef(xx, yy, zz);

    glCallList(sky);

    glPushMatrix();
        glTranslatef(0.0, -50.0, 0.0);
        glRotatef(-90.0, 1.0, 0.0, 0.0);
        glColor4f(1.0, 1.0, 1.0, 1.0);
        glCallList(room);
    glPopMatrix();

    glCallList(floor);
    glutSwapBuffers();

Quote:}

-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

Thank You
Alessandro

 
 
 

Light moving

Post by Paul Mart » Fri, 20 Aug 1999 04:00:00



>This is the display code of my simple game (it's the beginning). I want to
>leave the light in a point but when I move the player the light seem to
move
>too. How can I resolve my problem?

>-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-
*
>GLfloat position [] = {0.0, 80.0, 80.0, 1.0};

>void display (void)
>{
>glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

>glLoadIdentity();
>    glLightfv(GL_LIGHT0, GL_POSITION, position);

With the code so far, your light will always be positioned exactly 80 units
up and 80 units behind the viewpoint, regardless of how the view changes.
The light is fixed in this position with respect to the viewer.

Quote:>    glRotatef(vola, 1.0, 0.0, 0.0);
>    glRotatef(angle, 0.0, 1.0, 0.0);

>    glTranslatef(xx, yy, zz);

>    glCallList(sky);

You might try specifying the light position just before you call the sky
list, that way it will be rotated and translated just like the sky is, and
therefore fixed in position with respect to the sky. (Not sure that's what
you want, just a guess.)

   -Paul Martz
    Hewlett Packard Workstation Systems Lab
    To reply, remove "DONTSPAM" from email address.

 
 
 

Light moving

Post by Kasra Rasae » Fri, 20 Aug 1999 04:00:00


Actually I was having the same problem.. its not the light thats moving I
think... but anyway.. what I did to fix this damn problem was I took out the
glMatrixMode(GL_MODELVIEW);
and I just left in glMatrixMode(GL_PROJECTION); and that should fix
everything... don't bother moving the light or anything like that.. just
declare the light in the beginning and everything would be just fine. just
don't use glMatrixMode(GL_MODELVIEW); hell man.. I don't even know what the
damn thing does.. it doesn't seem to be of any use.. because I have got
along without it just fine..



> >This is the display code of my simple game (it's the beginning). I want
to
> >leave the light in a point but when I move the player the light seem to
> move
> >too. How can I resolve my problem?

>-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-
> *
> >GLfloat position [] = {0.0, 80.0, 80.0, 1.0};

> >void display (void)
> >{
> >glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

> >glLoadIdentity();
> >    glLightfv(GL_LIGHT0, GL_POSITION, position);

> With the code so far, your light will always be positioned exactly 80
units
> up and 80 units behind the viewpoint, regardless of how the view changes.
> The light is fixed in this position with respect to the viewer.

> >    glRotatef(vola, 1.0, 0.0, 0.0);
> >    glRotatef(angle, 0.0, 1.0, 0.0);

> >    glTranslatef(xx, yy, zz);

> >    glCallList(sky);

> You might try specifying the light position just before you call the sky
> list, that way it will be rotated and translated just like the sky is, and
> therefore fixed in position with respect to the sky. (Not sure that's what
> you want, just a guess.)

>    -Paul Martz
>     Hewlett Packard Workstation Systems Lab
>     To reply, remove "DONTSPAM" from email address.

 
 
 

Light moving

Post by Alessandro Benedett » Sat, 21 Aug 1999 04:00:00


I tried to move the light code just before the sky list and now all work
fine. I also tried before to remove the glMatrixMode(GL_MODELVIEW) but
nothing on the screen appear...
Now I have another question:
How can I calculate the normal vector of a triangle?

Thank you.
Alessandro

 
 
 

Light moving

Post by Thomas Ker » Sat, 21 Aug 1999 04:00:00


Quote:> I tried to move the light code just before the sky list and now all work
> fine. I also tried before to remove the glMatrixMode(GL_MODELVIEW) but
> nothing on the screen appear...
> Now I have another question:
> How can I calculate the normal vector of a triangle?

calculate the dot product

void CalcNormal(GLfloat *StartPoint, // Ursprung
                GLfloat *Point1,     // X-Achse
                GLfloat *Point2,     // Y-Achse
                GLfloat *Normal)     // Z-Achse wird berechnet
{
  int       i;
  GLdouble  v1[3], v2[3];               // Richtungsvektoren
  GLdouble  nbetrag, kehrwert;          // zum Normalisieren

  for(i = 0; i < 3; i++) {
    v1[i] = (Point1[i] - StartPoint[i]);
    v2[i] = (Point2[i] - StartPoint[i]);
  }

  Normal[0] = v1[1]*v2[2] - v1[2]*v2[1];
  Normal[1] = v1[2]*v2[0] - v1[0]*v2[2];
  Normal[2] = v1[0]*v2[1] - v1[1]*v2[0];

  nbetrag = sqrt( Normal[0]*Normal[0] +
                  Normal[1]*Normal[1] +
                  Normal[2]*Normal[2] );
  if(nbetrag) {
    kehrwert = 1/nbetrag;
    for(i = 0; i < 3; i++)
      Normal[i] *= kehrwert;
  }

Quote:}

As you can see, the normal is only one vertex (StartPoint). You can
use it for the complete triangle or you can calculate more normals
(Point1, Point2 depends on you).

Thomas
--
http://home.t-online.de/home/thk01/navigate.htm
Please remove the NOSPAM. from my e-mail adress.

 
 
 

Light moving

Post by Felice Pollan » Sun, 22 Aug 1999 04:00:00


Use the cross product !

In italiano, che meglio.
devi scegliere due lati del trianglo come vettori e calcolarne il prodotto
vettoriale AxB, la formula la trovi su qualsiasi libro di geometria.
Occhio che AxB != BxA, quindi il verso con cui scegli i vertici ti fa
puntare la normale in modo diverso ( esterno o interno della figura ).
E' poi bene normalizzare il vettore ottenuto dividendone ciascuna componente
x la lunghezza, evitando di usare glEnable(GL_NORMALIZE).


>I tried to move the light code just before the sky list and now all work
>fine. I also tried before to remove the glMatrixMode(GL_MODELVIEW) but
>nothing on the screen appear...
>Now I have another question:
>How can I calculate the normal vector of a triangle?

>Thank you.
>Alessandro

 
 
 

Light moving

Post by Christophe Tche » Thu, 23 Sep 1999 04:00:00


just move the line glLIghtfv after the the line glCallList(sky).
remember that after you call glLoadIdentity, the matrix is identity, so the light is always at position, from the point of view the gamer, and you want the light at a fixed position in the world (like the sky ).
: This is the display code of my simple game (it's the beginning). I want to
: leave the light in a point but when I move the player the light seem to move
: too. How can I resolve my problem?
:
: -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
: GLfloat position [] = {0.0, 80.0, 80.0, 1.0};
:
: void display (void)
: {
: glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
:
: glLoadIdentity();
:     glLightfv(GL_LIGHT0, GL_POSITION, position);
:     glRotatef(vola, 1.0, 0.0, 0.0);
:     glRotatef(angle, 0.0, 1.0, 0.0);
:
:     glTranslatef(xx, yy, zz);
:
:     glCallList(sky);
:
:     glPushMatrix();
:         glTranslatef(0.0, -50.0, 0.0);
:         glRotatef(-90.0, 1.0, 0.0, 0.0);
:         glColor4f(1.0, 1.0, 1.0, 1.0);
:         glCallList(room);
:     glPopMatrix();
:
:     glCallList(floor);
:     glutSwapBuffers();
: }
: -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
:
:
: Thank You
: Alessandro
:
:
:
:
 
 
 

1. Why is my Lighting Moving???

I have an application that is written with C and GL.  This produces 3D
light source shaded Z buffered polygons. I have set up a variety of image
types and other displays so I have a number of mmode() and setmode() calls.

Anyway, the first time I render one type of image (surface geometry), my
lighting model doesn't work quite, the wrong surfaces seem to bit
bright/dark. If I go to another type of image (volumetric surfaces) it
looks great, and now if I go back to the first image it looks ok too. This
was a problem, but not horrible.

Now I made another modification and I can get one decently lit model and
then everything uses the "other" "horrible" lighting.

So ... any idea what I can be doing? Do I have an mmode() somewhere which
has moved my lighting model?

Any insight would be welcome.

John

2. Help with Graphic Buttons

3. light moving..?

4. Orphaned Response

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

6. Dye sublimation printer - cheap

7. Lights moving with camera

8. Light blockers moving when the camera moves

9. Inventor error when moving light

10. Tough One......moving light

11. moving light with boned object