Primitive.cpp

Go to the documentation of this file.
00001 // Copyright (C) 2005 Dave Griffiths
00002 //
00003 // This program is free software; you can redistribute it and/or modify
00004 // it under the terms of the GNU General Public License as published by
00005 // the Free Software Foundation; either version 2 of the License, or
00006 // (at your option) any later version.
00007 //
00008 // This program is distributed in the hope that it will be useful,
00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00011 // GNU General Public License for more details.
00012 //
00013 // You should have received a copy of the GNU General Public License
00014 // along with this program; if not, write to the Free Software
00015 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00016 
00017 #include "Primitive.h"                          
00018 
00019 using namespace Fluxus; 
00020 
00021 Primitive::Primitive() : 
00022 m_IsPhysical(false),
00023 m_Hidden(false),
00024 m_Selectable(true)
00025 {
00026 }
00027 
00028 Primitive::Primitive(const Primitive &other) :
00029 PDataContainer(other),
00030 m_State(other.m_State),
00031 m_IsPhysical(other.m_IsPhysical),
00032 m_Hidden(other.m_IsPhysical),
00033 m_Selectable(other.m_IsPhysical) 
00034 {
00035 }
00036            
00037 Primitive::~Primitive()
00038 {
00039 }   
00040                 
00041 void Primitive::Prerender()
00042 {
00044     // (not all, as they are often primitive dependant)
00045     if (m_State.Hints & HINT_ORIGIN) RenderAxes();  
00046     if (m_State.Hints & HINT_BOUND) RenderBoundingBox();
00047     if (m_State.Hints & HINT_VERTCOLS) glEnable(GL_COLOR_MATERIAL);
00048     else glDisable(GL_COLOR_MATERIAL);
00049     if (m_State.Hints & HINT_IGNORE_DEPTH) glDisable(GL_DEPTH_TEST);
00050     else glEnable(GL_DEPTH_TEST);
00051     
00052     if (m_State.Shader)
00053     {
00054         for (map<string,PData*>::iterator i=m_PData.begin(); i!=m_PData.end(); i++)
00055         {
00056             TypedPData<dVector> *data = dynamic_cast<TypedPData<dVector>*>(i->second);  
00057             if (data) m_State.Shader->SetVectorArray(i->first,data->m_Data);
00058             else
00059             {
00060                 TypedPData<dColour> *data = dynamic_cast<TypedPData<dColour>*>(i->second);
00061                 if (data) m_State.Shader->SetColourArray(i->first,data->m_Data);
00062                 else 
00063                 {
00064                     TypedPData<float> *data = dynamic_cast<TypedPData<float>*>(i->second);
00065                     if (data) m_State.Shader->SetFloatArray(i->first,data->m_Data);
00066                 }
00067             }
00068         }
00069     }
00070     
00071 }
00072     
00073 void Primitive::RenderAxes()
00074 {
00075     glLineWidth(1);
00076     glDisable(GL_LIGHTING);
00077     glBegin(GL_LINES);
00078         glColor3f(1,0,0);
00079         glVertex3f(0,0,0);
00080         glVertex3f(1,0,0);
00081     
00082         glColor3f(0,1,0);
00083         glVertex3f(0,0,0);
00084         glVertex3f(0,1,0);
00085         
00086         glColor3f(0,0,1);
00087         glVertex3f(0,0,0);
00088         glVertex3f(0,0,1);
00089     glEnd();
00090 
00091     /*glColor3f(1, 0, 0);
00092     glRasterPos3f(1.1, 0.0, 0.0);
00093     glutBitmapCharacter(GLUT_BITMAP_HELVETICA_12, 'x');
00094     glColor3f(0, 1, 0);
00095     glRasterPos3f(0.0, 1.1, 0.0);
00096     glutBitmapCharacter(GLUT_BITMAP_HELVETICA_12, 'y');
00097     glColor3f(0, 0, 1);
00098     glRasterPos3f(0.0, 0.0, 1.1);
00099     glutBitmapCharacter(GLUT_BITMAP_HELVETICA_12, 'z');*/
00100     glEnable(GL_LIGHTING);
00101 }
00102                 
00103 void Primitive::RenderBoundingBox()
00104 {
00105     dBoundingBox b = GetBoundingBox();
00106     glDisable(GL_LIGHTING);
00107     glBegin(GL_LINES);
00108     glVertex3f(b.min.x,b.min.y,b.min.z);
00109     glVertex3f(b.max.x,b.min.y,b.min.z);
00110     glVertex3f(b.max.x,b.min.y,b.min.z);
00111     glVertex3f(b.max.x,b.max.y,b.min.z);
00112     glVertex3f(b.max.x,b.max.y,b.min.z);
00113     glVertex3f(b.min.x,b.max.y,b.min.z);
00114     glVertex3f(b.min.x,b.max.y,b.min.z);
00115     glVertex3f(b.min.x,b.min.y,b.min.z);
00116     glVertex3f(b.min.x,b.min.y,b.max.z);
00117     glVertex3f(b.max.x,b.min.y,b.max.z);
00118     glVertex3f(b.max.x,b.min.y,b.max.z);
00119     glVertex3f(b.max.x,b.max.y,b.max.z);
00120     glVertex3f(b.max.x,b.max.y,b.max.z);
00121     glVertex3f(b.min.x,b.max.y,b.max.z);
00122     glVertex3f(b.min.x,b.max.y,b.max.z);
00123     glVertex3f(b.min.x,b.min.y,b.max.z);
00124     glVertex3f(b.min.x,b.min.y,b.min.z);
00125     glVertex3f(b.min.x,b.min.y,b.max.z);
00126     glVertex3f(b.min.x,b.max.y,b.min.z);
00127     glVertex3f(b.min.x,b.max.y,b.max.z);
00128     glVertex3f(b.max.x,b.min.y,b.min.z);
00129     glVertex3f(b.max.x,b.min.y,b.max.z);
00130     glVertex3f(b.max.x,b.max.y,b.min.z);
00131     glVertex3f(b.max.x,b.max.y,b.max.z);
00132     glEnd();
00133     glEnable(GL_LIGHTING);
00134 }
00135 

Generated on Mon Feb 11 06:54:25 2008 for The Fluxus Renderer (libfluxus) by  doxygen 1.5.1