Blender  V2.59
RAS_Polygon.cpp
Go to the documentation of this file.
00001 /*
00002  * $Id: RAS_Polygon.cpp 35174 2011-02-25 13:38:24Z jesterking $
00003  * ***** BEGIN GPL LICENSE BLOCK *****
00004  *
00005  * This program is free software; you can redistribute it and/or
00006  * modify it under the terms of the GNU General Public License
00007  * as published by the Free Software Foundation; either version 2
00008  * of the License, or (at your option) any later version.
00009  *
00010  * This program is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  * GNU General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU General Public License
00016  * along with this program; if not, write to the Free Software Foundation,
00017  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00018  *
00019  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
00020  * All rights reserved.
00021  *
00022  * The Original Code is: all of this file.
00023  *
00024  * Contributor(s): none yet.
00025  *
00026  * ***** END GPL LICENSE BLOCK *****
00027  */
00028 
00034 #if defined(WIN32) && !defined(FREE_WINDOWS)
00035 #pragma warning (disable:4786)
00036 #endif
00037 
00038 #include "RAS_Polygon.h"
00039 #include "RAS_MeshObject.h" /* only for GetVertexOffsetAbs */
00040 
00041 RAS_Polygon::RAS_Polygon(RAS_MaterialBucket* bucket, RAS_DisplayArray *darray, int numvert)
00042 {
00043         m_bucket = bucket;
00044         m_darray = darray;
00045         m_offset[0]= m_offset[1]= m_offset[2]= m_offset[3]= 0;
00046         m_numvert = numvert;
00047 
00048 //      m_edgecode = 255;
00049         m_polyflags = 0;
00050 }
00051 
00052 int RAS_Polygon::VertexCount()
00053 {
00054         return m_numvert;
00055 }
00056 
00057 void RAS_Polygon::SetVertexOffset(int i, unsigned short offset)
00058 {
00059         m_offset[i] = offset;
00060 }
00061 
00062 RAS_TexVert *RAS_Polygon::GetVertex(int i)
00063 {
00064         return &m_darray->m_vertex[m_offset[i]];
00065 }
00066 
00067 int RAS_Polygon::GetVertexOffset(int i)
00068 {
00069         return m_offset[i];
00070 }
00071 
00072 int RAS_Polygon::GetVertexOffsetAbs(RAS_MeshObject *mesh, int i)
00073 {
00074         /* hack that only works because there can only ever be 2 different
00075          * GetDisplayArray's per mesh. if this uses a different display array to the first
00076          * then its incices are offset.
00077          * if support for edges is added back this would need to be changed. */
00078         RAS_DisplayArray* darray= mesh->GetPolygon(0)->GetDisplayArray();
00079         
00080         if(m_darray != darray)
00081                 return m_offset[i] + darray->m_vertex.size();
00082         
00083         return m_offset[i];
00084 }
00085 
00086 /*
00087 int RAS_Polygon::GetEdgeCode()
00088 {
00089         return m_edgecode;
00090 }
00091 
00092 void RAS_Polygon::SetEdgeCode(int edgecode)
00093 {
00094         m_edgecode = edgecode;
00095 }*/
00096 
00097         
00098 bool RAS_Polygon::IsVisible()
00099 {
00100         return (m_polyflags & VISIBLE) != 0;
00101 }
00102 
00103 void RAS_Polygon::SetVisible(bool visible)
00104 {
00105         if(visible) m_polyflags |= VISIBLE;
00106         else m_polyflags &= ~VISIBLE;
00107 }
00108 
00109 bool RAS_Polygon::IsCollider()
00110 {
00111         return (m_polyflags & COLLIDER) != 0;
00112 }
00113 
00114 void RAS_Polygon::SetCollider(bool visible)
00115 {
00116         if(visible) m_polyflags |= COLLIDER;
00117         else m_polyflags &= ~COLLIDER;
00118 }
00119 
00120 bool RAS_Polygon::IsTwoside()
00121 {
00122         return (m_polyflags & TWOSIDE) != 0;
00123 }
00124 
00125 void RAS_Polygon::SetTwoside(bool twoside)
00126 {
00127         if(twoside) m_polyflags |= TWOSIDE;
00128         else m_polyflags &= ~TWOSIDE;
00129 }
00130 
00131 RAS_MaterialBucket* RAS_Polygon::GetMaterial()
00132 {
00133         return m_bucket;
00134 }
00135 
00136 RAS_DisplayArray* RAS_Polygon::GetDisplayArray()
00137 {
00138         return m_darray;
00139 }