K3dDrawSphere.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 "K3dDrawSphere.h"
00034 
00036 void K3dDrawSphere::DrawSpheres()
00037 {
00038         for(int i=0; i<m_pGameData->GetSphereObjSP().GetNum(); i++)
00039         {
00040                 // Get sphere
00041                 K3dSphereObj *pSphere = m_pGameData->GetSphereObjSP().Get(i);
00042                 // Enable blending
00043                 glEnable(GL_BLEND);
00044                 // Set blend function
00045                 glBlendFunc(GL_ONE, GL_ONE);
00046                 glPushMatrix();
00047                 // Move with sphere by matrix
00048                 m_kViewMatrix = *m_pGameData->GetViewMatrix();
00049                 m_kModelMatrix = *pSphere->GetMatrix();
00050                 // Multiply model and view matrix
00051                 m_kViewMatrix.Multiply( m_kModelMatrix);
00052                 // Set new model view matrix
00053                 glLoadMatrixf(m_kViewMatrix.GetMatrix());
00054                 int iTextureId = pSphere->GetTextureId();
00055                 // If the sphere has a texture
00056                 if(iTextureId > 0)
00057                 {
00058                         // Texture a sphere
00059                         glEnable(GL_TEXTURE_2D);
00060                         glBindTexture(GL_TEXTURE_2D, iTextureId);
00061                         gluQuadricTexture(m_pQuadricObj, true);
00062                 }
00063                 glColor3ubv(pSphere->GetColor()->GetColorArray());
00064                 gluQuadricDrawStyle(m_pQuadricObj, GLU_FILL);
00065                 gluQuadricOrientation(m_pQuadricObj,GLU_OUTSIDE);
00066                 gluQuadricNormals(m_pQuadricObj, GLU_SMOOTH);
00067                 gluSphere(m_pQuadricObj, pSphere->GetRadius(), pSphere->GetNumSlices(), pSphere->GetNumStacks());
00068                 glPopMatrix();
00069                 // Disable blending
00070                 glDisable(GL_BLEND);
00071                 // Set default white color
00072                 glColor3ub( 255, 255, 255 ); 
00073         }
00074 }

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