i'm trying to show a 3D matrix made up of 7600700 points and i want to obtain a parallelepiped that is black on the surface and red inside. I have the parallelepiped and it's black on the surface and red inside and i use three different windows to show three different plans which section the parallelepiped and pressing a key it is possible to move along a direction (in one window along the x, in another along the y and in the third along the z) watching one section at a time. Moving along z and x doesn't give me any problem, i can see the sectioning plans correctly, but when i try to show something in the third window (the one that allows me to move along the y coordinate sectioning the parallelepiped with the xz plan) i get different things. If i write
gluLookAt (85.0f, 340.0f, 131.5f, 85.0f, 85.0f, 131.5f, 0.0f, -1.0f, 0.0f)
i only get a single point, but if i write
gluLookAt (340.0f, 85.0f, 131.5f, 85.0f, 85.0f, 131.5f, 0.0f, -1.0f, 0.0f)
or
gluLookAt (85.0f, 85.0f, 526.0f, 85.0f, 85.0f, 131.5f, 0.0f, -1.0f, 0.0f)
i get a plan. My parallelepiped is made up of 170 values for the x, 170 values for the y and 263 values for the z so i usually set the three parameters of gluLookAt in this way: i double the coordinate along which i will move and i halve the other two coordinates. Here's a piece of my code:
void fill_array_3() {
g_vertex_buffer_data_3=new GLfloat[3*p_mat_size_tot];
int i=0;
int k=0;
for(int y=0;y<170;y++) {
for(int z=0;z<263;z++) {
for(int x=0;x<170;x++) {
g_vertex_buffer_data_3[i]=(GLfloat)x+0.5f;
g_vertex_buffer_data_3[i+1]=(GLfloat)y+0.5f;
g_vertex_buffer_data_3[i+2]=(GLfloat)z+0.5f;
i+=3;
}
}
}
void display_3(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
gluLookAt (85.0f, 340.0f, 131.5f, 85.0f, 85.0f, 131.5f, 0.0f, -1.0f, 0.0f);
glPushMatrix();
glRotatef(step15, 1.0f, 0.0f, 0.0f);
glRotatef(step16, 0.0f, 1.0f, 0.0f);
glScalef(step17, step17, step17);
glTranslatef(0.0f, 0.0f, step18);
glTranslatef(step19, 0.0f, 0.0f);
glTranslatef(0.0f, step20, 0.0f);
glMatrixMode(GL_MODELVIEW);
glEnableClientState( GL_VERTEX_ARRAY );
glEnableClientState( GL_COLOR_ARRAY );
glVertexPointer( 3, GL_FLOAT, sizeof(Point), &points3[0].x );
glColorPointer( 3, GL_FLOAT, sizeof(Point), &points3[0].r );
glPointSize( 3.0 );
glDrawArrays( GL_POINTS, step21*170*263, 170*263);
glDisableClientState( GL_VERTEX_ARRAY );
glDisableClientState( GL_COLOR_ARRAY );
glFlush();
glPopMatrix();
glutSwapBuffers();
}
void reshape_3(int w, int h)
{
glViewport(0, 0, (GLsizei)w, (GLsizei)h);
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
glFrustum (-1.0f, 1.0f, -1.0f, 1.0f, 1.0f, 5000.0f);
glMatrixMode (GL_MODELVIEW);
}
int main(int argc, char** argv)
{
[...]
fill_array_1();
fill_array_2();
fill_array_3();
fill_array();
glutInit(&argc, argv);
glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
glutInitWindowSize(600,600);
glutInitWindowPosition (1100, 100);
window_3 = glutCreateWindow(argv[0]);
glutSetWindowTitle("Vista y");
init();
glutDisplayFunc(display_3);
glutReshapeFunc(reshape_3);
glutKeyboardFunc(keyPressed_3);
glutMainLoop();
return 0;
}
Thank you for your help!!!
With
gluLookAt (85.0f, 340.0f, 131.5f, 85.0f, 85.0f, 131.5f, 0.0f, -1.0f, 0.0f)
your viewing direction is (0, 85-340, 0)
, which is collinear to your up
vector of (0,-1,0)
. gluLookAt
will just fail, because your inputs don't describe a distinct camera orientation.