Hey guys, Im pretty new to OpenGL and I’m currently messing around with Translated, Rotated and Scale.
What I am trying to do is move an object (glutSolidSphere) round in a circle however I have had no luck after hours of trying to figure this out
I have so far managed to draw a circle but thats as far as I have gotten.
Here is my Display function:
void display() {
glClear(GL_COLOR_BUFFER_BIT );
glMatrixMode(GL_MODELVIEW);
glLoadIdentity(); // reset the matrix
gluLookAt(cam.pos.x, cam.pos.y, cam.pos.z,
cam.lookAt.x, cam.lookAt.y, cam.lookAt.z,
cam.up.x, cam.up.y, cam.up.z);
drawAxes();
glPushMatrix();
glColor3f(255,0,255);
glTranslated(p1->getPosition().posx, p1->getPosition().posy, p1->getPosition().posz);
glRotated(0, 0, 0.5, 1);
newCircle(0, 0, 10);
glScalef(0.5, 0.5, 0.5);
glutSolidSphere(p2->getradius(), p2->getslices(), p2->getstacks());
glPopMatrix();
glColor3f(0.0, 0.0, 0.0);
stringstream ss;
stringstream planet;
ss << "Camera (" << cam.pos.x << ", " << cam.pos.y << ", " << cam.pos.z << ")";
outputText(-1.0, 0.5, ss.str());
planet << p1->getname() << " ( " << planetPos.posx << ", " << planetPos.posy << ", " << planetPos.posz << ")";
outputText(p1->getPosition().posx, p1->getPosition().posy, planet.str());
glFlush();
}
the newcircle() function that I am calling is used to draw the circle and my attempt to move the object. here is the function:
void newCircle(float x, float z, float radius)
{
glBegin(GL_LINE_STRIP);
for (float i = 0.0; i < 2*3.14159; i += 0.05)
{
glVertex3f(x + cos(i)*radius,0, z + sin(i)*radius);
glTranslatef(x + cos(i)*radius,0, z + sin(i)*radius);
}
glutPostRedisplay();
}