$search
00001 00002 #include <blort/TomGine/tgRenderModel.h> 00003 #include <blort/TomGine/tgShapeCreator.h> 00004 #include <GL/gl.h> 00005 00006 using namespace TomGine; 00007 00008 tgRenderModel::tgRenderModel(){ 00009 m_material.Random(); 00010 m_bsmodel = 0; 00011 } 00012 00013 tgRenderModel::tgRenderModel(const tgModel& model){ 00014 m_vertices = model.m_vertices; 00015 m_faces = model.m_faces; 00016 m_bsmodel = 0; 00017 m_material.Random(); 00018 } 00019 00020 tgRenderModel::~tgRenderModel(){ 00021 if(m_bsmodel) 00022 delete(m_bsmodel); 00023 } 00024 00025 void tgRenderModel::ApplyMaterial(){ 00026 glEnable(GL_LIGHTING); 00027 glMaterialfv(GL_FRONT,GL_AMBIENT,m_material.ambient); 00028 glMaterialfv(GL_FRONT,GL_DIFFUSE,m_material.diffuse); 00029 glMaterialfv(GL_FRONT,GL_SPECULAR,m_material.specular); 00030 glMaterialfv(GL_FRONT,GL_SHININESS,&m_material.shininess); 00031 glColor4f(m_material.color.x, m_material.color.y, m_material.color.z, m_material.color.w); 00032 } 00033 00034 void tgRenderModel::ApplyColor(){ 00035 glColor4f(m_material.color.x, m_material.color.y, m_material.color.z, m_material.color.w); 00036 } 00037 00038 00039 void tgRenderModel::DrawFaces(){ 00040 DrawFaces(true); 00041 } 00042 00043 void tgRenderModel::DrawFaces(bool lighting){ 00044 if(lighting){ 00045 ApplyMaterial(); 00046 }else{ 00047 glDisable(GL_LIGHTING); 00048 glColor4f(m_material.color.x, m_material.color.y, m_material.color.z, m_material.color.w); 00049 } 00050 00051 m_pose.Activate(); 00052 tgModel::DrawFaces(); 00053 m_pose.Deactivate(); 00054 } 00055 00056 void tgRenderModel::DrawNormals(float normal_length){ 00057 m_pose.Activate(); 00058 tgModel::DrawNormals(normal_length); 00059 m_pose.Deactivate(); 00060 } 00061 00062 void tgRenderModel::DrawBoundingSphere(){ 00063 if(!m_bsmodel){ 00064 m_bsmodel = new tgModel(); 00065 tgShapeCreator creator; 00066 creator.CreateSphere(*m_bsmodel, m_bs.radius, 2, ICOSAHEDRON); 00067 if(!m_bsmodel) 00068 return; 00069 }else{ 00070 00071 m_pose.Activate(); 00072 glPushMatrix(); 00073 glTranslatef(m_bs.center.x, m_bs.center.y, m_bs.center.z); 00074 m_bsmodel->DrawFaces(); 00075 glPopMatrix(); 00076 m_pose.Deactivate(); 00077 } 00078 }