So I started out with OpenGL recently and I wanted to make a simple
simulation of our Solar System (although the main light source isn't the
Sun). It looks quite nice when viewed from above.
My next move was to implement changing perspectives. For example, when I
hit a button on my keyboard, I should be looking from the Earth towards the
Sun. And the Earth, of course, keeps circling the Sun along with me on it.
But alas, with this change of perspective, the light source moved too, and
it moves with me all the time. I defined light thus:
GLfloat lightSourcePosition[] = {10.0, 10.0, 10.0, 0.0};
GLfloat lightSourceDirection[] = {0.0, 0.0, 0.0, 0.0};
glLightfv(GL_LIGHT0, GL_POSITION, lightSourcePosition);
glLightfv(GL_LIGHT0, GL_SPOT_DIRECTION, lightSourceDirection);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
I change perspective by loading identity matrix and then calling
gluLookAt() to say where I want to look.
So, why does this light move with me? How can I make it stay at the same
place all the time while I change camera position?
The Red Book isn't very helpful in this issue because the example given
there has stationary light only until I change perspective, so it's no
good.
--
"Let's see what's out there. Engage."
Jean Luc Picard, Star Trek: TNG, Encounter at Farpoint
http://pinpoint.wordpress.com/
|
|
0
|
|
|
|
Reply
|
enlorkMAKNI (3)
|
5/20/2008 7:40:36 PM |
|
On May 20, 9:40 pm, Sourcerer <enlorkMA...@OVOgmail.com> wrote:
>
> GLfloat lightSourcePosition[] = {10.0, 10.0, 10.0, 0.0};
> GLfloat lightSourceDirection[] = {0.0, 0.0, 0.0, 0.0};
>
> glLightfv(GL_LIGHT0, GL_POSITION, lightSourcePosition);
> glLightfv(GL_LIGHT0, GL_SPOT_DIRECTION, lightSourceDirection);
>
My copy of the manual says: "The position is transformed by the
modelview matrix when glLight is called"
Maybe that's the problem.
--
<\___/>
/ O O \
\_____/ FTB. Remove my socks for email address.
|
|
0
|
|
|
|
Reply
|
fungus
|
5/20/2008 9:19:40 PM
|
|
On Tue, 20 May 2008 14:19:40 -0700 (PDT), fungus wrote:
> On May 20, 9:40 pm, Sourcerer <enlorkMA...@OVOgmail.com> wrote:
>>
>> GLfloat lightSourcePosition[] = {10.0, 10.0, 10.0, 0.0};
>> GLfloat lightSourceDirection[] = {0.0, 0.0, 0.0, 0.0};
>>
>> glLightfv(GL_LIGHT0, GL_POSITION, lightSourcePosition);
>> glLightfv(GL_LIGHT0, GL_SPOT_DIRECTION, lightSourceDirection);
>>
>
> My copy of the manual says: "The position is transformed by the
> modelview matrix when glLight is called"
>
> Maybe that's the problem.
Well, that doesn't really matter (i.e. I could live with that). What
matters is that the position of the light is transformed every time I
change the modelview matrix -- after the light is already placed in the
scene, by doing glLoadIdentity() and gluLookAt() -- and I don't want that
to happen.
If that can't work, is there another way to change my perspective in the
scene which won't move the light with me?
--
"Let's see what's out there. Engage."
Jean Luc Picard, Star Trek: TNG, Encounter at Farpoint
http://pinpoint.wordpress.com/
|
|
0
|
|
|
|
Reply
|
Sourcerer
|
5/20/2008 10:00:05 PM
|
|
On May 21, 12:00 am, Sourcerer <enlorkMA...@OVOgmail.com> wrote:
>
> > "The position is transformed by the
> > modelview matrix when glLight is called"
>
> Well, that doesn't really matter (i.e. I could live with that). What
> matters is that the position of the light is transformed every time I
> change the modelview matrix
????
--
<\___/>
/ O O \
\_____/ FTB. Remove my socks for email address.
|
|
0
|
|
|
|
Reply
|
fungus
|
5/20/2008 11:45:44 PM
|
|
"Sourcerer" <enlorkMAKNI@OVOgmail.com> wrote in message
news:jwnr5c1ltwdo.14dr6h1t1oq0v$.dlg@40tude.net...
> On Tue, 20 May 2008 14:19:40 -0700 (PDT), fungus wrote:
>
>> On May 20, 9:40 pm, Sourcerer <enlorkMA...@OVOgmail.com> wrote:
>>>
>>> GLfloat lightSourcePosition[] = {10.0, 10.0, 10.0, 0.0};
>>> GLfloat lightSourceDirection[] = {0.0, 0.0, 0.0, 0.0};
>>>
>>> glLightfv(GL_LIGHT0, GL_POSITION, lightSourcePosition);
>>> glLightfv(GL_LIGHT0, GL_SPOT_DIRECTION, lightSourceDirection);
>>>
>>
>> My copy of the manual says: "The position is transformed by the
>> modelview matrix when glLight is called"
>>
>> Maybe that's the problem.
>
> Well, that doesn't really matter (i.e. I could live with that). What
> matters is that the position of the light is transformed every time I
> change the modelview matrix -- after the light is already placed in the
> scene, by doing glLoadIdentity() and gluLookAt() -- and I don't want that
> to happen.
>
> If that can't work, is there another way to change my perspective in the
> scene which won't move the light with me?
>
> --
> "Let's see what's out there. Engage."
> Jean Luc Picard, Star Trek: TNG, Encounter at Farpoint
> http://pinpoint.wordpress.com/
Check out the FAQ:
"Here are some more specific questions, and their answers:
a.. How can I make my light position stay fixed relative to my eye
position? How do I make a headlight?
You need to specify your light in eye coordinate space. To do so, set the
ModelView matrix to the identity, then specify your light position. To make
a headlight (a light that appears to be positioned at or near the eye and
shining along the line of sight), set the ModelView to the identity, set the
light position at (or near) the origin, and set the direction to the
negative Z axis.
When a light's position is fixed relative to the eye, you don't need to
respecify the light position for every frame. Typically, you specify it once
when your program initializes.
a.. How can I make my light stay fixed relative to my scene? How can I put
a light in the corner and make it stay there while I change my view?
As your view changes, your ModelView matrix also changes. This means
you'll need to respecify the light position, usually at the start of every
frame. A typical application will display a frame with the following
pseudocode:
Set the view transform. Set the light position
//glLightfv(GL_LIGHT_POSITION,.) Send down the scene or model geometry. Swap
buffers.
If your light source is part of a light fixture, you also may need to
specify a modeling transform, so the light position is in the same location
as the surrounding fixture geometry.
a.. How can I make a light that moves around in a scene?
Again, you'll need to respecify this light position every time the view
changes. Additionally, this light has a dynamic modeling transform that also
needs to be in the ModelView matrix before you specify the light position.
In pseudocode, you need to do something like:
Set the view transform Push the matrix stack Set the model transform to
update the light's position Set the light position
//glLightfv(GL_LIGHT_POSITION,.) Pop the matrix stack Send down the scene or
model geometry Swap buffers. "
|
|
0
|
|
|
|
Reply
|
jbwest
|
5/21/2008 1:56:53 AM
|
|
On May 20, 8:40=A0pm, Sourcerer <enlorkMA...@OVOgmail.com> wrote:
> So I started out with OpenGL recently and I wanted to make a simple
> simulation of our Solar System (although the main light source isn't the
> Sun). It looks quite nice when viewed from above.
>
> My next move was to implement changing perspectives. For example, when I
> hit a button on my keyboard, I should be looking from the Earth towards th=
e
> Sun. And the Earth, of course, keeps circling the Sun along with me on it.=
>
> But alas, with this change of perspective, the light source moved too, and=
> it moves with me all the time. I defined light thus:
>
> GLfloat lightSourcePosition[] =3D {10.0, 10.0, 10.0, 0.0};
> GLfloat lightSourceDirection[] =3D {0.0, 0.0, 0.0, 0.0};
>
> glLightfv(GL_LIGHT0, GL_POSITION, lightSourcePosition);
> glLightfv(GL_LIGHT0, GL_SPOT_DIRECTION, lightSourceDirection);
>
> glEnable(GL_LIGHTING);
> glEnable(GL_LIGHT0);
>
> I change perspective by loading identity matrix and then calling
> gluLookAt() to say where I want to look.
>
> So, why does this light move with me? How can I make it stay at the same
> place all the time while I change camera position?
>
> The Red Book isn't very helpful in this issue because the example given
> there has stationary light only until I change perspective, so it's no
> good.
>
> --
> "Let's see what's out there. Engage."
> Jean Luc Picard, Star Trek: TNG, Encounter at Farpointhttp://pinpoint.word=
press.com/
Hi m8,
Just repeat the following lines again after the gluLookAt command:
gluLookAt(....
glLightfv(GL_LIGHT0, GL_POSITION, lightSourcePosition);
glLightfv(GL_LIGHT0, GL_SPOT_DIRECTION, lightSourceDirection);
it will work.
|
|
0
|
|
|
|
Reply
|
General
|
5/21/2008 6:14:13 PM
|
|
On Wed, 21 May 2008 11:14:13 -0700 (PDT), General wrote:
> On May 20, 8:40�pm, Sourcerer <enlorkMA...@OVOgmail.com> wrote:
>> So I started out with OpenGL recently and I wanted to make a simple
>> simulation of our Solar System (although the main light source isn't the
>> Sun). It looks quite nice when viewed from above.
>>
>> My next move was to implement changing perspectives. For example, when I
>> hit a button on my keyboard, I should be looking from the Earth towards the
>> Sun. And the Earth, of course, keeps circling the Sun along with me on it.
>>
>> But alas, with this change of perspective, the light source moved too, and
>> it moves with me all the time. I defined light thus:
>>
>> GLfloat lightSourcePosition[] = {10.0, 10.0, 10.0, 0.0};
>> GLfloat lightSourceDirection[] = {0.0, 0.0, 0.0, 0.0};
>>
>> glLightfv(GL_LIGHT0, GL_POSITION, lightSourcePosition);
>> glLightfv(GL_LIGHT0, GL_SPOT_DIRECTION, lightSourceDirection);
>>
>> glEnable(GL_LIGHTING);
>> glEnable(GL_LIGHT0);
>>
>> I change perspective by loading identity matrix and then calling
>> gluLookAt() to say where I want to look.
>>
>> So, why does this light move with me? How can I make it stay at the same
>> place all the time while I change camera position?
>>
>> The Red Book isn't very helpful in this issue because the example given
>> there has stationary light only until I change perspective, so it's no
>> good.
>>
>> --
>> "Let's see what's out there. Engage."
>> Jean Luc Picard, Star Trek: TNG, Encounter at Farpointhttp://pinpoint.wordpress.com/
>
> Hi m8,
>
> Just repeat the following lines again after the gluLookAt command:
> gluLookAt(....
> glLightfv(GL_LIGHT0, GL_POSITION, lightSourcePosition);
> glLightfv(GL_LIGHT0, GL_SPOT_DIRECTION, lightSourceDirection);
>
> it will work.
Thanks, that worked perfectly.
--
"Let's see what's out there. Engage."
Jean Luc Picard, Star Trek: TNG, Encounter at Farpoint
http://pinpoint.wordpress.com/
|
|
0
|
|
|
|
Reply
|
Sourcerer
|
5/25/2008 8:46:35 PM
|
|
|
6 Replies
236 Views
(page loaded in 0.092 seconds)
Similiar Articles: Why are lights moving? - comp.graphics.api.openglSo I started out with OpenGL recently and I wanted to make a simple simulation of our Solar System (although the main light source isn't the Sun). It... best graphic adapter - comp.unix.solaris... fried? - comp.laptops ..... yesterday, i lost the NIC in my pc, the A/C adapter of my ... up, nothing comes on the screen at all, the top ... Why are lights moving ... Changing the Viewpoint - OpenGL and Cg - comp.graphics.api.opengl ...Why are lights moving? - comp.graphics.api.opengl So I started out with OpenGL recently and I wanted to make a simple simulation of ... How can I put a light in the corner ... Amber light on Sunfire Cabinet - comp.unix.solarisHi there, the Frame-Manager's Amber light is active on Sun fire-e4900 Cabinet. I have seen in the dmesg and SC logs but nothing appears there.As far... moving in 3D - comp.lang.c++Moving 3D Objects | CAD Tips Why not just use the XYZ filters? Move or copy in 3d space using ... models, as well as build your own scenes, props and environments, light ... Stretch, moving slow in Cadence 6 - comp.cad.cadence... the edge of a big polygon to stretch it or try to move ... I am not sure why. If I work at lower resolutions with ... Net high light in schematic composer - comp.cad.cadence ... Detecting when the garage door opens or is left opened - comp.home ...The cat's even gotten used to the "clunk" of the appliance module and >will move ... Monitor power lights - why did they change from green to amber ... Detecting when the ... Positioning the model into the scene with mouse - comp.graphics ...Why are lights moving? - comp.graphics.api.opengl Positioning the model into the scene with mouse - comp.graphics ... Why are lights moving? - comp.graphics.api.opengl ... X10 PC Interface upgrade - comp.home.automationThat's why I was thinking moving to web based one but they > are just too expensive and don't ... would have to, with the >> "green" campaign to replace incandescent lights ... Optimal filtering method to degrade image resolution? - comp.soft ...I have seen moving average, low-pass FFT and DCT filters ... this type of data, but no good explanation is given why ... So basically I think you'd block average down -- light ... Why does light move? - Instructables - Make, How To, and DIYFrom the theory of relativity, we learn that time is relative to the observer. And that time starts going slower and slower as the observer (reference... Why does light move? Why doesn't it just stand still? | AnswerbagWhy does light move? Why doesn't it just stand still? Light is made of photons, photons are pure energy. Energy by definition can not be still. Therefore light has to ... 7/24/2012 3:34:31 PM
|