Jump to content
  • Advertisement
Sign in to follow this  
radhikat

OpenGL Orbiting light

This topic is 3028 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 am new to Opengl and to this forum. I created a table, a teapot and a floor, and also some mouse click interactions. I want to now create a spot light orbiting the table. Not sure how I should do it. Given up after trying for over a day. Any ideas?

Share this post


Link to post
Share on other sites
Advertisement
Basic functions:

void renderTeaPot (GLfloat x, GLfloat y,GLfloat z, GLfloat a, GLfloat b, GLfloat c, GLfloat d, GLfloat colorr, GLfloat colorg, GLfloat colorb )
{
glPushMatrix();
glRotatef(a,b,c,d);
glTranslatef(x, y, z);
GLfloat colorpot[]={colorr,colorg,colorb,1.0};
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, colorpot);
glColor3f(colorr,colorg,colorb);
glutSolidTeapot(.5);
glPopMatrix();

}

void renderCubes(GLfloat x, GLfloat y, GLfloat z, GLfloat scalea, GLfloat scaleb, GLfloat scalec, GLfloat r, GLfloat g, GLfloat b, GLfloat size) {
glPushMatrix();
glTranslatef(x,y,z);
glScalef(scalea, scaleb, scalec);
GLfloat colorcube[]={r,g,b,1.0};
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, colorcube);
glColor3f(r,g,b);
glutSolidCube(size);
glPopMatrix();
}

void display (void) {
GLfloat position[] = {-1.0, -1.0f, -1.0f, 0.0};
GLfloat spotDir[]={0.0,1.0,-1.0};

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glTranslatef(1.0f,0.0f,-5.0f);

//glPushMatrix();

//glTranslated(0.0, 0.0, 1.5);
// glPopMatrix();



//Floor
renderCubes(-1.0, -2.5, 0.0, 2.0, 0.02, 2.0, 0.3, 0.3, 0.3, 5.0);


//Table
renderCubes(-1.0, -1.0, -1.0, 15.0, 1, 12.0, 1.0, 0.0, 0.0, .25);//Table top
//Table Legs
renderCubes(-3.4, -2.8, -1.5, 1.3, 10.0, 1.0, 1.0, 0.0, 0.0, .25);
renderCubes(1.4, -2.8, -1.5, 1.3, 10.0, 1.0, 1.0, 0.0, 0.0, .25);
renderCubes(-2.8, -2.8, -3, 1.3, 10.0, 1.0, 1.0, 0.0, 0.0, .25);
renderCubes(0.9, -2.8, -3, 1.3, 10.0, 1.0, 1.0, 0.0, 0.0, .25);



//Teapot
renderTeaPot(-1.0f, -0.5f, -1.0f, spin, 0.0f, 1.0f, 0.0f, colorr, colorg, colorb);
glPopMatrix();
glutSwapBuffers();
}

Share this post


Link to post
Share on other sites
The positions forming a circular orbit can be generated using polar coordinates.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!