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

Generated on Thu Jul 1 06:08:19 2010 for Second Life Viewer by  doxygen 1.4.7