llbox.cpp

Go to the documentation of this file.
00001 
00032 #include "llviewerprecompiledheaders.h"
00033 
00034 #include "llbox.h"
00035 
00036 #include "llgl.h"
00037 #include "llglimmediate.h"
00038 #include "llglheaders.h"
00039 
00040 LLBox           gBox;
00041 
00042 // These routines support multiple textures on a box
00043 void LLBox::prerender()
00044 {
00045         F32 size = 1.f;
00046 
00047         mTriangleCount = 6 * 2;
00048 
00049         mVertex[0][0] = mVertex[1][0] = mVertex[2][0] = mVertex[3][0] = -size / 2;
00050         mVertex[4][0] = mVertex[5][0] = mVertex[6][0] = mVertex[7][0] =  size / 2;
00051         mVertex[0][1] = mVertex[1][1] = mVertex[4][1] = mVertex[5][1] = -size / 2;
00052         mVertex[2][1] = mVertex[3][1] = mVertex[6][1] = mVertex[7][1] =  size / 2;
00053         mVertex[0][2] = mVertex[3][2] = mVertex[4][2] = mVertex[7][2] = -size / 2;
00054         mVertex[1][2] = mVertex[2][2] = mVertex[5][2] = mVertex[6][2] =  size / 2;
00055 }
00056 
00057 // These routines support multiple textures on a box
00058 void LLBox::cleanupGL()
00059 {
00060         // No GL state, a noop.
00061 }
00062 
00063 void LLBox::renderface(S32 which_face)
00064 {
00065         /*static F32 normals[6][3] =
00066         {
00067                 {-1.0f,  0.0f,  0.0f},
00068                 { 0.0f,  1.0f,  0.0f},
00069                 { 1.0f,  0.0f,  0.0f},
00070                 { 0.0f, -1.0f,  0.0f},
00071                 { 0.0f,  0.0f,  1.0f},
00072                 { 0.0f,  0.0f, -1.0f}
00073                 };*/
00074         static S32 faces[6][4] =
00075         {
00076                 {0, 1, 2, 3},
00077                 {3, 2, 6, 7},
00078                 {7, 6, 5, 4},
00079                 {4, 5, 1, 0},
00080                 {5, 6, 2, 1},
00081                 {7, 4, 0, 3}
00082         };
00083 
00084         gGL.begin(LLVertexBuffer::QUADS);
00085                 //gGL.normal3fv(&normals[which_face][0]);
00086                 gGL.texCoord2f(1,0);
00087                 gGL.vertex3fv(&mVertex[ faces[which_face][0] ][0]);
00088                 gGL.texCoord2f(1,1);
00089                 gGL.vertex3fv(&mVertex[ faces[which_face][1] ][0]);
00090                 gGL.texCoord2f(0,1);
00091                 gGL.vertex3fv(&mVertex[ faces[which_face][2] ][0]);
00092                 gGL.texCoord2f(0,0);
00093                 gGL.vertex3fv(&mVertex[ faces[which_face][3] ][0]);
00094         gGL.end();
00095 }
00096 
00097 void LLBox::render()
00098 {
00099     // This is a flattend representation of the box as render here
00100     //                                       .
00101     //              (-++)        (+++)      /|\t
00102     //                +------------+         | (texture coordinates)
00103     //                |2          1|         |
00104     //                |     4      |        (*) --->s
00105     //                |    TOP     |
00106     //                |            |
00107     // (-++)     (--+)|3          0|(+-+)     (+++)        (-++)
00108     //   +------------+------------+------------+------------+
00109     //   |2          1|2          1|2          1|2          1|
00110     //   |     0      |     1      |     2      |     3      |
00111     //   |   BACK     |   RIGHT    |   FRONT    |   LEFT     |
00112     //   |            |            |            |            |
00113     //   |3          0|3          0|3          0|3          0|
00114     //   +------------+------------+------------+------------+
00115     // (-+-)     (---)|2          1|(+--)     (++-)        (-+-)
00116     //                |     5      |
00117     //                |   BOTTOM   |
00118     //                |            |
00119     //                |3          0|
00120     //                +------------+
00121     //              (-+-)        (++-)
00122 
00123         renderface(5);
00124         renderface(4);
00125         renderface(3);
00126         renderface(2);
00127         renderface(1);
00128         renderface(0);
00129         gGL.flush();
00130 }

Generated on Fri May 16 08:33:15 2008 for SecondLife by  doxygen 1.5.5