PDA

View Full Version : Lights in animation



jade6
02-11-2001, 03:28 PM
I've been placing several primitive shapes on the screen, setting them all into motion (isolated rotation directions) and then blasting them with full diffuse- and specular light. Basically works Ok...

The problem I have is this: eventhough I re-apply the light every time in FormPaint, it still seems that the colors are calculated only once when the screen is initialized; it's as if there was a separate lamp rotating alongside each primitive. How can I re-draw the light based on the new object alignments?

zed
02-11-2001, 07:33 PM
check out the faq link on this sites homepage
if objects are changing shapes u need to recalculate the normals
if the viewers position has changed u will need to reposition the light after the camera change

jade6
02-12-2001, 01:33 PM
I was only vaguely aware of the importance of re-positioning the light every time, but it appears that I've been doing it all the time by coincidence. It still won't work, and the shapes are not deformed or anything. You can download a demonstration from:
http://www.netsonic.fi/~jade6/3Demo/LightDemo.exe

Here's some example code; I'm using Delphi at the moment, although I'll probably soon move to C++. I hope it doesn't matter that much... using Delphi, I mean.

By the way, I would also greatly appreciate any help with exporting this stuff into web-deployed ActiveX; I managed to do it once, but usually OpenGL starts drawing before the IE Device Context becomes available, and I have no idea how to fix that.

----------------------------

procedure TForm1.FormPaint(Sender: TObject);
begin
glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT);

glPushMatrix;
glTranslatef(2.2, 1.8, 2.3);
GLLight1.Draw;
glPopMatrix;

//
// Various push-pops and geometry drawing
//

GLScreen1.Swap;
end;

...and the light-class draw method looks like this. Note that I'm using two-sided material colouring and lighting since many of the primitives are at least partially open.

procedure TGLLight.Draw;
begin
if FActive then begin
glEnable(FSource);
end else begin
glDisable(FSource);
exit;
end;

glLightfv(FSource, GL_POSITION, @FLocation);
glLightfv(FSource, GL_DIFFUSE, @FDiffuse);
glLightfv(FSource, GL_SPECULAR, @FSpecular);

if FSpotLight then begin
glLightfv(FSource, GL_SPOT_CUTOFF, @FCutOff);
glLightfv(FSource, GL_SPOT_DIRECTION, @FDirect);
end;
end;