ParticlePrimitive.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 "Renderer.h"
00018 #include "ParticlePrimitive.h"
00019 #include "State.h"
00020 
00021 using namespace Fluxus;
00022     
00023 ParticlePrimitive::ParticlePrimitive() 
00024 {
00025     AddData("p",new TypedPData<dVector>);
00026     AddData("c",new TypedPData<dColour>);
00027     AddData("s",new TypedPData<dVector>);
00028     
00029     // direct access for speed
00030     PDataDirty();
00031 }
00032 
00033 ParticlePrimitive::ParticlePrimitive(const ParticlePrimitive &other) :
00034 Primitive(other) 
00035 {
00036     PDataDirty();
00037 }
00038 
00039 ParticlePrimitive::~ParticlePrimitive()
00040 {
00041 }
00042 
00043 ParticlePrimitive* ParticlePrimitive::Clone() const 
00044 {
00045     return new ParticlePrimitive(*this); 
00046 }
00047 
00048 void ParticlePrimitive::PDataDirty()
00049 {   
00050     m_VertData=GetDataVec<dVector>("p");
00051     m_ColData=GetDataVec<dColour>("c");
00052     m_SizeData=GetDataVec<dVector>("s");
00053 }
00054 
00055 void ParticlePrimitive::Render()
00056 {
00057     glDisable(GL_LIGHTING);
00058     
00059     if (m_State.Hints & HINT_POINTS)
00060     {
00061         glDisableClientState(GL_NORMAL_ARRAY);
00062         glDisableClientState(GL_TEXTURE_COORD_ARRAY);
00063         glEnableClientState(GL_COLOR_ARRAY);
00064     
00065         glVertexPointer(3,GL_FLOAT,sizeof(dVector),(void*)m_VertData->begin()->arr());
00066         glColorPointer(4,GL_FLOAT,sizeof(dColour),(void*)m_ColData->begin()->arr());
00067     
00068         //glEnable(GL_BLEND);
00069         //glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
00070         //glHint(GL_POINT_SMOOTH_HINT,GL_NICEST);   
00071     
00072         if (m_State.Hints & HINT_AALIAS) glEnable(GL_POINT_SMOOTH); 
00073         else glDisable(GL_POINT_SMOOTH);    
00074 
00075         glDrawArrays(GL_POINTS,0,m_VertData->size());
00076 
00077         glDisableClientState(GL_COLOR_ARRAY);
00078         glEnableClientState(GL_NORMAL_ARRAY);
00079         glEnableClientState(GL_TEXTURE_COORD_ARRAY);
00080     }
00081     
00082     if (m_State.Hints & HINT_SOLID)
00083     {
00084         dMatrix ModelView;
00085         glGetFloatv(GL_MODELVIEW_MATRIX,ModelView.arr());
00086         ModelView = ModelView.inverse();
00087         
00088         dVector CameraDir(0,0,1);
00089         CameraDir=ModelView.transform_no_trans(CameraDir);
00090         CameraDir.normalise();
00091         
00092         dVector up(0,1,0);
00093         up = ModelView.transform(up);
00094         dVector across=up.cross(CameraDir);
00095         across.normalise();
00096         dVector down=across.cross(CameraDir);
00097         down.normalise();
00098         
00099         glBegin(GL_QUADS);
00100         for (unsigned int n=0; n<m_VertData->size(); n++)
00101         {
00102             dVector scaledacross(across*(*m_SizeData)[n].x*0.5);
00103             dVector scaledown(down*(*m_SizeData)[n].y*0.5);
00104             glColor3fv((*m_ColData)[n].arr());
00105             glTexCoord2f(0,0);
00106             glVertex3fv(((*m_VertData)[n]-scaledacross-scaledown).arr());
00107             glTexCoord2f(0,1);
00108             glVertex3fv(((*m_VertData)[n]-scaledacross+scaledown).arr());
00109             glTexCoord2f(1,1);
00110             glVertex3fv(((*m_VertData)[n]+scaledacross+scaledown).arr());
00111             glTexCoord2f(1,0);
00112             glVertex3fv(((*m_VertData)[n]+scaledacross-scaledown).arr());
00113         }
00114         glEnd();
00115     }
00116     glEnable(GL_LIGHTING);
00117 }
00118 
00119 dBoundingBox ParticlePrimitive::GetBoundingBox()
00120 {   
00121     dBoundingBox box;
00122     for (vector<dVector>::iterator i=m_VertData->begin(); i!=m_VertData->end(); ++i)
00123     {
00124         box.expand(*i);
00125     }
00126     return box;
00127 }
00128 
00129 void ParticlePrimitive::ApplyTransform(bool ScaleRotOnly)
00130 {
00131     if (!ScaleRotOnly)
00132     {
00133         for (vector<dVector>::iterator i=m_VertData->begin(); i!=m_VertData->end(); ++i)
00134         {
00135             *i=GetState()->Transform.transform(*i);
00136         }
00137     }
00138     else
00139     {
00140         for (vector<dVector>::iterator i=m_VertData->begin(); i!=m_VertData->end(); ++i)
00141         {
00142             *i=GetState()->Transform.transform_no_trans(*i);
00143         }
00144     }
00145     
00146     GetState()->Transform.init();
00147 }

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