Main Page   Namespace List   Class Hierarchy   Compound List   File List   Compound Members   File Members  

RAS_MeshObject.cpp

Go to the documentation of this file.
00001 #include "RAS_MeshObject.h"
00002 #include "RAS_IRasterizer.h"
00003 
00004 
00005 void RAS_MeshObject::Bucketize(double* oglmatrix,void* clientobj)

00006 {
00007 
00008         KX_MeshSlot ms;
00009         ms.m_clientObj = clientobj;
00010         ms.m_mesh = this;
00011         ms.m_OpenGLMatrix = oglmatrix;
00012 
00013         for (set<RAS_MaterialBucket*>::const_iterator it = m_materials.begin();
00014         !(it==m_materials.end());it++)
00015         {
00016                 (*it)->SchedulePolygons(0);
00017                 KX_ArrayOptimizer* oa = GetArrayOptimizer((*it)->GetPolyMaterial());
00018                 (*it)->SetMeshSlot(ms);
00019         }
00020 
00021 }
00022 void RAS_MeshObject::MarkVisible(double* oglmatrix,void* clientobj,bool visible)

00023 {
00024         
00025         KX_MeshSlot ms;
00026         ms.m_clientObj = clientobj;
00027         ms.m_mesh = this;
00028         ms.m_OpenGLMatrix = oglmatrix;
00029 
00030         for (set<RAS_MaterialBucket*>::const_iterator it = m_materials.begin();
00031         !(it==m_materials.end());it++)
00032         {
00033                 (*it)->SchedulePolygons(0);
00034                 KX_ArrayOptimizer* oa = GetArrayOptimizer((*it)->GetPolyMaterial());
00035                 (*it)->MarkVisibleMeshSlot(ms,visible);
00036         }
00037 
00038 }
00039 
00040 void RAS_MeshObject::RemoveFromBuckets(double* oglmatrix,void* clientobj)

00041 {
00042 
00043         KX_MeshSlot ms;
00044         ms.m_clientObj = clientobj;
00045         ms.m_mesh = this;
00046         ms.m_OpenGLMatrix = oglmatrix;
00047 
00048         for (set<RAS_MaterialBucket*>::const_iterator it = m_materials.begin();
00049         !(it==m_materials.end());it++)
00050         {
00051                 (*it)->SchedulePolygons(0);
00052                 KX_ArrayOptimizer* oa = GetArrayOptimizer((*it)->GetPolyMaterial());
00053                 (*it)->RemoveMeshSlot(ms);
00054         }
00055 
00056 }
00057 
00058 
00059 /*
00060  * RAS_MeshObject::GetVertex returns the vertex located somewhere in the vertexpool

00061  * it is the clients responsibility to make sure the array and index are valid

00062  */
00063 
00064  RAS_TexVert*   RAS_MeshObject::GetVertex(short array,short index,RAS_IPolyMaterial* polymat)

00065 {
00066          KX_ArrayOptimizer* ao = GetArrayOptimizer(polymat);//*(m_matVertexArrays[*polymat]);
00067         return &((*(ao->m_VertexArrayCache1)[array])[index]);
00068 }
00069 
00070 
00071 void RAS_MeshObject::ClearArrayData()

00072 {
00073         for (int i=0;i<m_matVertexArrayS.size();i++)
00074         {       KX_ArrayOptimizer** ao = m_matVertexArrayS.at(i);
00075                 if (ao)
00076                         delete *ao;
00077         }
00078 
00079 }
00080 
00081 
00085 
00086 int     RAS_MeshObject::FindVertexArray(int numverts,RAS_IPolyMaterial* polymat)

00087 {
00088         bool found=false;
00089         int array=-1;
00090         
00091         KX_ArrayOptimizer* ao = GetArrayOptimizer(polymat);
00092 
00093         for (int i=0;i<ao->m_VertexArrayCache1.size();i++)
00094         {
00095                 if ( (ao->m_TriangleArrayCount[i] + (numverts-2)) < BUCKET_MAX_TRIANGLES) 
00096                 {
00097                          if((ao->m_VertexArrayCache1[i]->size()+numverts < BUCKET_MAX_INDICES))
00098                                 {
00099                                         array = i;
00100                                         ao->m_TriangleArrayCount[array]+=numverts-2;
00101                                         break;
00102                                 }
00103                 }
00104                 else
00105                 {
00106                         int i=0;
00107                 }
00108         }
00109         
00110 
00111         if (array == -1)
00112         {
00113                 array = ao->m_VertexArrayCache1.size();
00114                 vector<RAS_TexVert>* va = new vector<RAS_TexVert>;
00115                 ao->m_VertexArrayCache1.push_back(va);
00116                 KX_IndexArray *ia = new KX_IndexArray();
00117                 ao->m_IndexArrayCache1.push_back(ia);
00118                 ao->m_TriangleArrayCount.push_back(numverts-2);
00119         }
00120 
00121                 
00122         return array;
00123 }
00124 
00125 
00126 
00127 
00128 //void RAS_MeshObject::Transform(const MT_Transform& trans)
00129 //{
00130         //m_trans.translate(MT_Vector3(0,0,1));//.operator *=(trans);
00131         
00132 //      for (int i=0;i<m_Polygons.size();i++)
00133 //      {
00134 //              m_Polygons[i]->Transform(trans);
00135 //      }
00136 //}
00137 
00138 
00139 /*
00140 void RAS_MeshObject::RelativeTransform(const MT_Vector3& vec)

00141 {

00142         for (int i=0;i<m_Polygons.size();i++)

00143         {

00144                 m_Polygons[i]->RelativeTransform(vec);

00145         }

00146 }

00147 */
00148 
00149 void RAS_MeshObject::UpdateMaterialList()

00150 {
00151 
00152         m_materials.clear();
00153         int numpolys = m_Polygons.size();
00154         // for all polygons, find out which material they use, and add it to the set of materials
00155         for (int i=0;i<numpolys;i++)
00156         {
00157                 m_materials.insert(m_Polygons[i]->GetMaterial());
00158         }
00159         int nummaterials = m_materials.size();
00160 
00161 }
00162 
00163 void    RAS_MeshObject::SchedulePolygons(int drawingmode,RAS_IRasterizer* rasty)

00164 {
00165         int nummaterials = m_materials.size();
00166         int i;
00167                 
00168         if (m_bModified)
00169         {
00170                 for (set<RAS_MaterialBucket*>::const_iterator it = m_materials.begin();
00171                 !(it==m_materials.end());it++)
00172                 {
00173 
00174                         (*it)->SchedulePolygons(drawingmode);
00175                 }
00176 
00177                 
00178                 
00179                 int numpolys = m_Polygons.size();
00180                 //int resultingdrawingmode = GEN_min(m_drawingmode, 
00181                 
00182                 if ((rasty->GetDrawingMode() > RAS_IRasterizer::KX_BOUNDINGBOX) && 
00183                         (rasty->GetDrawingMode() < RAS_IRasterizer::KX_SOLID))
00184                 {
00185                         for (i=0;i<numpolys;i++)
00186                         {
00187                                 //m_Polygons[i]->ScheduleWireframePolygon((*it));
00188                                 RAS_Polygon* poly = m_Polygons[i];
00189                                 if (poly->IsVisible())
00190                                         ScheduleWireframePoly(poly->GetVertexIndexBase(),poly->VertexCount(),poly->GetEdgeCode()
00191                                         ,poly->GetMaterial()->GetPolyMaterial());
00192                                 
00193                         }
00194                 } else
00195                 {
00196                         for (i=0;i<numpolys;i++)
00197                         {
00198                                 RAS_Polygon* poly = m_Polygons[i];
00199                                 if (poly->IsVisible())
00200                                 {
00201                                         SchedulePoly(poly->GetVertexIndexBase(),poly->VertexCount(),poly->GetMaterial()->GetPolyMaterial());
00202                                 }
00203                         }
00204                 }
00205                 
00206                 
00207                 
00208                 m_bModified = false;
00209         } 
00210         
00211         //      }
00212 }

Generated at Thu Feb 1 13:03:08 2001 for Ketsji Game Engine by doxygen1.2.3 written by Dimitri van Heesch, © 1997-2000