Archived

This topic is now archived and is closed to further replies.

How do i tell which direction a spotlight is pointing

This topic is 5009 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

i have some how amazing created a flashlight that points at whatever the eye is pointing at. how do i tell what a light is pointing at. i any one cares here''s the relative code. float ambientLight[] = {0.3f,0.5f,0.8f,1}; float diffuseLight[] = {0.25f,0.25f,0.25f,1}; float lightPosition[] = {1.0f, 0.0f, 8.0f, 1.0f}; float matAmbient[] = {0,0,0,1}; float matDiff[] = {1,1,1,1}; float matSpec[] = {.1,.1,.1,1}; glEnable(GL_LIGHTING); glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuseLight); glLightfv(GL_LIGHT0, GL_POSITION, lightPosition); glLightf(GL_LIGHT0, GL_SPOT_CUTOFF, 10.0f); glLightf(GL_LIGHT0, GL_SPOT_EXPONENT, 8.0f); glMaterialfv(GL_FRONT, GL_DIFFUSE, matDiff); glMaterialfv(GL_FRONT, GL_SPECULAR, matSpec); glMateriali(GL_FRONT, GL_SHININESS, 128); glColorMaterial(GL_FRONT, GL_DIFFUSE); glEnable(GL_LIGHT0);

Share this post


Link to post
Share on other sites
thank you verry much. is it defaulted to follow the camera?

edit i take it that you input the position in euler coordinites, yaw pitch and roll?

[edited by - cibressus on March 29, 2004 1:03:43 AM]

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
No. Set the camera-position:
glLightfv(GL_LIGHT0, GL_POSITION, lightPosition);

Then, set its direction:
glLightfv(GL_LIGHT0, GL_SPOT_DIRECTION, lightDirection);

The direction is a normalized vector.

lightDirection = objectPosition - lightPosition;
lightDirection.normalize();

If you want it ''aimed'' at a specific location.

Share this post


Link to post
Share on other sites