LinePrimitive.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 "LinePrimitive.h"
00019 #include "State.h"
00020 
00021 using namespace Fluxus;
00022 
00023 LinePrimitive::LinePrimitive() 
00024 {   
00025     AddData("p",new TypedPData<dVector>);
00026     AddData("w",new TypedPData<float>);
00027     PDataDirty();
00028 }
00029 
00030 LinePrimitive::LinePrimitive(const LinePrimitive &other) :
00031 Primitive(other) 
00032 {
00033     PDataDirty();
00034 }
00035 
00036 LinePrimitive::~LinePrimitive()
00037 {
00038 }
00039 
00040 LinePrimitive* LinePrimitive::Clone() const 
00041 {
00042     return new LinePrimitive(*this); 
00043 }
00044 
00045 void LinePrimitive::PDataDirty()
00046 {
00047     // reset pointers
00048     m_VertData=GetDataVec<dVector>("p");
00049     m_WidthData=GetDataVec<float>("w");
00050 }
00051 
00052 void LinePrimitive::Render()
00053 {
00054     if (m_VertData->size()<2) return;
00055     
00056     dMatrix ModelView;
00057     glGetFloatv(GL_MODELVIEW_MATRIX,ModelView.arr());
00058 
00059     if (m_State.Hints & HINT_UNLIT) glDisable(GL_LIGHTING);
00060     if (m_State.Hints & HINT_AALIAS) glEnable(GL_LINE_SMOOTH);      
00061     
00062     if (m_State.Hints & HINT_SOLID)
00063     {
00064         dVector CameraDir(0,0,1);
00065         CameraDir=ModelView.inverse().transform_no_trans(CameraDir);
00066         CameraDir.normalise();
00067 
00068         glBegin(GL_TRIANGLE_STRIP);
00069 
00070         for (unsigned int n=0; n<m_VertData->size()-1; n++)
00071         {
00072             float txstart = n/(float)m_VertData->size();
00073             float txend = (n+1)/(float)m_VertData->size();
00074         
00075             dVector line=(*m_VertData)[n+1]-(*m_VertData)[n];
00076             dVector up=line.cross(CameraDir);
00077             up.normalise();
00078 
00079             dVector topnorm=up;
00080             dVector botnorm=-up;
00081 
00082             glTexCoord2f(txstart,0);
00083             glNormal3fv(botnorm.arr());
00084             glVertex3fv(((*m_VertData)[n]-(up*(*m_WidthData)[n])).arr());
00085             glTexCoord2f(txstart,1);
00086             glNormal3fv(topnorm.arr());
00087             glVertex3fv(((*m_VertData)[n]+(up*(*m_WidthData)[n])).arr());
00088             glTexCoord2f(txend,0);
00089             glNormal3fv(botnorm.arr());
00090             glVertex3fv(((*m_VertData)[n+1]-(up*(*m_WidthData)[n+1])).arr());
00091             glTexCoord2f(txend,1);
00092             glNormal3fv(topnorm.arr());
00093             glVertex3fv(((*m_VertData)[n+1]+(up*(*m_WidthData)[n+1])).arr());
00094         }
00095         glEnd();
00096 
00097     }
00098     
00099     if (m_State.Hints & HINT_WIRE)
00100     {
00101         glBegin(GL_LINE_STRIP);
00102         for (unsigned int n=0; n<m_VertData->size()-1; n++)
00103         {
00104             float txstart = n/(float)m_VertData->size();
00105             float txend = (n+1)/(float)m_VertData->size();
00106             glTexCoord2f(txstart,0);
00107             glVertex3fv((*m_VertData)[n].arr());
00108             glTexCoord2f(txend,0);
00109             glVertex3fv((*m_VertData)[n+1].arr());
00110         }
00111         glEnd();
00112     }
00113     
00114     if (m_State.Hints & HINT_AALIAS) glDisable(GL_LINE_SMOOTH);     
00115     if (m_State.Hints & HINT_UNLIT) glEnable(GL_LIGHTING);
00116 }
00117 
00118 dBoundingBox LinePrimitive::GetBoundingBox()
00119 {
00120     dBoundingBox box;
00121     for (unsigned int n=0; n<m_VertData->size()-1; n++)
00122     {
00123         box.expand((*m_VertData)[n]);
00124     }
00125     return box;
00126 }
00127 
00128 void LinePrimitive::ApplyTransform(bool ScaleRotOnly)
00129 {
00130     if (!ScaleRotOnly)
00131     {
00132         for (vector<dVector>::iterator i=m_VertData->begin(); i!=m_VertData->end(); ++i)
00133         {
00134             *i=GetState()->Transform.transform(*i);
00135         }
00136     }
00137     else
00138     {
00139         for (vector<dVector>::iterator i=m_VertData->begin(); i!=m_VertData->end(); ++i)
00140         {
00141             *i=GetState()->Transform.transform_no_trans(*i);
00142         }
00143     }
00144     
00145     GetState()->Transform.init();
00146 }
00147 

Generated on Tue Sep 4 23:22:18 2007 for The Fluxus Renderer (libfluxus) by  doxygen 1.5.1