K3dPolyPlaneBuild.cpp

Go to the documentation of this file.
00001 
00011 /***************************************************************************
00012  *   Copyright (C) 2007 by Jan Koci   *
00013  *   honza.koci@email.cz   *
00014  *   http://kengine.sourceforge.net/tutorial/
00015  *                                                                         *
00016  *   This program is free software; you can redistribute it and/or modify  *
00017  *   it under the terms of the GNU General Public License as published by  *
00018  *   the Free Software Foundation; either version 2 of the License, or     *
00019  *   (at your option) any later version.                                   *
00020  *                                                                         *
00021  *   This program is distributed in the hope that it will be useful,       *
00022  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00023  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00024  *   GNU General Public License for more details.                          *
00025  *                                                                         *
00026  *   You should have received a copy of the GNU General Public License     *
00027  *   along with this program; if not, write to the                         *
00028  *   Free Software Foundation, Inc.,                                       *
00029  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
00030  ***************************************************************************/
00031 
00032 #include "K3dPolyPlaneBuild.h"
00033 
00034 
00035 K3dPolyPlaneBuild::K3dPolyPlaneBuild(K3dGameData *_pGameData)
00036 {
00037         m_pGameData = _pGameData;
00038         // Set this pointer to the game data
00039         m_pGameData->SetPolyPlaneBuild(this);
00040         m_pPlaneBuild = m_pGameData->GetPlaneBuild();
00041 }
00042 
00043 K3dPolyPlaneBuild::~K3dPolyPlaneBuild(void)
00044 {
00045         DeletePolyPlanes();
00046 }
00047 
00049 void K3dPolyPlaneBuild::CalcVertsOnPlane(K3dPolyPlane *_pPlane)
00050 {
00051         _pPlane->GetOnPlaneVertexArray().clear();
00052         for(int i=0; i<(int) _pPlane->GetVertexArray().size(); i++)
00053         {
00054                 K3dVector3Obj *pVertex = _pPlane->GetVertexArray()[i];
00055                 // Calculate distance between plane and point
00056                 float fDistance = m_pGameData->GetIntersection()->PointPlane(*_pPlane, *pVertex);
00057                 if(fDistance == (float) 0)
00058                 {
00059                         _pPlane->GetOnPlaneVertexArray().push_back(pVertex);
00060                 }
00061         }
00062 }
00063 
00066 K3dPolyPlane *K3dPolyPlaneBuild::CreateNewPolyPlaneObj()
00067 {
00068         K3dPlaneObj *pPlaneObj = m_pPlaneBuild->CreateNewPlaneObj();
00069         K3dPolyPlane *pPolyPlane = m_pGameData->GetPolyPlaneSP().New();
00070         pPolyPlane->SetPosition(pPlaneObj->GetPosition());
00071         pPolyPlane->SetNormal(pPlaneObj->GetNormal());
00072         pPolyPlane->GetVertexArray() = pPlaneObj->GetVertexArray();
00073         pPolyPlane->SetColor(pPlaneObj->GetColor());
00074         pPolyPlane->SetRelPosition(pPlaneObj->GetRelPosition());
00075         pPolyPlane->SetRelNormal(pPlaneObj->GetRelNormal());
00076         pPolyPlane->SetRotation(pPlaneObj->GetRotation());
00077         pPolyPlane->SetMatrix(pPlaneObj->GetMatrix());
00078         pPolyPlane->SetRotMatrix(pPlaneObj->GetRotMatrix());    
00079         pPolyPlane->GetId() = m_pGameData->GetPolyPlaneSP().GetNum()-1;
00080         return pPolyPlane;
00081 }
00082 
00084 void K3dPolyPlaneBuild::DeletePolyPlanes()
00085 {
00086         std::cout << "void K3dPolyPlaneBuild::DeletePolyPlanes()" << endl;
00087         while(m_pGameData->GetPolyPlaneSP().GetNum())
00088         {
00089                 K3dPolyPlane *p = m_pGameData->GetPolyPlaneSP().Get(0);
00090                 p = m_pGameData->GetPolyPlaneSP().Delete(p);
00091         }
00092 }
00093 
00098 K3dPolyPlane *K3dPolyPlaneBuild::CreateNewPolyPlaneObj(const K3dVector3Obj &_rkPosition,const K3dVector3Obj &_rkNormal)
00099 {
00100         K3dPolyPlane *pPlane = CreateNewPolyPlaneObj();
00101         m_pPlaneBuild->CalcPlane(pPlane, _rkPosition, _rkNormal);
00102         return pPlane;
00103 }
00104 
00110 K3dPolyPlane *K3dPolyPlaneBuild::CreateNewPolyPlaneObj(const K3dVector3Obj &_rkV0,const K3dVector3Obj &_rkV1,const K3dVector3Obj &_rkV2)
00111 {
00112         K3dPolyPlane *pPlane = CreateNewPolyPlaneObj();
00113         m_pPlaneBuild->CalcPlane(pPlane, _rkV0, _rkV1, _rkV2);
00114         return pPlane;
00115 }
00116 

Generated on Thu Aug 16 23:53:28 2007 for K3dEngine by  doxygen 1.5.0