I have written the following code for one assignment at uni, but it is not working as i would like. could you, please, help me?
I would like to give this arm as the maximum possible moviments as a human arm, like it shouldn't move 360, etc
can you help or give any tip, please?!?!
many thanks
It has some words in portuguese coz this is my mother language
ombro means shoulder
antibraco means arm ( between shouder and elbow )
braco means arm ( between elbow and wrist )
dedo means finger
thanks again
#include <windows.h> // Headers para execucao do Projeto
#include <gl/gl.h>
#include <gl/glu.h>
#include <gl/glut.h>
static int ombro = 0, AntiBraco = 0, Braco = 0, dedo1 = 0, dedo2 = 0, dedo3 = 0;
void init(void)
{
glClearColor (1.0, 1.0, 1.0, 1.0); // Cor do Fundo da Janela
glShadeModel (GL_FLAT);
}
void display(void)
{
glClear (GL_COLOR_BUFFER_BIT);
glPushMatrix();
glTranslatef (-0.5, 0.0, 0.0);
glRotatef ((GLfloat) ombro, 0.0, 90.0, 0.0);
glTranslatef (0.5, 0.0, 0.0);
glPushMatrix();
glScalef (1.0, 0.8, 1.0); // Tamanho do ombro
glColor3f(0.0,0.0,0.0); // Cor do Ombro
glutSolidCube (0.5); // Tamanho do Cubo Solido
glPopMatrix();
glTranslatef (0.3, 0.0, 0.0);
glRotatef ((GLfloat) AntiBraco, 0.0, 0.0, 0.1);
glTranslatef (0.7, 0.0, 0.0);
glPushMatrix();
glScalef (3.0, 0.4, 1.0);
glColor3f(0.5,0.5,0.5); // Cor do AntiBraco
glutSolidCube (0.5);
glPopMatrix();
glTranslatef (0.7, 0.0, 0.0);
glRotatef ((GLfloat) Braco, 0.0, 0.0,0.1);
glTranslatef (0.5, 0.0, 0.0);
glPushMatrix();
glScalef (2.0, 0.4, 1.0);
glColor3f(0.8,0.8,0.8); // Cor do Braco
glutSolidCube (0.5);
glPopMatrix();
glPushMatrix();
glTranslatef (0.5, 0.0, 0.25);
glRotatef ((GLfloat) dedo1, 0.0, 0.0, 1.0);
glTranslatef (0.3, 0.0, 0.0);
glPushMatrix();
glScalef (2.0, 0.4, 1.0);
glColor3f(0.0,0.0,0.0);
glutSolidCube (0.25); // Cubo nao Solido
glPopMatrix();
glPopMatrix();
glPushMatrix();
glTranslatef (0.5, 0.0, 0.0);
glRotatef ((GLfloat)dedo2, 0.0, 0.0, 1.0);
glTranslatef (0.3, 0.0, 0.0);
glPushMatrix();
glScalef (2.0, 0.4, 1.0);
glColor3f(0.0,0.0,0.0);
glutSolidCube (0.25);
glPopMatrix();
glPopMatrix();
glPushMatrix();
glTranslatef (0.5, 0.0, -0.25);
glRotatef ((GLfloat) dedo3, 0.0, 0.0, 1.0);
glTranslatef (0.3, 0.0, 0.0);
glPushMatrix();
glScalef (2.0, 0.4, 1.0);
glColor3f(0.0,0.0,0.0);
glutSolidCube (0.25);
glPopMatrix();
glPopMatrix();
glPopMatrix();
glutSwapBuffers();
}
void reshape (int w, int h)
{
glViewport (0, 0, (GLsizei) w, (GLsizei) h);
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
gluPerspective(65.0, (GLfloat) w/(GLfloat) h, 1.0, 20.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef (0.0, 0.0, -5.0);
}
void keyboard (unsigned char key, int x, int y)
{
switch (key) {
case 's': // S s move o ombro
ombro = (ombro + 5) % 360;
glutPostRedisplay();
break;
case 'S':
ombro = (ombro - 5) % 360;
glutPostRedisplay();
break;
case 'e': // E e move o AntiBraco
AntiBraco = (AntiBraco + 5) % 360;
glutPostRedisplay();
break;
case 'E':
AntiBraco = (AntiBraco - 5) % 360;
glutPostRedisplay();
break;
case 'w': // W w move o Braco
Braco = (Braco + 5) % 360; // Velocidade e Angulo do Movimento
glutPostRedisplay();
break;
case 'W':
Braco = (Braco - 5) % 360;
glutPostRedisplay();
break;
case '1': //
dedo1 = (dedo1 - 5) % 90;
glutPostRedisplay();
break;
case '2': //
dedo1 = (dedo1 + 5) % 90;
glutPostRedisplay();
break;
case '3':
dedo2 = (dedo2 - 5) % 90;
glutPostRedisplay();
break;
case '4':
dedo2 = (dedo2 + 5) % 90;
glutPostRedisplay();
break;
case '5':
dedo3 = (dedo3 - 5) % 90;
glutPostRedisplay();
break;
case '6':
dedo3 = (dedo3 + 5) % 90;
glutPostRedisplay();
break;
default:
break;
}
}
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB);
glutInitWindowSize (800, 800);
glutInitWindowPosition (50, 50);
glutCreateWindow (argv[0]);
init ();
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutKeyboardFunc(keyboard);
glutMainLoop();
return 0;
}
Edited by WingedPanther, 12 April 2009 - 05:22 PM.
add code tags (the # button)


Sign In
Create Account

Back to top









