K3dPlaneBuild.cpp

Go to the documentation of this file.
00001 
00012 /***************************************************************************
00013  *   Copyright (C) 2007 by Jan Koci   *
00014  *   honza.koci@email.cz   *
00015  *   http://kengine.sourceforge.net/tutorial/
00016  *                                                                         *
00017  *   This program is free software; you can redistribute it and/or modify  *
00018  *   it under the terms of the GNU General Public License as published by  *
00019  *   the Free Software Foundation; either version 2 of the License, or     *
00020  *   (at your option) any later version.                                   *
00021  *                                                                         *
00022  *   This program is distributed in the hope that it will be useful,       *
00023  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00024  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00025  *   GNU General Public License for more details.                          *
00026  *                                                                         *
00027  *   You should have received a copy of the GNU General Public License     *
00028  *   along with this program; if not, write to the                         *
00029  *   Free Software Foundation, Inc.,                                       *
00030  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
00031  ***************************************************************************/
00032 
00033 #include "K3dPlaneBuild.h"
00034 
00038 K3dPlaneBuild::K3dPlaneBuild(K3dGameData *_pGameData): K3dPlaneWork(_pGameData)
00039 {
00040         m_pGameData = _pGameData;
00041         // Set this pointer to the game data
00042         m_pGameData->SetPlaneBuild(this);
00043         m_pVector3Build = m_pGameData->GetVector3Build();
00044         m_pColor3Build =  m_pGameData->GetColor3Build();
00045         m_pMatrixBuild = m_pGameData->GetMatrixBuild();
00046 }
00047 
00048 K3dPlaneBuild::~K3dPlaneBuild(void)
00049 {
00050         DeletePlanes();
00051 }
00052 
00055 K3dPlaneObj *K3dPlaneBuild::CreateNewPlaneObj()
00056 {
00057         K3dPlaneObj *pPlaneObj = m_pGameData->GetPlaneObjSP().New();
00058         pPlaneObj->SetPosition(m_pVector3Build->CreateNewVector3());
00059         pPlaneObj->SetNormal(m_pVector3Build->CreateNewVector3());
00060         pPlaneObj->DeleteVertexArray();
00061         for(int i=0; i<4; i++)
00062         {
00063                 pPlaneObj->AddVertex(m_pVector3Build->CreateNewVector3());
00064         }
00065         pPlaneObj->SetColor(m_pColor3Build->CreateNewColor3());
00066         pPlaneObj->GetColor()->GetR() = 0;
00067         pPlaneObj->GetColor()->GetG() = 0;
00068         pPlaneObj->GetColor()->GetB() = 255;
00069         pPlaneObj->SetRelPosition(m_pVector3Build->CreateNewVector3());
00070         pPlaneObj->SetRelNormal(m_pVector3Build->CreateNewVector3());
00071         pPlaneObj->SetRotation(m_pVector3Build->CreateNewVector3());
00072         pPlaneObj->SetMatrix(m_pMatrixBuild->CreateNewMatrix());
00073         pPlaneObj->SetRotMatrix(m_pMatrixBuild->CreateNewMatrix());
00074         pPlaneObj->GetId() = m_pGameData->GetPlaneObjSP().GetNum()-1;
00075         return pPlaneObj;
00076 }
00077 
00079 void K3dPlaneBuild::LoadPlanes()
00080 {
00081         cout << "void K3dPlaneBuild::LoadPlanes()" << endl;
00082         K3dString strFc = "void K3dPlaneBuild::LoadPlanes() -- ";
00083         K3dString strOut;
00084         // Get virtual machine from global data
00085         K3dLua *pLua = m_pGameData->GetLua();
00086         // Get number of planes
00087         pLua->LuaGetGlobal(K_STR_NUM_PLANES);
00088     if (!pLua->LuaIsNumber(-1))
00089         {
00090                 cerr << "Warning :: void K3dPlaneBuild::LoadPlanes() -- Doesn`t load " << K_STR_NUM_PLANES << " from map file" << endl;
00091                 return;
00092     }
00093         int iNumPlanes = (int) pLua->LuaToNumber(-1);
00094         for(int i=0; i<iNumPlanes; i++)
00095         {
00096                 K3dPlaneObj *pPlane = CreateNewPlaneObj();
00097                 K3dString kString(K_STR_PLANE);
00098                 // Add number behind string
00099                 kString.AddNumber(i);
00100                 pLua->LuaGetGlobal(kString.GetString().c_str());
00101                 if (!pLua->LuaIsTable(-1))
00102                 {
00103                         strOut = strFc + kString;
00104                         strOut += " is not a valid line table";
00105                         pLua->LuaError(strOut.GetString().c_str());
00106                         return;
00107                 }
00108                 pPlane->GetName() = pLua->LuaGetFieldString(K_STR_NAME);
00109                 pPlane->GetNormal()->GetX() =  (float)pLua->LuaGetFieldNumber(K_STR_NORMAL_X);
00110                 pPlane->GetNormal()->GetY() =  (float)pLua->LuaGetFieldNumber(K_STR_NORMAL_Y);
00111                 pPlane->GetNormal()->GetZ() =  (float)pLua->LuaGetFieldNumber(K_STR_NORMAL_Z);
00112                 pPlane->GetWidth() =  (float)pLua->LuaGetFieldNumber(K_STR_WIDTH);
00113                 pPlane->GetHeight() =  (float)pLua->LuaGetFieldNumber(K_STR_HEIGHT);
00114                 pPlane->GetColor()->GetR() =  (GLubyte)pLua->LuaGetFieldNumber(K_STR_R);
00115                 pPlane->GetColor()->GetG() =  (GLubyte)pLua->LuaGetFieldNumber(K_STR_G);
00116                 pPlane->GetColor()->GetB() =  (GLubyte)pLua->LuaGetFieldNumber(K_STR_B);
00117                 Init(pPlane);
00118         }
00119 }
00120 
00122 void K3dPlaneBuild::DeletePlanes()
00123 {
00124         std::cout << "void K3dPlaneBuild::DeletePlanes()" << endl;
00125         while(m_pGameData->GetPlaneObjSP().GetNum())
00126         {
00127                 K3dPlaneObj *p = m_pGameData->GetPlaneObjSP().Get(0);
00128                 p = m_pGameData->GetPlaneObjSP().Delete(p);
00129         }
00130 }
00131 
00136 K3dPlaneObj *K3dPlaneBuild::CreateNewPlaneObj(const K3dVector3Obj &_rkPosition,const K3dVector3Obj &_rkNormal)
00137 {
00138         K3dPlaneObj *pPlane = CreateNewPlaneObj();
00139         CalcPlane(pPlane, _rkPosition, _rkNormal);
00140         return pPlane;
00141 }
00142 
00148 K3dPlaneObj *K3dPlaneBuild::CreateNewPlaneObj(const K3dVector3Obj &_rkV0,const K3dVector3Obj &_rkV1,const K3dVector3Obj &_rkV2)
00149 {
00150         K3dPlaneObj *pPlane = CreateNewPlaneObj();
00151         CalcPlane(pPlane, _rkV0, _rkV1, _rkV2);
00152         return pPlane;
00153 }
00154 

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