00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
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
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
00092
00093
00094
00095
00096
00097
00098
00099
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