Blender  V2.59
RAS_TexVert.h
Go to the documentation of this file.
00001 /*
00002  * $Id: RAS_TexVert.h 35072 2011-02-22 12:42:55Z jesterking $
00003  *
00004  * ***** BEGIN GPL LICENSE BLOCK *****
00005  *
00006  * This program is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU General Public License
00008  * as published by the Free Software Foundation; either version 2
00009  * of the License, or (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software Foundation,
00018  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00019  *
00020  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
00021  * All rights reserved.
00022  *
00023  * The Original Code is: all of this file.
00024  *
00025  * Contributor(s): none yet.
00026  *
00027  * ***** END GPL LICENSE BLOCK *****
00028  */
00029 
00034 #ifndef __RAS_TEXVERT
00035 #define __RAS_TEXVERT
00036 
00037 
00038 #include "MT_Point3.h"
00039 #include "MT_Point2.h"
00040 #include "MT_Transform.h"
00041 
00042 #ifdef WITH_CXX_GUARDEDALLOC
00043 #include "MEM_guardedalloc.h"
00044 #endif
00045 
00046 static MT_Point3 g_pt3;
00047 static MT_Point2 g_pt2;
00048 
00049 class RAS_TexVert
00050 {
00051         
00052         float                   m_localxyz[3];  // 3*4 = 12
00053         float                   m_uv1[2];               // 2*4 =  8
00054         float                   m_uv2[2];               // 2*4 =  8
00055         unsigned int    m_rgba;                 //        4
00056         float                   m_tangent[4];   // 4*4 =  16
00057         float                   m_normal[3];    // 3*4 =  12
00058         short                   m_flag;                 //        2
00059         short                   m_softBodyIndex;                //2
00060         unsigned int    m_unit;                 //                4
00061         unsigned int    m_origindex;            //    4
00062                                                                         //---------
00063                                                                         //       56+6+8+2=72
00064         // 32 bytes total size, fits nice = 56 = not fit nice.
00065 
00066 public:
00067         enum {
00068                 FLAT = 1,
00069                 SECOND_UV = 2,
00070                 MAX_UNIT = 8
00071         };
00072 
00073         short getFlag() const;
00074         unsigned int getUnit() const;
00075         
00076         RAS_TexVert()// :m_xyz(0,0,0),m_uv(0,0),m_rgba(0)
00077         {}
00078         RAS_TexVert(const MT_Point3& xyz,
00079                                 const MT_Point2& uv,
00080                                 const MT_Point2& uv2,
00081                                 const MT_Vector4& tangent,
00082                                 const unsigned int rgba,
00083                                 const MT_Vector3& normal,
00084                                 const bool flat,
00085                                 const unsigned int origindex);
00086         ~RAS_TexVert() {};
00087 
00088         const float* getUV1 () const { 
00089                 return m_uv1;
00090         };
00091 
00092         const float* getUV2 () const { 
00093                 return m_uv2;
00094         };
00095 
00096         const float* getXYZ() const { 
00097                 return m_localxyz;
00098         };
00099         
00100         const float* getNormal() const {
00101                 return m_normal;
00102         }
00103         
00104         short int getSoftBodyIndex() const
00105         {
00106                 return m_softBodyIndex;
00107         }
00108         
00109         void    setSoftBodyIndex(short int sbIndex)
00110         {
00111                 m_softBodyIndex = sbIndex;
00112         }
00113 
00114         const float* getTangent() const {
00115                 return m_tangent;
00116         }
00117 
00118         const unsigned char* getRGBA() const {
00119                 return (unsigned char *) &m_rgba;
00120         }
00121 
00122         unsigned int getOrigIndex() const {
00123                 return m_origindex;
00124         }
00125 
00126         void                            SetXYZ(const MT_Point3& xyz);
00127         void                            SetXYZ(const float *xyz);
00128         void                            SetUV(const MT_Point2& uv);
00129         void                            SetUV2(const MT_Point2& uv);
00130 
00131         void                            SetRGBA(const unsigned int rgba);
00132         void                            SetNormal(const MT_Vector3& normal);
00133         void                            SetTangent(const MT_Vector3& tangent);
00134         void                            SetFlag(const short flag);
00135         void                            SetUnit(const unsigned u);
00136         
00137         void                            SetRGBA(const MT_Vector4& rgba);
00138         const MT_Point3&        xyz();
00139 
00140         void                            Transform(const class MT_Matrix4x4& mat,
00141                                       const class MT_Matrix4x4& nmat);
00142 
00143         // compare two vertices, to test if they can be shared, used for
00144         // splitting up based on uv's, colors, etc
00145         bool                            closeTo(const RAS_TexVert* other);
00146         
00147 #ifdef WITH_CXX_GUARDEDALLOC
00148 public:
00149         void *operator new(size_t num_bytes) { return MEM_mallocN(num_bytes, "GE:RAS_TexVert"); }
00150         void operator delete( void *mem ) { MEM_freeN(mem); }
00151 #endif
00152 };
00153 
00154 #endif //__RAS_TEXVERT
00155