Jump to content

  • Log In with Google      Sign In   
  • Create Account

Interested in a FREE copy of HTML5 game maker Construct 2?

We'll be giving away three Personal Edition licences in next Tuesday's GDNet Direct email newsletter!

Sign up from the right-hand sidebar on our homepage and read Tuesday's newsletter for details!


We're also offering banner ads on our site from just $5! 1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


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.

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

#1 Shawn619   Members   -  Reputation: 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();
}


Sponsor:

#2 Shawn619   Members   -  Reputation: 342

Like
0Likes
Like

Posted 23 April 2013 - 08:07 PM

Solved.



#3 MarkS   Prime Members   -  Reputation: 882

Like
0Likes
Like

Posted 24 April 2013 - 04:38 PM

Solved.

YAY! huh.png dry.png

 

Care to elaborate?



#4 Shawn619   Members   -  Reputation: 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.



PARTNERS