• Lunes 29 de Abril de 2024, 07:20

Autor Tema:  Ayuda Con Este Codigo En Opengl  (Leído 4488 veces)

cholisimo

  • Nuevo Miembro
  • *
  • Mensajes: 3
    • Ver Perfil
Ayuda Con Este Codigo En Opengl
« en: Lunes 20 de Febrero de 2006, 05:06 »
0
Hola a todos mi problema esque no se casi nada de opengl y me han mandado este pedazo trabajo  :( . El trabajo consiste en realizar un programa que simule un sistema solar con el sol, la luna y la tierra. Ademas que realicen el movimiento de rotacion y de traslacion. El codigo bueno he podido hacer algo en Blooshed Dev-C++ que es este codigo:

#include <windows.h>
#include <conio.h>
#include <gl\gl.h>
#include <gl\glaux.h>
#include <gl\glu.h>
void myinit(void);
void drawPlane(void);

void CALLBACK dayAdd (void);
void CALLBACK daySubtract (void);
void CALLBACK yearAdd (void);
void CALLBACK yearSubtract (void);
void CALLBACK display(void);
void CALLBACK myReshape(GLsizei w, GLsizei h);
static int day =0, year = 0;

void CALLBACK dayAdd (void)
{
day = (day + 1) % 360;
}
void CALLBACK daySubtract (void)
{
day = (day - 1) % 360;
}

void CALLBACK yearAdd (void)
{
year = (year + 5) % 360;

}
void CALLBACK yearSubtract (void)
{
year = (year - 5) % 360;

}
void CALLBACK display(void)
{
     // Borramos la pantalla antes de dibujar
glClear(GL_COLOR_BUFFER_BIT);
//Datos del Sol
glPushMatrix();
glColor3f (1.0, 1.0, 0.0);// ponemos el color del sol
glPushMatrix();
auxSolidSphere (1.0); //dibujamos el Sol
glPopMatrix();
//Datos del planeta
glRotatef ((GLfloat) year, 0.0, 1.0, 0.0);//Translacion del planeta sobre el sol
glTranslatef (0, 0.0, 2.5f); // lo situamos en la pantalla
glRotatef ((GLfloat) day, 1.0, 0.0, 1.0); // rotamos la tierra sobre si misma
glColor3f (0.0, 0.0, 1.0); //le damos el color al planeta
auxWireSphere (0.2); //dibujamos un planeta de mallas
glPopMatrix();
glPushMatrix(); //fijamos la matriz
//Datos de la luna
glRotatef ((GLfloat) year, 0.0, 1.0, 0.0); // translacion sobre el planeta
glTranslatef (0, 0.0, 3.0f);//la situamos en pantalla
glRotatef ((GLfloat) day, 0.0f, 0.5, 3.0f); //rota sobre si misma
glColor3f (1.0, 0.0, 0.0);
auxWireSphere (0.1);
glPopMatrix();
glFlush();
glPushMatrix();

//fIN LUNA
glFlush();
}
void myinit (void) {
glShadeModel (GL_FLAT);
}
void CALLBACK myReshape(GLsizei w, GLsizei h)
{
h = (h == 0) ? 1 : h;
glViewport(0, 0, w, h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(90.0, (GLfloat) w/(GLfloat) h, 1.0, 20.0);
glMatrixMode(GL_MODELVIEW);//iniciamos la pila en la que metemos los objetos
glLoadIdentity();
glTranslatef (0.0, 0.0, -5.0);
}
/* Programa principal.
* Abre la ventana con el tamaño inicial, una barra de titulo,
* modo de pantalla RGBA, y maneja los eventos de entrada.
*/
int main(int argc, char** argv)
{
auxInitDisplayMode (AUX_SINGLE | AUX_RGB);
auxInitPosition (0, 0, 500, 500);
auxInitWindow ("Composición de transformaciones de modelado");
myinit ();
auxKeyFunc (AUX_LEFT, yearSubtract);
auxKeyFunc (AUX_RIGHT, yearAdd);
auxKeyFunc (AUX_UP, dayAdd);
auxKeyFunc (AUX_DOWN, daySubtract);
auxReshapeFunc (myReshape);
auxMainLoop(display); //llamada para dibujar
return(0);
}

En el codigo lo que conseguido es dibujar los platenas (sol, luna y la tierra) y que utilizando el teclado el sol y la luna roten sobre si mismos y giren alrededor del sol.Pero de la luna no consigo que gire alrededor del planeta y me toy desesperando ¿algien me puede ayudar y poner el codigo como seria?.Me haria un gran favor :comp:

Ruben3d

  • Moderador
  • ******
  • Mensajes: 710
  • Nacionalidad: es
    • Ver Perfil
    • Web personal
Re: Ayuda Con Este Codigo En Opengl
« Respuesta #1 en: Jueves 23 de Febrero de 2006, 00:23 »
0
Hola.

Intuitivamente diría que no restaurando la matriz entre el dibujado del planeta y de la luna debería solucionar el problema, es decir, eliminando estas dos líneas:
Código: Text
  1. glPopMatrix();
  2. glPushMatrix(); //fijamos la matriz
  3.  

Un saludo,

Ruben3d