PDA

View Full Version : Orbiting light around an object



radhikarrr
05-03-2010, 05:39 PM
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?

radhikarrr
05-03-2010, 05:53 PM
Basic Functions:
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();
}