llviewerjointshape.cpp

Go to the documentation of this file.
00001 
00032 //-----------------------------------------------------------------------------
00033 // Header Files
00034 //-----------------------------------------------------------------------------
00035 #include "llviewerprecompiledheaders.h"
00036 
00037 #include "llviewerjointshape.h"
00038 
00039 #include "llbox.h"
00040 #include "llsphere.h"
00041 #include "llcylinder.h"
00042 #include "llgldbg.h"
00043 #include "llglheaders.h"
00044 
00045 F32 LLViewerJointShape::sColorScale = 1.0f;
00046 
00047 //-----------------------------------------------------------------------------
00048 // LLViewerJointShape()
00049 //-----------------------------------------------------------------------------
00050 LLViewerJointShape::LLViewerJointShape()
00051 {
00052         mType = ST_NULL;
00053         mColor[0] = 1.0f;
00054         mColor[1] = 1.0f;
00055         mColor[2] = 1.0f;
00056         mColor[3] = 1.0f;
00057         mTexture = NULL;
00058 }
00059 
00060 
00061 //-----------------------------------------------------------------------------
00062 // LLViewerJointShape()
00063 //-----------------------------------------------------------------------------
00064 LLViewerJointShape::LLViewerJointShape( ShapeType type, F32 red, F32 green, F32 blue, F32 alpha )
00065 {
00066         mType = type;
00067         mColor[0] = red * sColorScale;
00068         mColor[1] = green * sColorScale;
00069         mColor[2] = blue * sColorScale;
00070         mColor[3] = alpha;
00071         mTexture = NULL;
00072 }
00073 
00074 
00075 //-----------------------------------------------------------------------------
00076 // ~LLViewerJointShape()
00077 // Class Destructor
00078 //-----------------------------------------------------------------------------
00079 LLViewerJointShape::~LLViewerJointShape()
00080 {
00081 }
00082 
00083 
00084 //--------------------------------------------------------------------
00085 // getType()
00086 //--------------------------------------------------------------------
00087 LLViewerJointShape::ShapeType LLViewerJointShape::getType()
00088 {
00089         return mType;
00090 }
00091 
00092 
00093 //--------------------------------------------------------------------
00094 // setType()
00095 //--------------------------------------------------------------------
00096 void LLViewerJointShape::setType( ShapeType type )
00097 {
00098         mType = type;
00099 }
00100 
00101 
00102 //--------------------------------------------------------------------
00103 // getColor()
00104 //--------------------------------------------------------------------
00105 void LLViewerJointShape::getColor( F32 *red, F32 *green, F32 *blue, F32 *alpha )
00106 {
00107         *red   = mColor[0];
00108         *green = mColor[1];
00109         *blue  = mColor[2];
00110         *alpha = mColor[3];
00111 }
00112 
00113 //--------------------------------------------------------------------
00114 // setColor()
00115 //--------------------------------------------------------------------
00116 void LLViewerJointShape::setColor( F32 red, F32 green, F32 blue, F32 alpha )
00117 {
00118         mColor[0] = red  * sColorScale;
00119         mColor[1] = green * sColorScale;
00120         mColor[2] = blue * sColorScale;
00121         mColor[3] = alpha;
00122 }
00123 
00124 
00125 //--------------------------------------------------------------------
00126 // getTexture()
00127 //--------------------------------------------------------------------
00128 LLViewerImage *LLViewerJointShape::getTexture()
00129 {
00130         return mTexture;
00131 }
00132 
00133 //--------------------------------------------------------------------
00134 // setTexture()
00135 //--------------------------------------------------------------------
00136 void LLViewerJointShape::setTexture( LLViewerImage *texture )
00137 {
00138         mTexture = texture;
00139 }
00140 
00141 
00142 //--------------------------------------------------------------------
00143 // drawBone()
00144 //--------------------------------------------------------------------
00145 void LLViewerJointShape::drawBone()
00146 {
00147 }
00148 
00149 
00150 //--------------------------------------------------------------------
00151 // isTransparent()
00152 //--------------------------------------------------------------------
00153 BOOL LLViewerJointShape::isTransparent()
00154 {
00155         return (        (mColor[3] < 1.0f) ||
00156                                 (!mTexture.isNull() && (mTexture->getComponents()==4)) );
00157 }
00158 
00159 //--------------------------------------------------------------------
00160 // drawShape()
00161 //--------------------------------------------------------------------
00162 U32 LLViewerJointShape::drawShape( F32 pixelArea, BOOL first_pass )
00163 {
00164         U32 triangle_count = 0;
00165 
00166         //----------------------------------------------------------------
00167         // render ST_NULL
00168         //----------------------------------------------------------------
00169         if (mType == ST_NULL)
00170         {
00171                 return triangle_count;
00172         }
00173 
00174         //----------------------------------------------------------------
00175         // setup current color
00176         //----------------------------------------------------------------
00177         glColor4fv(mColor.mV);
00178 
00179         //----------------------------------------------------------------
00180         // setup current texture
00181         //----------------------------------------------------------------
00182         glMatrixMode(GL_TEXTURE);
00183         glPushMatrix();
00184         glLoadIdentity();
00185         if (mType == ST_SPHERE)
00186         {
00187                 glTranslatef(-0.25f, 0.0f, 0.0f);
00188         }
00189         glMatrixMode(GL_MODELVIEW);
00190         LLViewerImage::bindTexture(mTexture);
00191 
00192         //----------------------------------------------------------------
00193         // update pixel area
00194         //----------------------------------------------------------------
00195         F32 s1 = llmax( getScale().mV[VX], llmax( getScale().mV[VY], getScale().mV[VZ] ) );
00196         F32 s2 = llmin( getScale().mV[VX], llmax( getScale().mV[VY], getScale().mV[VZ] ) );
00197         pixelArea *= s1 * s2;
00198 
00199         //----------------------------------------------------------------
00200         // render shape
00201         //----------------------------------------------------------------
00202         switch ( mType )
00203         {
00204         case ST_CUBE:
00205                 gBox.render();
00206                 break;
00207 
00208         case ST_SPHERE:
00209                 gSphere.render( pixelArea );
00210                 break;
00211 
00212         case ST_CYLINDER:
00213                 gCylinder.render( pixelArea );
00214                 break;
00215 
00216         default:
00217                 break;
00218         }
00219 
00220         //----------------------------------------------------------------
00221         // disable texture
00222         //----------------------------------------------------------------
00223         if ( mTexture )
00224         {
00225                 glMatrixMode(GL_TEXTURE);
00226                 glPopMatrix();
00227                 glMatrixMode(GL_MODELVIEW);
00228         }
00229 
00230         return triangle_count;
00231 }
00232 
00233 // End

Generated on Thu Jul 1 06:09:28 2010 for Second Life Viewer by  doxygen 1.4.7