K3dDrawPlane.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 
00034 #include "K3dDrawPlane.h"
00035 
00037 void K3dDrawPlane::DrawPlanes()
00038 {
00039         for(int i=0; i<m_pGameData->GetPlaneObjSP().GetNum(); i++)
00040         {
00041                 // Get plane
00042                 K3dPlaneObj *pPlane = m_pGameData->GetPlaneObjSP().Get(i);
00043                 if(pPlane->GetIsVisible() == true)
00044                 {
00045                         glDisable(GL_TEXTURE_2D);
00046                         glColor3ubv(pPlane->GetColor()->GetColorArray());
00047                         glLineWidth(pPlane->GetWidth());
00048                         // Disable cull face
00049                         glDisable(GL_CULL_FACE);        
00050                         // Enable blending
00051                         glEnable(GL_BLEND);
00052                         // Set blend function
00053                         glBlendFunc(GL_ONE, GL_ONE);
00054                         glPushMatrix();
00055                         // Move with plane by matrix
00056                         m_kViewMatrix = *m_pGameData->GetViewMatrix();
00057                         m_kModelMatrix = *pPlane->GetMatrix();
00058                         // Multiply model and view matrix
00059                         m_kViewMatrix.Multiply( m_kModelMatrix);
00060                         // Set new view matrix
00061                         glLoadMatrixf(m_kViewMatrix.GetMatrix());
00062                         glBegin( GL_QUADS  );
00063                                 if(pPlane->GetVertexArray().size() == 4)
00064                                 {
00065                                         for(int iVertexId=0; iVertexId < 4; iVertexId++)
00066                                         {
00067                                                 glVertex3f((GLfloat) pPlane->GetVertexArray()[iVertexId]->GetX(), (GLfloat) pPlane->GetVertexArray()[iVertexId]->GetY(), (GLfloat) pPlane->GetVertexArray()[iVertexId]->GetZ());
00068                                         }
00069                                 }
00070                                 else
00071                                 {
00072                                         cerr << "Error in K3dDrawPlane::DrawPlanes() -- Number of plane vertices must be 4 !!!. Current number of vertices are " << pPlane->GetVertexArray().size() << endl;
00073                                 }
00074                         glEnd();
00075                         glPopMatrix();
00076                         glPushMatrix();
00077                         // Draw normal vector
00078                         glColor3ub(255,255,0);
00079                         glLineWidth(3);
00080                         glBegin( GL_LINES  );
00081                                 glVertex3f((GLfloat) pPlane->GetPosition()[0][0], (GLfloat) pPlane->GetPosition()[0][1], (GLfloat) pPlane->GetPosition()[0][2]);
00082                                 K3dVector3 kNormalPos = *pPlane->GetPosition() + (*pPlane->GetNormal() * pPlane->GetWidth());
00083                                 glVertex3f((GLfloat) kNormalPos[0], (GLfloat) kNormalPos[1], (GLfloat) kNormalPos[2]);
00084                         glEnd();
00085                         glLineWidth(1);
00086                         glPopMatrix();
00087                         // Disable blending
00088                         glDisable(GL_BLEND);
00089                         // Enable cull face
00090                         glEnable(GL_CULL_FACE); 
00091                         // Set default white color
00092                         glColor3ub( 255, 255, 255 ); 
00093                         glEnable(GL_TEXTURE_2D);                // Enable texturing*/
00094                 }
00095         }
00096 }

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