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

SourceForge.net Logo

©2005 Laurent Ribon