Pregunta

Tengo un problema con insertar múltiples objeto. Cargo objeto pero todos están en un solo lugar,

for( int i = 0; i <= 5; i++ )
{        
  glCallList( OBJECT_LIST[ i ] );
}

glFlush();
glutSwapBuffers();

} // unopened paren 

void Reshape( int width, int height ) {
  glViewport( 0, 0, width, height );
  glMatrixMode( GL_PROJECTION );

  glLoadIdentity();
  for( int i = 0; i <= 5; i++ )  {      
    if( !load_obj( argv[ i ], OBJECT_LIST[ i ] ) )
    {
      printf( "error load file %s", argv[ i ] );
    }
  } 
}
¿Fue útil?

Solución

Debe especificar la matriz de objeto directamente (como si cargar objetos de un archivo 3DS) como este:

glMatrixMode(GL_MODELVIEW); // we are going to manipulate object matrix
for(int i = 0; i <= 5; i++) {
    glPushMatrix(); // save the current modelview (assume camera matrix is there)
    glMultMatrixf(pointer_to_object_matrix(i)); // apply object matrix
    glCallList( OBJECT_LIST[i]);
    glPopMatrix(); // restore modelview
}

Mirando esto, también tenga en cuenta que no puede almacenar operaciones de matriz en listas de visualización (es decir, si su función load_obj () está configurando matrices de todos modos, no funcionará porque estas operaciones no están "registradas").

La otra opción es usar un esquema simple de posicionamiento de objetos, como este:

glMatrixMode(GL_MODELVIEW); // we are going to manipulate object matrix
for(int i = 0; i <= 5; i++) {
    glPushMatrix(); // save the current modelview (assume camera matrix is there)

    glTranslatef(object_x(i), object_y(i), object_z(i)); // change object position

    glRotatef(object_yaw(i), 0, 1, 0);
    glRotatef(object_pitch(i), 1, 0, 0);
    glRotatef(object_roll(i), 0, 0, 1); // change object rotations

    glCallList( OBJECT_LIST[i]);
    glPopMatrix(); // restore modelview
}

De cualquier manera, debe escribir algunas funciones adicionales (pointer_to_object_matrix u object_ [x, y, z, bostezo, tono y rollo]). Si solo está buscando mostrar algunos objetos, intente esto:

glMatrixMode(GL_MODELVIEW); // we are going to manipulate object matrix
for(int i = 0; i <= 5; i++) {
    glPushMatrix(); // save the current modelview (assume camera matrix is there)

    const float obj_step = 50; // spacing between the objects
    glTranslatef((i - 2.5f) * obj_step, 0, 0); // change object position

    glCallList( OBJECT_LIST[i]);
    glPopMatrix(); // restore modelview
}

Espero eso ayude ...

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top