C++ Learning Community Forum
August 01, 2010, 03:03:05 AM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: Hello. Smiley
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: Any Help Please?!?!  (Read 1599 times)
BladeRunner1
N00b!!1
*
Posts: 1


View Profile
« on: April 12, 2009, 11:52:11 PM »

Hey

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
Code:
#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;
}


« Last Edit: April 13, 2009, 11:51:57 AM by C-Man » Logged
oulyt
C++ Freak
***
Posts: 340



View Profile
« Reply #1 on: April 13, 2009, 04:52:50 AM »

you should use the code tag so your code is easier to read.

if you use code tags line of code like glColor3f(0.8,0.8,0.Cool; // Cor do Braco turn to
Code:
glColor3f(0.8,0.8,0.8); // Cor do Braco
« Last Edit: April 13, 2009, 04:55:12 AM by oulyt » Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!