SIMPLE OpenGL Questions

Started by
14 comments, last by neonfaktory 21 years, 4 months ago
WAHH, it was something dumb I was doing... UGH, i do that all the time where I post a prob and then solve it like, a minute later. ANYWAY, I was translating to the center of my object and THEN trying to place the light, which was putting the light inside my box... Now I just gotta figure out why it isnt rotating (I''m still getting the hang of these Matrix Transformations), if anyone can find a flaw in the order of my Transformations and why the light wouldnt rotate, thatd be helpfull.. Haha, chances are I''ll solve it minutes after posting this THanks anyways, though
weee!
Advertisement
Maybe I should ask a little more clearly..

How do I get a light to rotate around an object?

I have the light in working condition, just not moving. The light position is at 0,0,0. I''m basically using this piece of code to rotate it, and unless my perception of how lights work is wrong (which i guess it probably is), I figured it should work...

glPushMatrix();
glRotatef(lAngle, 0.0f, 1.0f, 0.0f);
glLightfv(GL_LIGHT0, GL_POSITION, LightPosition0);
glPopMatrix();
..Draw Object..

The way I saw it was that you techincally rotate the world by lAngle, and then place the light position with the Lightfv command. THen you restore the prev settings and the light should remain where you had put it - rotated around the object.. ack, i dunno how this is supposed to work properly - the light just stays at the origin. Any help would be great.
weee!
If your light position is at the origin, then rotating it will do nothing - it simply pivots on the spot. You want something like:

glPushMatrix();
glRotatef(lAngle, 0.0f, 1.0f, 0.0f);
glTranslatef(orbitDistance, 0.0f, 0.0f);
glLightfv(GL_LIGHT0, GL_POSITION, LightPosition0);
glPopMatrix();

(I may have the rotate/translate commands in the wrong order though..)
Ahh... For some reason I was thinking that the Rotatef was technically rotating me around the object... don''t know WHY.

To avoid some fat math sin/cos calcs, i think I might set the "z" of the light''s position to the radius of the light orbit, translate the camera to the center of the cube, and THEN call Rotatef, so itll spin the light around... Let''s see if this works
Again, thanks for all the help Orangy
weee!
YUP! Worked like a charm - woo!x3
weee!
Ok, probably another simple fix here...

I have implemented TGA loading with alpha blending and all that, but I''ve run into a wierd problem.

For some reason, only the front face of my cube does NOT have transparency. The other faces show through just fine, but for some strange reason you can''t see through the parts of the front face that you can the other faces. ANy ideas? I tried to make extra sure all the sides were generated the same way (CCW) and the normals were all correct.. It seems wierd that only one face is not working, too. I dunno, any help/suggestions would be great.
weee!

This topic is closed to new replies.

Advertisement