glc_line.cpp

Go to the documentation of this file.
00001 /****************************************************************************
00002 
00003  This file is part of the GLC-lib library.
00004  Copyright (C) 2005-2008 Laurent Ribon (laumaya@users.sourceforge.net)
00005  http://glc-lib.sourceforge.net
00006 
00007  GLC-lib is free software; you can redistribute it and/or modify
00008  it under the terms of the GNU Lesser General Public License as published by
00009  the Free Software Foundation; either version 3 of the License, or
00010  (at your option) any later version.
00011 
00012  GLC-lib is distributed in the hope that it will be useful,
00013  but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  GNU Lesser General Public License for more details.
00016 
00017  You should have received a copy of the GNU Lesser General Public License
00018  along with GLC-lib; if not, write to the Free Software
00019  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00020 
00021  *****************************************************************************/
00022 
00023 #include "glc_line.h"
00024 #include "../glc_openglexception.h"
00025 
00027 // Constructor Destructor
00029 
00030 GLC_Line::GLC_Line(const GLC_Point3d & point1, const GLC_Point3d & point2)
00031 : GLC_Geometry("Line", true)
00032 , m_Point1(point1)
00033 , m_Point2(point2)
00034 {
00035 
00036 }
00037 
00038 GLC_Line::GLC_Line(const GLC_Line& line)
00039 : GLC_Geometry(line)
00040 , m_Point1(line.m_Point1)
00041 , m_Point2(line.m_Point2)
00042 {
00043 
00044 }
00045 
00046 GLC_Line::~GLC_Line()
00047 {
00048 
00049 }
00050 
00052 // Get Functions
00054 
00055 const GLC_BoundingBox& GLC_Line::boundingBox(void)
00056 {
00057 
00058         if (NULL == m_pBoundingBox)
00059         {
00060                 m_pBoundingBox= new GLC_BoundingBox();
00061 
00062                 m_pBoundingBox->combine(m_Point1);
00063                 m_pBoundingBox->combine(m_Point2);
00064         }
00065         return *m_pBoundingBox;
00066 }
00067 
00068 GLC_Geometry* GLC_Line::clone() const
00069 {
00070         return new GLC_Line(*this);
00071 }
00072 
00073 
00075 // Set Functions
00077 void GLC_Line::setColor(const QColor& color)
00078 {
00079         m_WireColor= color;
00080         if (GLC_Geometry::hasMaterial())
00081         {
00082                 GLC_Geometry::firstMaterial()->setDiffuseColor(color);
00083         }
00084 }
00086 // OpenGL Functions
00088 
00089 void GLC_Line::glDraw(const GLC_RenderProperties&)
00090 {
00091         // Point Display
00092         glBegin(GL_LINES);
00093                 glVertex3dv(m_Point1.data());
00094                 glVertex3dv(m_Point2.data());
00095         glEnd();
00096 
00097         // OpenGL error handler
00098         GLenum error= glGetError();
00099         if (error != GL_NO_ERROR)
00100         {
00101                 GLC_OpenGlException OpenGlException("GLC_Line::GlDraw ", error);
00102                 throw(OpenGlException);
00103         }
00104 }
00105 

SourceForge.net Logo

©2005-2011 Laurent Ribon