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

SourceForge.net Logo

©2005 Laurent Ribon