// // Box.m // Box-1 // #import "Box.h" @implementation Box - (void)init:(GLfloat)x y:(GLfloat)y z:(GLfloat)z { px = x; py = y; pz = z; // coordenadas spriteVertices[0]=-1.0f; spriteVertices[1]= -1.0f;spriteVertices[2]= -1.0f; spriteVertices[3]= 1.0f; spriteVertices[4]= -1.0f; spriteVertices[5]=-1.0f; spriteVertices[6]=-1.0f; spriteVertices[7]= -1.0f; spriteVertices[8]= 1.0f; spriteVertices[9]= 1.0f; spriteVertices[10]=-1.0f;spriteVertices[11]= 1.0f; // texturas spriteTexcoords[0] = 0.0f; spriteTexcoords[1] = 0.0f; spriteTexcoords[2] = 1.0f; spriteTexcoords[3] = 0.0f; spriteTexcoords[4] = 0.0f; spriteTexcoords[5] = 1.0f; spriteTexcoords[6] = 1.0f; spriteTexcoords[7] = 1.0f; // normales spriteNormals[0] = 0.0f; spriteNormals[1] = 1.0f; spriteNormals[2] = 0.0; spriteNormals[3] = 0.0f; spriteNormals[4] = 1.0f; spriteNormals[5] = 0.0; spriteNormals[6] = 0.0f; spriteNormals[7] = 1.0f; spriteNormals[8] = 0.0; spriteNormals[9] = 0.0f; spriteNormals[10] = 1.0f; spriteNormals[11] = 0.0; } - (void)Render { glPushMatrix(); glColor4f(1.0f, 1.0f, 1.0f, 1.0f); GLfloat sep = 2.50f; glTranslatef(px * sep, py * sep, pz * sep); [self drawPlane:3 ry:0 rz:0]; [self drawPlane:3 ry:1 rz:0]; [self drawPlane:3 ry:2 rz:0]; [self drawPlane:3 ry:3 rz:0]; [self drawPlane:0 ry:0 rz:0]; [self drawPlane:2 ry:0 rz:0]; glPopMatrix(); } - (void)drawPlane:(int)rx ry:(int)ry rz:(int)rz { glPushMatrix(); glRotatef(90 * rz, 0, 0, 1); glRotatef(90 * ry, 0, 1, 0); glRotatef(90 * rx, 1, 0, 0); glEnableClientState(GL_VERTEX_ARRAY); glVertexPointer(3, GL_FLOAT, 0, spriteVertices); glEnableClientState(GL_TEXTURE_COORD_ARRAY); glTexCoordPointer(2, GL_FLOAT, 0, spriteTexcoords); glEnableClientState( GL_NORMAL_ARRAY ); glNormalPointer ( GL_FLOAT, 0, spriteNormals ); glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); glPopMatrix(); } @end