This post has been de-listed
It is no longer included in search results and normal feeds (front page, hot posts, subreddit posts, etc). It remains visible only via the author's post history.
include <GL/glut.h>
float angle[4] = { 0.0, 0.0, 0.0, 0.0 }; // Initialize angle array for rotation int lowerArmDirection = 1; // 1 for clockwise, -1 for counterclockwise int upperArmDirection = 1; // 1 for clockwise, -1 for counterclockwise int upperAssDirection = 1; const float BASE_HEIGHT = 0.9; const float LOWER_ARM_LENGTH = 1.5; const float UPPER_ARM_LENGTH = 1.0; const float UPPER_ASS_LENGTH = 1.0; const float TAIL_LENGTH = 0.5;
void drawThigh() { glPushMatrix(); glScalef(1.5, BASE_HEIGHT, 1.0); glutWireCube(0.8);
glTranslatef(0.4, 0.7, 0.0);
glutWireCube(0.7);
glTranslatef(0.2, -0.7, 0.0);
glutWireCube(0.4);
glTranslatef(-0.9, 0.7, 0.0);
glutWireCube(0.7);
glTranslatef(0.2, 0.7, 0.0);
glutWireCube(0.7);
glPopMatrix();
}
void drawLowerArm() { glPushMatrix(); glTranslatef(0.0, (LOWER_ARM_LENGTH * 0.5), 0.0); glScalef(0.2, LOWER_ARM_LENGTH, 0.2); glutWireCube(2.0); glPopMatrix(); }
void drawUpperArm() { glPushMatrix(); glRotatef(-45, 0.0, 0.0, 1.0); glTranslatef(0.0, (UPPER_ARM_LENGTH * 1.6), -1.0); glScalef(0.1, UPPER_ARM_LENGTH, 0.1); glutWireCube(3.0); glPopMatrix(); }
void drawTaid() { glPushMatrix(); glTranslatef(0.0, -TAIL_LENGTH * 1.5, 0.0); glRotatef(angle[3], 0.0, 1.0, 0.0); glScalef(0.05, TAIL_LENGTH, 0.05); glutWireCube(1.0); glPopMatrix(); }
void drawLEG() { drawTaid();
glRotatef(angle[0], 0.0, 1.0, 0.0);
drawThigh();
glTranslatef(0.0, (BASE_HEIGHT * -1.0), 0.0);
glRotatef(180.0, 1.0, 0.0, 0.0);
glRotatef(angle[1], 0.0, 0.0, 11.0);
drawLowerArm();
// Add glutWireCube between lower and upper arm
glTranslatef(0.0, LOWER_ARM_LENGTH * 1.6, 0.0);
glutWireCube(1.0); // Adjust the size of the cube as needed
glTranslatef(0.0, LOWER_ARM_LENGTH, 2.0);
glRotatef(angle[2], 0.0, 0.0, 1.0);
drawUpperArm();
// Add the tail to the robot
glTranslatef(0.0, UPPER_ARM_LENGTH * 0.2, 0.0);
}
void rotate() { // Check and reverse the direction for the lower arm rotation if (angle[1] >= 45.0 || angle[1] <= -45.0) { lowerArmDirection *= -1; } angle[1] = 1.0 * lowerArmDirection;
// Check and reverse the direction for the upper arm rotation
if (angle[2] >= 45.0 || angle[2] <= -45.0) {
upperArmDirection *= -1;
}
angle[2] = 1.0 * upperArmDirection;
if (angle[3] >= 45.0 || angle[3] <= -45.0) {
upperAssDirection *= -1;
}
angle[3] = 1.0 * upperAssDirection;
// Ensure angles are within the range [0, 360)
for (int i = 1; i <= 3; i) {
if (angle[i] >= 360.0) {
angle[i] -= 360.0;
}
}
glutPostRedisplay();
}
void display() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glMatrixMode(GL_MODELVIEW); glLoadIdentity();
// Set up the stationary light source
GLfloat lightPosition[] = { 2.0, 3.0, 2.0, 1.0 };
glLightfv(GL_LIGHT0, GL_POSITION, lightPosition);
gluLookAt(0.0, 3.0, 5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
drawLEG();
glutSwapBuffers();
}
void init() { glClearColor(0.0, 0.0, 0.0, 0.0); glEnable(GL_DEPTH_TEST); glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); glColor3f(1.0, 1.0, 1.0); glMatrixMode(GL_PROJECTION); glLoadIdentity();
// Specify the aspect ratio based on the window dimensions
int windowWidth = 500; // Adjust to your window size
int windowHeight = 500; // Adjust to your window size
gluPerspective(45.0, static_cast<double>(windowWidth) / windowHeight, 1.0, 10.0);
}
int main(int argc, char** argv) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH); glutInitWindowSize(500, 500); glutInitWindowPosition(0, 0); glutCreateWindow("Dog"); glutDisplayFunc(display); init(); glutIdleFunc(rotate); // Set the idle function for continuous rotation glutMainLoop(); return 0; }
Subreddit
Post Details
- Posted
- 11 months ago
- Reddit URL
- View post on reddit.com
- External URL
- reddit.com/r/GraphicsPro...