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 00018 // Generates a shadow volume poly primitive for the supplied 00019 // primitives and light position 00020 00021 // Can we accelerate the process by caching as much as possible, and 00022 // changing only when light positions/primitive transforms/deform? 00023 00024 #include "Primitive.h" 00025 #include "PolyPrimitive.h" 00026 #include "NURBSPrimitive.h" 00027 00028 #ifndef N_SHADOWGEN 00029 #define N_SHADOWGEN 00030 00031 namespace Fluxus 00032 { 00033 00041 class ShadowVolumeGen 00042 { 00043 public: 00044 ShadowVolumeGen(); 00045 ~ShadowVolumeGen(); 00046 00049 void SetLightPosition(dVector pos) { Clear(); m_LightPosition=pos; } 00050 00053 void Clear(); 00054 00057 void Generate(Primitive *prim); 00058 00060 PolyPrimitive *GetVolume(); 00061 00063 void SetLength(float s) { m_Length=s; } 00064 00067 void SetExpand(float s) { m_Expand=s; } 00068 00073 void SetDebug(bool s) { m_Debug=s; } 00074 bool GetDebug() { return m_Debug; } 00076 00077 private: 00078 00079 typedef pair<int,int> EdgeType; 00080 typedef vector<EdgeType> EdgeContainer; 00081 typedef vector<EdgeContainer> SharedEdgeContainer; 00082 00083 void PolyGen(PolyPrimitive *src); 00084 void NURBSGen(NURBSPrimitive *src); 00085 00086 void AddEdge(dVector start, dVector end); 00087 int FindNextEdge(unsigned int index, vector<pair<dVector,dVector> > &silhouette, bool &flip); 00088 00089 PolyPrimitive m_ShadowVolume; 00090 dVector m_LightPosition; 00091 float m_Length; 00092 float m_Expand; 00093 bool m_Debug; 00094 }; 00095 00096 }; 00097 00098 #endif