00001 /**************************************************************************** 00002 00003 This file is part of the GLC-lib library. 00004 Copyright (C) 2005-2008 Laurent Ribon (laumaya@users.sourceforge.net) 00005 Version 0.9.9, packaged on May, 2008. 00006 00007 http://glc-lib.sourceforge.net 00008 00009 GLC-lib is free software; you can redistribute it and/or modify 00010 it under the terms of the GNU General Public License as published by 00011 the Free Software Foundation; either version 2 of the License, or 00012 (at your option) any later version. 00013 00014 GLC-lib is distributed in the hope that it will be useful, 00015 but WITHOUT ANY WARRANTY; without even the implied warranty of 00016 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00017 GNU General Public License for more details. 00018 00019 You should have received a copy of the GNU General Public License 00020 along with GLC-lib; if not, write to the Free Software 00021 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00022 00023 *****************************************************************************/ 00024 00026 00027 #include "glc_part.h" 00028 #include "glc_world.h" 00029 #include "glc_mesh2.h" 00030 00031 GLC_Part::GLC_Part(GLC_Collection *pCollection, GLC_Instance& instance) 00032 : GLC_Node(pCollection) 00033 , m_RepID(instance.getID()) 00034 { 00035 m_pCollection->add(instance); 00036 } 00037 00038 GLC_Part::~GLC_Part() 00039 { 00040 m_pCollection->remove(m_RepID); 00041 } 00043 // Get Functions 00045 00046 // Clone the part 00047 GLC_Part* GLC_Part::clone(GLC_Collection * pCollection) const 00048 { 00049 GLC_Instance instance(m_pCollection->getInstanceHandle(m_RepID)->instanciate()); 00050 GLC_Part* pReturnPart= new GLC_Part(pCollection, instance); 00051 return pReturnPart; 00052 } 00053 00055 int GLC_Part::getNumberOfFaces() const 00056 { 00057 int number= 0; 00058 const GLC_Mesh2* pMesh= dynamic_cast<GLC_Mesh2*>(m_pCollection->getInstanceHandle(m_RepID)->getGeometry()); 00059 if (NULL != pMesh) 00060 { 00061 number= pMesh->getNumberOfFaces(); 00062 } 00063 return number; 00064 } 00066 int GLC_Part::getNumberOfVertex() const 00067 { 00068 int number= 0; 00069 const GLC_Mesh2* pMesh= dynamic_cast<GLC_Mesh2*>(m_pCollection->getInstanceHandle(m_RepID)->getGeometry()); 00070 if (NULL != pMesh) 00071 { 00072 number= pMesh->getNumberOfVertex(); 00073 } 00074 return number; 00075 } 00076 00077 00079 // Set Functions 00081 00082 // Move the Part with specified matrix 00083 void GLC_Part::move(const GLC_Matrix4x4 &matrix) 00084 { 00085 m_RelativeMatrix= matrix * m_RelativeMatrix; 00086 m_AbsoluteMatrix= matrix * m_AbsoluteMatrix; 00087 m_pCollection->getInstanceHandle(m_RepID)->setMatrix(m_AbsoluteMatrix); 00088 } 00089 // Update Part absolute matrix 00090 void GLC_Part::updateAbsoluteMatrix() 00091 { 00092 if (NULL != m_pParent) 00093 { 00094 m_AbsoluteMatrix= m_pParent->absoluteMatrix() * m_RelativeMatrix; 00095 m_pCollection->getInstanceHandle(m_RepID)->setMatrix(m_AbsoluteMatrix); 00096 } 00097 } 00099 void GLC_Part::reverseMeshNormal() 00100 { 00101 GLC_Mesh2* pMesh= dynamic_cast<GLC_Mesh2*>(m_pCollection->getInstanceHandle(m_RepID)->getGeometry()); 00102 if (NULL != pMesh) 00103 { 00104 pMesh->reverseNormal(); 00105 } 00106 } 00107
1.4.5