View more

View more

View more

### Image of the Day Submit

IOTD | Top Screenshots

### The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.

# Opengl - Light rotating around object (video)

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

3 replies to this topic

### #1Shawn619  Members

Posted 22 April 2013 - 07:34 PM

I translate my object(soccer ball) -20z pixels away from the camera, keep the camera and rotating sphere(blue sphere=light, so you know where the light is) at origin, and rotate the light(represented by the sphere) around the origin to simulate moving light.

I think this short video(00:14) should clear things up:

*note: blue sphere=light, soccer ball=object, grey plane=flat ground

Why is my object acting as if it is at the origin, where the light is rotating around, but in reality it is -20z further away from the origin?

main function:

void drawScene() {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

glMatrixMode(GL_MODELVIEW);

//lighting+sphere
rot+=1.0f;
glPushMatrix();

//glTranslatef(0.0f, 0.0f, -20.0f);
glRotatef(rot,0.0f,1.0f,0.0);
glTranslatef(0.0f, 0.0f, 10.0f);

initSceneLighting();//set position light[0] {0,0,0,1}
drawSceneSphereLight();//blue sphere
glPopMatrix();

//soccer ball(object)
glPushMatrix();
glTranslatef(0.0f, 0.0f, -20.0f);

glColor3f(1.0f,0.0f,0.0f);
glCallList(soccerBall);
glPopMatrix();

//floor
glPushMatrix();

glColor3f(0.5f,0.5f,0.4f);
drawSceneFloor();//grey ground

glPopMatrix();

glutSwapBuffers();
}


### #2Shawn619  Members

Posted 23 April 2013 - 08:07 PM

Solved.

### #3MarkS  Members

Posted 24 April 2013 - 04:38 PM

Solved.

YAY!

Care to elaborate?

### #4Shawn619  Members

Posted 24 April 2013 - 09:52 PM

There was actually a dot product error in my shader program, which made the lighting go hairwire.

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.