I have an object which i want to move around in a circle in Open GL/ Visual Studio. But so far, the object is only rotating around itself.
How can i make it move in a circular way?
Currently, it just translates the object instantly, but not over the course of my rotation animation.
This is my code in the display function - because i was told if you want the object not to rotate around itself, you need to translate. But so far, my object just ignores the translation here completely and still revolves around itself..
glRotatef(0.0f, 0, 1, 0);
glTranslatef(2.0, 0.0, 0.0);
glRotatef(angle, 0.0, -1.0, 0.0);
drawExcavator(); // draws the object
And this is my animating function for later on to define the angle i use in the glRotatef call:
void animate() {
// calculating the time needed for the animation
static long time = clock();
long oldTime = time;
float diffTime;
time = clock();
diffTime = ((float)(time - oldTime)) / ((float)CLOCKS_PER_SEC); // taken from the exercise sheets
// checking if the animation has not been stopped:
if (!pause) {
angle += diffTime*rotateSpeed;
elapsedTime += diffTime;
frameCount++;
// adding up the frames so that they are shown in the window:
if (elapsedTime > 1.0)
{
// counting the fps so that they are outprinted in the window line:
fps = (float)frameCount / elapsedTime;
fps = fps / 100; // for correct frame numbers
elapsedTime = 0.0;
frameCount = 0.0;
}
}
}