//! Sample graphical objects /*! * Sample graphical objects (wireframe and solid cubes) * * NOTE: wireframe cube is only supported on the PC */ /* * Copyright (C) 2006-2010 Alejandro Valenzuela Roca, * Hugo Mendieta Pacheco * * http://lj9.mexinetica.com/ * * This file is part of MotorJ, a free framework for videogame development. * * * * MotorJ is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * MotorJ is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with MotorJ. If not, see . */ #include "objects.h" #ifdef NINTENDO_WII #include "wii_only/gl2gxtrans.h" #endif #ifndef NINTENDO_DS // FIXME: NO GL_LINE_STRIP on Nintendo DS // Should be substituted with GL_LINES or something? void mjWireCube(void) { int r; static vector3 vertices[8]; for (r = 0; r < 4; r++) vertices[r].y = 0.5; for (r = 4; r < 8; r++) vertices[r].y = -0.5; vertices[0].x = vertices[3].x = vertices[4].x = vertices[7].x = -0.5; vertices[1].x = vertices[2].x = vertices[5].x = vertices[6].x = 0.5; vertices[0].z = vertices[1].z = vertices[4].z = vertices[5].z = -0.5; vertices[2].z = vertices[3].z = vertices[6].z = vertices[7].z = 0.5; glBegin(GL_LINE_STRIP); /* Tapa superior */ for (r = 0; r < 4; r++){ glVertex3f(vertices[3-r].x, vertices[3-r].y, vertices[3-r].z); } glVertex3f(vertices[3].x, vertices[3].y, vertices[3].z); glVertex3f(vertices[7].x, vertices[7].y, vertices[7].z); /* Tapa inferior */ for (r = 4; r < 8; r++){ glVertex3f(vertices[r].x, vertices[r].y, vertices[r].z); } glEnd(); for (r=0; r<3; r++){ glBegin(GL_LINES); glVertex3f(vertices[r].x, vertices[r].y, vertices[r].z); glVertex3f(vertices[r+4].x, vertices[r+4].y, vertices[r+4].z); glEnd(); } } void mjSolidTxCube(GLuint* textures) { vector3 vertices[8]; vector2 txcoords[4]; txcoords[0].u = 0; txcoords[0].v = 0; txcoords[1].u = 0; txcoords[1].v = 1; txcoords[2].u = 1; txcoords[2].v = 1; txcoords[3].u = 1; txcoords[3].v = 0; int r; for (r = 0; r < 4; r++) vertices[r].y = 0.5; for (r = 4; r < 8; r++) vertices[r].y = -0.5; vertices[0].x = vertices[3].x = vertices[4].x = vertices[7].x = -0.5; vertices[1].x = vertices[2].x = vertices[5].x = vertices[6].x = 0.5; vertices[0].z = vertices[1].z = vertices[4].z = vertices[5].z = -0.5; vertices[2].z = vertices[3].z = vertices[6].z = vertices[7].z = 0.5; glBindTexture(GL_TEXTURE_2D, textures[0]); /* Top cube cap */ glBegin(GL_QUADS); // FIXME: What's wrong with using glNormal3f in Nintendo DS? glNormal3f(0,1,0); for (r = 0; r < 4; r++){ glTexCoord2fv((GLfloat*)&txcoords[r]); glVertex3fv((GLfloat*) &vertices[3-r]); } glEnd(); glBindTexture(GL_TEXTURE_2D, textures[1]); glBegin(GL_QUADS); /* Bottom cube cap */ glNormal3f(0,-1,0); for (r = 4; r < 8; r++){ glTexCoord2fv((GLfloat*)&txcoords[r-4]); glVertex3fv((GLfloat*)&vertices[r]); } glEnd(); glBindTexture(GL_TEXTURE_2D, textures[2]); glBegin(GL_QUADS); /* Left side */ // FIXME: What's wrong with using glNormal3f in Nintendo DS? glNormal3f(-1,0,0); glTexCoord2fv((GLfloat*)&txcoords[0]); glVertex3fv((GLfloat*)&vertices[0]); glTexCoord2fv((GLfloat*)&txcoords[1]); glVertex3fv((GLfloat*)&vertices[4]); glTexCoord2fv((GLfloat*)&txcoords[2]); glVertex3fv((GLfloat*)&vertices[7]); glTexCoord2fv((GLfloat*)&txcoords[3]); glVertex3fv((GLfloat*)&vertices[3]); glEnd(); glBindTexture(GL_TEXTURE_2D, textures[3]); glBegin(GL_QUADS); /* Right side */ // FIXME: What's wrong with using glNormal3f in Nintendo DS? glNormal3f(1,0,0); glTexCoord2fv((GLfloat*)&txcoords[0]); glVertex3fv((GLfloat*)&vertices[2]); glTexCoord2fv((GLfloat*)&txcoords[1]); glVertex3fv((GLfloat*)&vertices[6]); glTexCoord2fv((GLfloat*)&txcoords[2]); glVertex3fv((GLfloat*)&vertices[5]); glTexCoord2fv((GLfloat*)&txcoords[3]); glVertex3fv((GLfloat*)&vertices[1]); glEnd(); glBindTexture(GL_TEXTURE_2D, textures[4]); glBegin(GL_QUADS); /* front */ // FIXME: What's wrong with using glNormal3f in Nintendo DS? glNormal3f(0,0,1); glTexCoord2fv((GLfloat*)&txcoords[0]); glVertex3fv((GLfloat*)&vertices[3]); glTexCoord2fv((GLfloat*)&txcoords[1]); glVertex3fv((GLfloat*)&vertices[7]); glTexCoord2fv((GLfloat*)&txcoords[2]); glVertex3fv((GLfloat*)&vertices[6]); glTexCoord2fv((GLfloat*)&txcoords[3]); glVertex3fv((GLfloat*)&vertices[2]); glEnd(); glBindTexture(GL_TEXTURE_2D, textures[5]); glBegin(GL_QUADS); /* Rear */ // FIXME: What's wrong with using glNormal3f in Nintendo DS? glNormal3f(0,0,-1); glTexCoord2fv((GLfloat*)&txcoords[0]); glVertex3fv((GLfloat*)&vertices[1]); glTexCoord2fv((GLfloat*)&txcoords[1]); glVertex3fv((GLfloat*)&vertices[5]); glTexCoord2fv((GLfloat*)&txcoords[2]); glVertex3fv((GLfloat*)&vertices[4]); glTexCoord2fv((GLfloat*)&txcoords[3]); glVertex3fv((GLfloat*)&vertices[0]); glEnd(); glEnd(); } void mjSolidCube() { vector3 vertices[8]; int r; for (r = 0; r < 4; r++) vertices[r].y = 0.5; for (r = 4; r < 8; r++) vertices[r].y = -0.5; vertices[0].x = vertices[3].x = vertices[4].x = vertices[7].x = -0.5; vertices[1].x = vertices[2].x = vertices[5].x = vertices[6].x = 0.5; vertices[0].z = vertices[1].z = vertices[4].z = vertices[5].z = -0.5; vertices[2].z = vertices[3].z = vertices[6].z = vertices[7].z = 0.5; // An extra instruction must be used for the Wii version to function: #ifdef NINTENDO_WII mjWiiGLSetVs(24); #endif /* Top cube cap */ glBegin(GL_QUADS); #ifdef PC_SDL // FIXME: What's wrong with using glNormal3f in Nintendo DS? glNormal3f(0,1,0); #endif for (r = 0; r < 4; r++){ glVertex3f(vertices[3-r].x, vertices[3-r].y, vertices[3-r].z); } /* Bottom cube cap */ #ifdef PC_SDL glNormal3f(0,-1,0); #endif for (r = 4; r < 8; r++){ glVertex3f(vertices[r].x, vertices[r].y, vertices[r].z); } /* Left side */ #ifdef PC_SDL // FIXME: What's wrong with using glNormal3f in Nintendo DS? glNormal3f(-1,0,0); #endif glVertex3f(vertices[0].x, vertices[0].y, vertices[0].z); glVertex3f(vertices[4].x, vertices[4].y, vertices[4].z); glVertex3f(vertices[7].x, vertices[7].y, vertices[7].z); glVertex3f(vertices[3].x, vertices[3].y, vertices[3].z); /* Right side */ #ifdef PC_SDL // FIXME: What's wrong with using glNormal3f in Nintendo DS? glNormal3f(1,0,0); #endif glVertex3f(vertices[2].x, vertices[2].y, vertices[2].z); glVertex3f(vertices[6].x, vertices[6].y, vertices[6].z); glVertex3f(vertices[5].x, vertices[5].y, vertices[5].z); glVertex3f(vertices[1].x, vertices[1].y, vertices[1].z); /* front */ #ifdef PC_SDL // FIXME: What's wrong with using glNormal3f in Nintendo DS? glNormal3f(0,0,1); #endif glVertex3f(vertices[3].x, vertices[3].y, vertices[3].z); glVertex3f(vertices[7].x, vertices[7].y, vertices[7].z); glVertex3f(vertices[6].x, vertices[6].y, vertices[6].z); glVertex3f(vertices[2].x, vertices[2].y, vertices[2].z); /* Rear */ #ifdef PC_SDL // FIXME: What's wrong with using glNormal3f in Nintendo DS? glNormal3f(0,0,-1); #endif glVertex3f(vertices[1].x, vertices[1].y, vertices[1].z); glVertex3f(vertices[5].x, vertices[5].y, vertices[5].z); glVertex3f(vertices[4].x, vertices[4].y, vertices[4].z); glVertex3f(vertices[0].x, vertices[0].y, vertices[0].z); glEnd(); } void mjPlane(float n_u, float n_v) { glBegin(GL_QUADS); glNormal3f(0,1,0); #ifdef PC_SDL glTexCoord2f(0,0); #endif glVertex3f(-0.5, 0, -0.5); #ifdef PC_SDL glTexCoord2f(0,n_v); #endif glVertex3f(-0.5, 0, 0.5); #ifdef PC_SDL glTexCoord2f(n_u,n_v); #endif glVertex3f(0.5, 0, 0.5); #ifdef PC_SDL glTexCoord2f(n_u,0); #endif glVertex3f(0.5, 0, -0.5); glEnd(); } #else void mjSolidCube(void) { static u32 DLCube[] = { 83, FIFO_COMMAND_PACK(FIFO_BEGIN, FIFO_VERTEX16, FIFO_VERTEX16, FIFO_VERTEX16), GL_TRIANGLE, ///// CARA FRONTAL 13 //NORMAL_PACK(0,0,floattov10(1)), VERTEX_PACK(floattov16(-0.5),floattov16(-0.5)), VERTEX_PACK(floattov16(0.5),0), VERTEX_PACK(floattov16(0.5),floattov16(-0.5)), VERTEX_PACK(floattov16(0.5),0), VERTEX_PACK(floattov16(-0.5),floattov16(0.5)), VERTEX_PACK(floattov16(0.5),0), FIFO_COMMAND_PACK(FIFO_VERTEX16, FIFO_VERTEX16, FIFO_VERTEX16, FIFO_VERTEX16), VERTEX_PACK(floattov16(0.5),floattov16(-0.5)), VERTEX_PACK(floattov16(0.5),0), VERTEX_PACK(floattov16(0.5),floattov16(0.5)), VERTEX_PACK(floattov16(0.5),0), VERTEX_PACK(floattov16(-0.5),floattov16(0.5)), VERTEX_PACK(floattov16(0.5),0), ///// CARA POSTERIOR 14 //NORMAL_PACK(0,0,floattov10(-1)), VERTEX_PACK(floattov16(0.5),floattov16(-0.5)), VERTEX_PACK(floattov16(-0.5),0), FIFO_COMMAND_PACK(FIFO_VERTEX16, FIFO_VERTEX16, FIFO_VERTEX16, FIFO_VERTEX16), VERTEX_PACK(floattov16(-0.5),floattov16(-0.5)), VERTEX_PACK(floattov16(-0.5),0), VERTEX_PACK(floattov16(0.5),floattov16(0.5)), VERTEX_PACK(floattov16(-0.5),0), VERTEX_PACK(floattov16(-0.5),floattov16(-0.5)), VERTEX_PACK(floattov16(-0.5),0), VERTEX_PACK(floattov16(-0.5),floattov16(0.5)), VERTEX_PACK(floattov16(-0.5),0), FIFO_COMMAND_PACK(FIFO_VERTEX16, FIFO_VERTEX16, FIFO_VERTEX16, FIFO_VERTEX16), VERTEX_PACK(floattov16(0.5),floattov16(0.5)), VERTEX_PACK(floattov16(-0.5),0), ///// CARA LATERAL DERECHA 13 //NORMAL_PACK(floattov10(1),0,0), VERTEX_PACK(floattov16(0.5),floattov16(0.5)), VERTEX_PACK(floattov16(0.5),0), VERTEX_PACK(floattov16(0.5),floattov16(-0.5)), VERTEX_PACK(floattov16(0.5),0), VERTEX_PACK(floattov16(0.5),floattov16(0.5)), VERTEX_PACK(floattov16(-0.5),0), FIFO_COMMAND_PACK(FIFO_VERTEX16, FIFO_VERTEX16, FIFO_VERTEX16, FIFO_VERTEX16), VERTEX_PACK(floattov16(0.5),floattov16(-0.5)), VERTEX_PACK(floattov16(0.5),0), VERTEX_PACK(floattov16(0.5),floattov16(-0.5)), VERTEX_PACK(floattov16(-0.5),0), VERTEX_PACK(floattov16(0.5),floattov16(0.5)), VERTEX_PACK(floattov16(-0.5),0), ///// CARA LATERAL IZQUIERDA 14 //NORMAL_PACK(floattov10(-1),0,0), VERTEX_PACK(floattov16(-0.5),floattov16(0.5)), VERTEX_PACK(floattov16(-0.5),0), FIFO_COMMAND_PACK(FIFO_VERTEX16, FIFO_VERTEX16, FIFO_VERTEX16, FIFO_VERTEX16), VERTEX_PACK(floattov16(-0.5),floattov16(-0.5)), VERTEX_PACK(floattov16(-0.5),0), VERTEX_PACK(floattov16(-0.5),floattov16(0.5)), VERTEX_PACK(floattov16(0.5),0), VERTEX_PACK(floattov16(-0.5),floattov16(-0.5)), VERTEX_PACK(floattov16(-0.5),0), VERTEX_PACK(floattov16(-0.5),floattov16(-0.5)), VERTEX_PACK(floattov16(0.5),0), FIFO_COMMAND_PACK(FIFO_VERTEX16, FIFO_VERTEX16, FIFO_VERTEX16, FIFO_VERTEX16), VERTEX_PACK(floattov16(-0.5),floattov16(0.5)), VERTEX_PACK(floattov16(0.5),0), ///// CARA SUPERIOR 13 //NORMAL_PACK(0,floattov10(1),0), VERTEX_PACK(floattov16(0.5),floattov16(0.5)), VERTEX_PACK(floattov16(0.5),0), VERTEX_PACK(floattov16(0.5),floattov16(0.5)), VERTEX_PACK(floattov16(-0.5),0), VERTEX_PACK(floattov16(-0.5),floattov16(0.5)), VERTEX_PACK(floattov16(0.5),0), FIFO_COMMAND_PACK(FIFO_VERTEX16, FIFO_VERTEX16, FIFO_VERTEX16, FIFO_VERTEX16), VERTEX_PACK(floattov16(0.5),floattov16(0.5)), VERTEX_PACK(floattov16(-0.5),0), VERTEX_PACK(floattov16(-0.5),floattov16(0.5)), VERTEX_PACK(floattov16(-0.5),0), VERTEX_PACK(floattov16(-0.5),floattov16(0.5)), VERTEX_PACK(floattov16(0.5),0), ///// CARA INFERIOR 14 //NORMAL_PACK(0,floattov10(-1),0), VERTEX_PACK(floattov16(0.5),floattov16(-0.5)), VERTEX_PACK(floattov16(0.5),0), FIFO_COMMAND_PACK(FIFO_VERTEX16, FIFO_VERTEX16, FIFO_VERTEX16, FIFO_VERTEX16), VERTEX_PACK(floattov16(-0.5),floattov16(-0.5)), VERTEX_PACK(floattov16(0.5),0), VERTEX_PACK(floattov16(0.5),floattov16(-0.5)), VERTEX_PACK(floattov16(-0.5),0), VERTEX_PACK(floattov16(-0.5),floattov16(-0.5)), VERTEX_PACK(floattov16(0.5),0), VERTEX_PACK(floattov16(-0.5),floattov16(-0.5)), VERTEX_PACK(floattov16(-0.5),0), FIFO_COMMAND_PACK(FIFO_VERTEX16, FIFO_END, FIFO_NOP, FIFO_NOP), VERTEX_PACK(floattov16(0.5),floattov16(-0.5)), VERTEX_PACK(floattov16(-0.5),0), }; glCallList(DLCube); } #endif