elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Sigue las noticias más importantes de seguridad informática en el Twitter! de elhacker.NET


+  Foro de elhacker.net
|-+  Programación
| |-+  Programación C/C++ (Moderadores: Eternal Idol, Littlehorse, K-YreX)
| | |-+  Ayuda con eventos del mouse!!!
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: Ayuda con eventos del mouse!!!  (Leído 1,721 veces)
delirio

Desconectado Desconectado

Mensajes: 11


Ver Perfil
Ayuda con eventos del mouse!!!
« en: 27 Junio 2011, 11:13 am »

Alguien que me ayude a mejorar mi programa de opengl......quiero mover mi figura con el mouse...no se muy bien manejar estos eventos del mouse...solo hice para que pueda moverlo con el teclado, pero quisiera tambien con el mouse..........
Ahi va mi codigo que he hecho:


Código
  1. #include <GL/freeglut.h>
  2. #include <GL/glu.h>
  3. #include <iostream>
  4.  
  5. int posx=0, posy=0;
  6.  
  7. void resize(int width, int height)
  8. {
  9.    glViewport(0, 0, width, height);
  10.  
  11.    glMatrixMode(GL_PROJECTION);
  12.    glLoadIdentity();
  13.    glOrtho(-50,50,-50,50,-10,10);
  14.    glMatrixMode(GL_MODELVIEW);
  15.    glLoadIdentity();
  16.  
  17.    glEnable(GL_DEPTH_TEST);
  18.    glDepthFunc(GL_LEQUAL);
  19. }
  20.  
  21.  
  22. //---------------------------------------------------------//
  23. void display()
  24. {
  25.    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  26. glLoadIdentity();
  27. glBegin(GL_LINES);
  28. glColor3f(1.0f,1.0f,1.0f);
  29. glVertex3f( -50.0f, 0.0f,0.0f);
  30. glVertex3f(50.0f, 0.0f,0.0f);
  31. glColor3f(1.0f,1.0f,1.0f);
  32. glVertex3f( 0.0f, -50.0f,0.0f);
  33. glVertex3f(0.0f, 50.0f,0.0f);
  34. glEnd();
  35.  
  36. //----------------1º  TRIANGULO----------------//  
  37.  glPushMatrix();
  38. glTranslatef(posx, posy, 0);
  39.    glColor3f(1,0,0);
  40. glutSolidSphere(5, 20, 2);
  41.  glEnd();
  42.  glPopMatrix();
  43.  
  44.    glutSwapBuffers();
  45. }
  46. //---------------------------------------------------//
  47.  
  48. void key(unsigned char key, int x, int y)
  49. {
  50.    switch (key)
  51.    {
  52.        case 27 :
  53.            exit(0);
  54.            break;
  55.        default:
  56.            break;
  57.    }
  58.  
  59.    glutPostRedisplay();
  60. }
  61.  
  62.  
  63. void tecladoEspecial(int tecla, int x, int y) {
  64. switch(tecla) {
  65.   case GLUT_KEY_UP : posy++;break;
  66.   case GLUT_KEY_DOWN : posy--;break;
  67.   case GLUT_KEY_RIGHT : posx++;break;
  68.   case GLUT_KEY_LEFT : posx--;break;
  69. }
  70. glutPostRedisplay();
  71. }
  72.  
  73.  
  74.  
  75. void idle()
  76. {
  77.    glutPostRedisplay();
  78. }
  79.  
  80. int main(int argc, char *argv[])
  81. {
  82.    glutInit(&argc, argv);
  83.    glutInitWindowSize(640,480);
  84.    glutInitWindowPosition(10,10);
  85.    glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
  86.    glutCreateWindow("Transformacion 1");
  87.    glutReshapeFunc(resize);
  88.    glutDisplayFunc(display);
  89.    glutKeyboardFunc(key);
  90.    glutSpecialFunc(tecladoEspecial);
  91.  
  92.    glutIdleFunc(idle);
  93.  
  94.    glutMainLoop();
  95. return 0;
  96. }

Gracias de antemano....


En línea

Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
Controlar eventos del mouse « 1 2 3 4 »
Java
danielo- 39 25,745 Último mensaje 16 Junio 2018, 03:35 am
por 0xFer
ayuda con microparones del mouse
Hardware
CrÄsH 4 2,335 Último mensaje 26 Junio 2010, 19:22 pm
por Aprendiz-Oscuro
Ayuda con Eventos y libreria Swing
Java
DarkSorcerer 3 2,916 Último mensaje 5 Febrero 2013, 20:52 pm
por DarkSorcerer
Ayuda con Adsense y eventos onclick
Desarrollo Web
mascalapiz 2 1,957 Último mensaje 27 Julio 2015, 18:21 pm
por mascalapiz
Ayuda con eventos del teclado
Java
sebast345 3 2,364 Último mensaje 18 Noviembre 2016, 13:22 pm
por Orubatosu
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines