K3dMngGeometry.cpp

Go to the documentation of this file.
00001 
00014 /***************************************************************************
00015  *   Copyright (C) 2007 by Jan Koci   *
00016  *   honza.koci@email.cz   *
00017  *   http://kengine.sourceforge.net/tutorial/
00018  *                                                                         *
00019  *   This program is free software; you can redistribute it and/or modify  *
00020  *   it under the terms of the GNU General Public License as published by  *
00021  *   the Free Software Foundation; either version 2 of the License, or     *
00022  *   (at your option) any later version.                                   *
00023  *                                                                         *
00024  *   This program is distributed in the hope that it will be useful,       *
00025  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00026  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00027  *   GNU General Public License for more details.                          *
00028  *                                                                         *
00029  *   You should have received a copy of the GNU General Public License     *
00030  *   along with this program; if not, write to the                         *
00031  *   Free Software Foundation, Inc.,                                       *
00032  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
00033  ***************************************************************************/
00034 
00035 
00036 #include "K3dMngGeometry.h"
00037 
00038 K3dMngGeometry::K3dMngGeometry(K3dGameData *_pGameData):
00039         K3dObjectBuild( _pGameData),
00040         K3dDraw(_pGameData),
00041         K3dAim(_pGameData),
00042         K3dTools(_pGameData)
00043 {
00044         m_pGameData = _pGameData;
00045         m_pOpenGL = m_pGameData->GetOpenGL();
00046 }
00047 
00048 K3dMngGeometry::~K3dMngGeometry()
00049 {
00050 }
00051 
00053 void K3dMngGeometry::InitMngGeometry()
00054 {
00055         cout << "void K3dMngGeometry::InitMngGeometry()" << endl;
00056         InitSphereWork();
00057         InitConvex();
00058         //InitCutPoly();
00059         LoadCameras();
00060         LoadVertices();
00061         LoadFaces();
00062         BuildTriangles();
00063         LoadBlocks();
00064         LoadSpheres();
00065         LoadLines();
00066         LoadPlanes();
00067         InitLight();
00068         BuildTriangleArray();
00069         // Create aiming ray and add to the global data
00070         CreateAimRay();
00071         LoadRays();
00072 }
00073 
00075 void K3dMngGeometry::UpdateMngGeometry()
00076 {
00077         // Get active camera index
00078         int iCamId = m_pGameData->GetActiveCamId();
00079         if(iCamId>=0)
00080         {
00081                 // Get active camera
00082                 K3dCamera *pCamera = m_pGameData->GetCameraObjSP().Get(iCamId);
00083                 if(!pCamera)
00084                 {
00085                         cerr << "void K3dMngGeometry::UpdateMngGeometry() -- Error - Pointer to camera object is NULL!!" << endl;
00086                         return;
00087                 }
00088                 pCamera->UpdateCamera();
00089         }
00090         // Calculate aiming ray
00091         CalcAimRay();
00092         UpdateSpheres();
00093         UpdatePlanes();
00094         UpdateLines();
00095 }
00096 
00098 void K3dMngGeometry::DrawMngGeometry()
00099 {
00100         m_pOpenGL->Set3DProjection();
00101         // Get active camera index
00102         int iCamId = m_pGameData->GetActiveCamId();
00103         if(iCamId>=0)
00104         {
00105                 // Get active camera
00106                 K3dCamera *pCamera = m_pGameData->GetCameraObjSP().Get(iCamId);
00107                 if(!pCamera)
00108                 {
00109                         cerr << "void K3dMngGeometry::DrawMngGeometry() -- Error - Pointer to camera object is NULL!!" << endl;
00110                         return;
00111                 }
00112                 // Look by active camera
00113                 pCamera->Look();
00114         }       
00115         // Disable texturing
00116         glDisable(GL_TEXTURE_2D);
00117         // Get modelview matrix and save this to the global data
00118         float afViewMatrix[16];
00119         glGetFloatv(GL_MODELVIEW_MATRIX, afViewMatrix);
00120         K3dMatrix kViewMatrix(afViewMatrix);
00121         *m_pGameData->GetViewMatrix() = kViewMatrix;
00122         DrawLight();
00123         DrawTriangleArray();
00124         DrawSpheres();
00125         DrawLines();
00126         DrawPlanes();
00127         DrawVertices();
00128 }
00129 
00131 void K3dMngGeometry::DeleteMngGeometry()
00132 {
00133         cout << "void K3dMngGeometry::DeleteMngGeometry()" << endl;
00134         DeleteVertices();
00135         DeleteTriangles();
00136         DeleteFaces();
00137         DeleteBlocks();
00138         DeleteLines();
00139         DeleteCameras();
00140         //DeleteTriangleArray();
00141         DeleteVertexArray();
00142         DeleteLines();
00143         DeleteSpheres();
00144         DeleteRays();
00145         DeletePlanes();
00146 }

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