glc_point.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 
00024 
00025 #include "glc_point.h"
00026 #include "../glc_openglexception.h"
00027 
00028 using namespace glc;
00030 // Constructor Destructor
00032 
00033 
00034 GLC_Point::GLC_Point(const GLC_Point3d &setCoord)
00035 :GLC_Geometry("Point", true)
00036 , m_Coordinate(setCoord)
00037 , m_Size(1.0f)
00038 {
00039 
00040 }
00042 GLC_Point::GLC_Point(double x, double y, double z)
00043 :GLC_Geometry("Point", true)
00044 , m_Coordinate(x, y, z)
00045 , m_Size(1.0f)
00046 {
00047 }
00048 
00050 // Get Functions
00052 
00053 // Get a 4D point represent point coordinate
00054 GLC_Point3d GLC_Point::coordinate(void) const
00055 {
00056         return m_Coordinate;
00057 }
00058 
00059 // return the point bounding box
00060 const GLC_BoundingBox& GLC_Point::boundingBox(void)
00061 {
00062 
00063         if (NULL == m_pBoundingBox)
00064         {
00065                 m_pBoundingBox= new GLC_BoundingBox();
00066                 const double delta= 1e-2;
00067                 GLC_Point3d lower(m_Coordinate.x() - delta,
00068                                 m_Coordinate.y() - delta,
00069                                 m_Coordinate.z() - delta);
00070                 GLC_Point3d upper(m_Coordinate.x() + delta,
00071                                 m_Coordinate.y() + delta,
00072                                 m_Coordinate.z() + delta);
00073                 m_pBoundingBox->combine(lower);
00074                 m_pBoundingBox->combine(upper);
00075         }
00076         return *m_pBoundingBox;
00077 }
00078 
00079 // Return a copy of the current geometry
00080 GLC_Geometry* GLC_Point::clone() const
00081 {
00082         return new GLC_Point(*this);
00083 }
00084 
00086 // Set Functions
00088 
00089 // Set Point coordinate by 4D Vector
00090 void GLC_Point::setCoordinate(const GLC_Point3d &point)
00091 {
00092         m_Coordinate= point;
00093 }
00094 // Set Point coordinate by 3 double
00095 void GLC_Point::setCoordinate(double x, double y, double z)
00096 {
00097         m_Coordinate.setVect(x, y, z);
00098 }
00099 
00101 // OpenGL Functions
00103 
00104 void GLC_Point::glDraw(const GLC_RenderProperties&)
00105 {
00106         glPointSize(m_Size);
00107         // Point Display
00108         glBegin(GL_POINTS);
00109                 glVertex3dv(m_Coordinate.data());
00110         glEnd();
00111         glPointSize(1.0f);
00112 
00113         // OpenGL error handler
00114         GLenum error= glGetError();
00115         if (error != GL_NO_ERROR)
00116         {
00117                 GLC_OpenGlException OpenGlException("GLC_Point::GlDraw ", error);
00118                 throw(OpenGlException);
00119         }
00120 }
00121 

SourceForge.net Logo

©2005-2011 Laurent Ribon