Foros del Web » Programación para mayores de 30 ;) » Programación General »

Problemas Opengl urgente

Estas en el tema de Problemas Opengl urgente en el foro de Programación General en Foros del Web. Hola a todos tengo un grabe problema que no se como fijar una esfera (que haga de luna ,y que no se me mueva la ...
  #1 (permalink)  
Antiguo 19/02/2006, 10:45
 
Fecha de Ingreso: enero-2005
Mensajes: 2
Antigüedad: 19 años, 3 meses
Puntos: 0
Pregunta Problemas Opengl urgente

Hola a todos tengo un grabe problema que no se como fijar una esfera (que haga de luna ,y que no se me mueva la pantalla de ejecucion) en el siguiente programa:

#include <windows.h>
#include <conio.h>
#include <gl\gl.h>
#include <gl\glu.h>
#include <gl\glaux.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 year = 0, day = 0;
void CALLBACK dayAdd (void)
{
day = (day + 10) % 360;
}
void CALLBACK daySubtract (void)
{
day = (day - 10) % 360;
}
void CALLBACK yearAdd (void)
{
year = (year + 5) % 360;
}
void CALLBACK yearSubtract (void)
{
year = (year - 5) % 360;
}
void CALLBACK display(void)
{
glClear(GL_COLOR_BUFFER_BIT
glColor3f (1.0, 1.0, 1.0);
glPushMatrix();
/* Dibuja el sol */
glPushMatrix();
glRotatef (90.0, 1.0, 0.0, 0.0); /* rotate it upright */
glColor3f (1.0, 1.0, 0.0);
auxSolidSphere (1.0);
glPopMatrix();
/* Situa el planeta */
glRotatef ((GLfloat) year, 0.0, 1.0, 0.0);
glTranslatef (2.5, 0.0, 0.0);
glRotatef ((GLfloat) day, 0.0, 1.0, 0.0);
glRotatef (90.0, 1.0, 0.0, 0.0); /* rotate it upright */
/* Dibuja el planeta */
glColor3f (0.0, 0.0, 1.0);/
auxWireSphere (0.2);
glPopMatrix();
//situa luna//
glTranslatef (3, 0.0, 0.0);
glRotatef (0, 0.0, 1.0, 0.0);
glRotatef (90.0, 1.0, 0.0, 0.0);
/* Dibuja la luna */
glColor3f (1.0, 1.0, 1.0);
auxSolidSphere (0.1);
glPopMatrix();
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);
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); //tamaño de la ventana
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);
return(0);
}
  #2 (permalink)  
Antiguo 19/02/2006, 13:25
 
Fecha de Ingreso: noviembre-2003
Ubicación: Mexico
Mensajes: 1.081
Antigüedad: 20 años, 5 meses
Puntos: 7
no entiendo tu pregunta.
a que te refieres con "fijar una esfera"?
y a que te refieres con que: "no se me mueva la pantalla de ejecucion"¿

Siguiendo la logica de programa, te hace falta un guardar la matriz para cuando dibujas la luna (hacer el glPushMatrix(), ya que solo tienes el pop).
Recuerda que en OpenGL todo son matrices, si no guardas un estado y haces alguna traslacion, rotacion o escalamiento afecta a todas las matrices que no han sido guardadas. Pero no se si ese sea tu problema aqui ya que no entiendo cual es tu duda.....

saludos,
  #3 (permalink)  
Antiguo 19/02/2006, 21:38
 
Fecha de Ingreso: enero-2005
Mensajes: 2
Antigüedad: 19 años, 3 meses
Puntos: 0
Si lo que me refero de movimientos esque en mi practica tengo que simular un sistema solar ( con el sol, la luna y la tierra). Luego tengo que mostrar sus movimientos de translacion y rotacion tanto de la tierra como de la luna.
Utilizo el Bloodshev Dev-C++ y bueno mi codigo mejor explicado es este:


#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 este codigo solo hago que se transladen ambos (tierra y la luna) alrededor del sol y que giren sobre si mismos. Pero yo lo que quiero esq la luna gire alrededor de la tierra.
  #4 (permalink)  
Antiguo 20/02/2006, 20:10
 
Fecha de Ingreso: noviembre-2003
Ubicación: Mexico
Mensajes: 1.081
Antigüedad: 20 años, 5 meses
Puntos: 7
ah ok, ya entendi. Lo que pasa es que tendrias que crear una variable mas para la rotacion de la luna sobre la tierra.
Podrias hacer algo asi para la rotacion de la luna alrededor de la tierra:

Código PHP:
        static float fMoonRot 0.0f;
    static 
float fEarthRot 0.0f;    
    
glPushMatrix();
    
glRotatef(fEarthRot0.0f1.0f0.0f);

    
// La tierra
    
glColor3ub(0,0,255);
    
glTranslatef(105.0f,0.0f,0.0f);
    
glutSolidSphere(15.0f3017);


    
// Rotar a la luna con respecto a la tierra
    
glColor3ub(200,200,200);
    
glRotatef(fMoonRot,0.0f1.0f0.0f);
    
glTranslatef(30.0f0.0f0.0f);
    
fMoonRot+= 15.0f;
    if(
fMoonRot 360.0f)
        
fMoonRot 0.0f;

    
glutSolidSphere(6.0f3017);
        
glPopMatrix(); 
No cheque si el codigo funciona a la perfeccion, ya que ni lo probe, pero ahi esta la idea.......
Si ya tienes de la tierra sobre el sol, la de la luna es el mismo principio.....
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 04:17.