Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

11991 Posts in 1587 Topics- by 3509 Members - Latest Member: lioneltenel

26. May 2012, 08:30:33 pm
Xith3D CommunityGeneral CategoryGeneral Discussion (Moderators: Marvin Fröhlich, 'n ddrylliog)A flashlight inplementation
Pages: 1 [2]
Print
Author Topic: A flashlight inplementation  (Read 3177 times)
Marvin Fröhlich
Xith Lord
Administrator
Guru
*****
Offline Offline

Posts: 4381


May the 4th, be with you...


View Profile
« Reply #15 on: 19. September 2007, 10:56:08 am »

Have you tried setting the light position before the viewing transformation (not in the transformation but so that the transformation occurs after the position of the light is declared)?

The view transformation is always pushed to opengl before all transformgroups are. So this won't work. Even if I have little of time this week, I will try to find some time to have a look at this.

Marvin
Logged
Pandaemonium
Enjoying the stay
*
Offline Offline

Posts: 85


If at first you don't succeed; call it version 1.0


View Profile
« Reply #16 on: 19. September 2007, 03:15:28 pm »

I don't know how to get this to work in Xith, but here is a snippet taken from the Red Book which I think is the overall goal:

Example 5-7 : Light Source That Moves with the Viewpoint
Code:
GLfloat light_position() = { 0.0, 0.0, 0.0, 1.0 };

glViewport(0, 0, (GLint) w, (GLint) h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(40.0, (GLfloat) w/(GLfloat) h, 1.0, 100.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glLightfv(GL_LIGHT0, GL_POSITION, light_position);

If the viewpoint is now moved, the light will move along with it, maintaining (0, 0, 0) distance, relative to the eye. In the continuation of Example 5-7, which follows next, the global variables (ex, ey, ez) and (upx, upy, upz) control the position of the viewpoint and up vector. The display() routine that's called from the event loop to redraw the scene might be this:

Code:
static GLdouble ex, ey, ez, upx, upy, upz;

void display(void)
{
    glClear(GL_COLOR_BUFFER_MASK | GL_DEPTH_BUFFER_MASK);
    glPushMatrix();
        gluLookAt (ex, ey, ez, 0.0, 0.0, 0.0, upx, upy, upz);
        glutSolidTorus (0.275, 0.85, 8, 15);
    glPopMatrix();
    glFlush();
}

When the lit torus is redrawn, both the light position and the viewpoint are moved to the same location. As the values passed to gluLookAt() change and the eye moves, the object will never appear dark, because it is always being illuminated from the eye position. Even though you haven't respecified the light position, the light moves because the eye coordinate system has changed.

This method of moving the light can be very useful for simulating the illumination from a miner's hat. Another example would be carrying a candle or lantern. The light position specified by the call to glLightfv(GL_LIGHTi, GL_POSITION, position) would be the x, y, and z distance from the eye position to the illumination source. Then as the eye position moves, the light will remain the same relative distance away.
Logged
Marvin Fröhlich
Xith Lord
Administrator
Guru
*****
Offline Offline

Posts: 4381


May the 4th, be with you...


View Profile
« Reply #17 on: 20. September 2007, 12:14:58 am »

I have created a View attached SpotLight testcase (org.xith3d.test.lighting.ViewSpotlightTest). Well, this testcase needs a better shading model like phong shading. But it still demonstrates, what you need.

I will later create a directly supported internal light-view-attachment. But not this week, I suppose.

Marvin
Logged
hawkwind
Getting respectable
***
Offline Offline

Posts: 363



View Profile Email
« Reply #18 on: 20. September 2007, 01:47:01 pm »

nice....thanx...let me play with it.
Logged
Marvin Fröhlich
Xith Lord
Administrator
Guru
*****
Offline Offline

Posts: 4381


May the 4th, be with you...


View Profile
« Reply #19 on: 24. September 2007, 05:31:38 pm »

Now the integrated solution is online and works. Have a look at the testcase. Yu can also attach a light to a Node in the scenegraph. Have a look at SphereMotionLightingTest for an example.

Marvin
Logged
Pages: 1 [2]
Print
Jump to:  

Theme orange-lt created by panic