PDA

View Full Version : My Lights rotates.. not good



McZ
11-10-2001, 02:21 AM
it looks like my light rotate when I render My quake 3 health sphere http://www.opengl.org/discussion_boards/ubb/smile.gif I canīt get why ?! the light pos is 0,20,0 but when the Helth sphere rotates and the + inside reflect the light it looks like the light is 0,-20,0 and sometimes other places..

this is how I render:

void render()
{
clear z-buffer and color
set Model matrix and load identity

move the sceen to z:-100 (or camera to z:100)

set the light pos to 0,20,0

push matrix
rotate the health sphere and +
draw the +
blend the sphere and draw it
pop matrix
}

this is how I do it.. but if I render My spaceship I drawed in 3Ds max the lights works perfect.

T2k
11-10-2001, 02:39 AM
try to set the fourth light coord to 1, i think you used 0, which will produce a directional light...
or you normals are calculated wrong (you have to reverse the sign of a normal if the frontface changes from cw to ccw or ccw to cw)

McZ
11-10-2001, 02:53 AM
I have tried with the fourth as 1 and 0 no different and the objects I use is from 3Ds with the normals from the .ase file and they work with the same code for my teapot and spaceship.. the teapot use 3ds normals and the spaceship I have to calculate them but they work.. I have tried to calculate the normals to but there is not working any better..

jlg1636
11-10-2001, 07:37 PM
Try this. All I did was switch the statements that set the light position and set the camera position. If using gluLookAt(), it sets a rotation parameter, so your light will also be rotated if you specify it after gluLookAt(). So try setting the light position first.

void render()
{
clear z-buffer and color
set Model matrix and load identity

set the light pos to 0,20,0

move the sceen to z:-100 (or camera to z:100)

push matrix
rotate the health sphere and +
draw the +
blend the sphere and draw it
pop matrix
}

dorbie
11-10-2001, 11:53 PM
You are talking about positioning the light w.r.t. the transformation.

You certainly want the light positioned after the viewing transform unless it is attached to the viewer/ownship, the key question is what is the purpose of the "move the sceen to z:-100 (or camera to z:100)" transform. Is it a scene move or a camera move, this is critical for the purpose of lighting. Are you moving the camera +100 or moving the object -100, the answer will determine whether the light should be positioned before or after the translate. One will produce results that you don't expect mainly because the light will be translated to a different place. It should only affect local lights though since this is a translation, not a rotation.


[This message has been edited by dorbie (edited 11-11-2001).]

McZ
11-12-2001, 01:24 AM
I have tried to set the light before I move the scen and after but there is no different and I use glTranslatef(0.0f, 0.0f, -100.0f); when I move the scen.. and in my book OpenGL superbible they say that there is no difference in moving the scen -100 or moving the camera +100.

dorbie
11-12-2001, 04:13 AM
Are you sure it's the light that's causing the problem? What about surface normals or texgen spheremap? There doesn't appear to be anything wrong with your light position w.r.t. the object. The lighting on the object SHOULD change as it rotates, so I hope there's no confusion over expectations.

dorbie
11-12-2001, 04:14 AM
P.S. If the normals are in the wrong direction it would appear that the light was in the wrong place.

FoxDie
11-12-2001, 07:32 AM
How can I calculate the spot direction vector?

dorbie
11-12-2001, 10:40 PM
You supply this and it gets transformed. If this is for debug then the simplest thing to try is to draw a vector when you position the light, just draw a line from lightpos to lightpos+vector_direction. (you might want to turn off lighting when you draw this) The simplest test is to use a point light with no spot orientation, that should at least tell you if the position is correct, then worry about the vector.

McZ
11-12-2001, 11:44 PM
but I read the object and normals from an .Ase file exported from 3D Studio Max 2.5 and I have tried to calculate my own normals.. and the light works if I change the object to my spaceship I made in 3D studio max 2.5.