Jump to content

View more

Image of the Day

Boxes as reward for our ranking mode. ヾ(☆▽☆)
#indiedev #gamedev #gameart #screenshotsaturday https://t.co/ALF1InmM7K
IOTD | Top Screenshots

The latest, straight to your Inbox.

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


Sign up now

Opengl - Light rotating around object (video)

4: Adsense

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.


  • You cannot reply to this topic
3 replies to this topic

#1 Shawn619   Members   

342
Like
1Likes
Like

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);
    glLoadIdentity();
 
 
 
    //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();
}


#2 Shawn619   Members   

342
Like
0Likes
Like

Posted 23 April 2013 - 08:07 PM

Solved.



#3 MarkS   Members   

3439
Like
0Likes
Like

Posted 24 April 2013 - 04:38 PM

Solved.

YAY! huh.png dry.png

 

Care to elaborate?



#4 Shawn619   Members   

342
Like
0Likes
Like

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.