1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
| void myWindow::reconstruction3D(const std::vector<int> & table)
{
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
glMatrixMode( GL_MODELVIEW);
glLoadIdentity( );
glScalef(0.01, 0.01, 0.01);
glTranslatef(0.0f, 0.0f, -6.0f);
int index=0;
for(int z =0 ; z<64 ; z++)
for(int y=0 ; y < 64 ; y++)
for (int x = 0 ; x < 64;x++)
{
index = x+y*64+z*64*64;
glBegin(GL_QUADS);
//front
glColor3ub(table[index],table[index],table[index]);
glVertex3i(x-1, y-1 , z+1);
glVertex3i(x-1, y-1 ,z-1);
glVertex3i( x+1 ,y-1 ,z-1);
glVertex3i( x+1 ,y-1 , z+1);
//right
glColor3ub(table[index],table[index],table[index]);
glVertex3i( x+1, y-1 , z-1);
glVertex3i( x+1, y+1 ,z-1);
glVertex3i( x+1 ,y+1 ,z+1);
glVertex3i( x+1 ,y-1 , z+1);
//behind
glColor3ub(table[index],table[index],table[index]);
glVertex3i( x+1 , y+1 , z-1);
glVertex3i( x-1 , y+1 ,z-1);
glVertex3i( x-1 ,y+1 ,z+1);
glVertex3i( x+1 ,y+1 , z+1);
//left
glColor3ub(table[index],table[index],table[index]);
glVertex3i( x-1 , y+1 , z-1);
glVertex3i( x-1 ,y-1 ,z-1);
glVertex3i( x-1 ,y-1 , z+1);
glVertex3i( x-1 , y+1 ,z+1);
//above
glColor3ub(table[index],table[index],table[index]);
glVertex3i( x-1 , y-1 , z+1);
glVertex3i( x+1 , y-1 ,z+1);
glVertex3i( x+1 ,y+1 ,z+1);
glVertex3i( x-1 ,y+1 , z+1);
//below
glColor3ub(table[index],table[index],table[index]);
glVertex3i( x-1 , y-1 , z-1);
glVertex3i( x-1 , y+1 ,z-1);
glVertex3i( x+1 ,y+1 ,z-1);
glVertex3i( x+1 ,y-1 , z-1);
glEnd();
}
} |
Partager