I am working on a simple OpenGL project where I need to simulate the movement of a wheel. I want the wheel to move in a circular path based on its rotation angle. Currently, the wheel moves forward in a straight line when I press the ‘w’ key. I have functions to rotate the wheel left and right, but I’m struggling to make it move in a circular path.
Here is the relevant part of my code:
GLfloat deg = 0;
GLfloat xWheel = 0, yWheel = -1.2, zWheel = 2;
GLfloat wheelColor[3] = { 0, 0, 0 };
// Function to rotate the wheel to the left
static void rotateWheelLeft() {
if (deg > -45) {
deg -= 2.0f;
}
}
// Function to rotate the wheel to the right
static void rotateWheelRight() {
if (deg < 45) {
deg += 2.0f;
}
}
// Function to move the wheel forward based on its rotation angle
static void moveForward() {
GLfloat radianAngle = deg * 3.14 / 180;
GLfloat forwardX = 0.1f * cos(radianAngle);
GLfloat forwardZ = 0.1f * sin(radianAngle);
xWheel -= forwardX;
zWheel += forwardZ;
}
Current behavior:
The wheel moves forward in a straight line based on the rotation angle when I call moveForward().
I can rotate the wheel left and right using the rotateWheelLeft() and rotateWheelRight() functions.
Desired behavior:
I want the wheel to move in a circular path while respecting its rotation angle.
The wheel should follow a circular trajectory instead of moving in a straight line.