GLC_lib  2.5.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
glc_circle.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 
3  This file is part of the GLC-lib library.
4  Copyright (C) 2005-2008 Laurent Ribon (laumaya@users.sourceforge.net)
5  http://glc-lib.sourceforge.net
6 
7  GLC-lib is free software; you can redistribute it and/or modify
8  it under the terms of the GNU Lesser General Public License as published by
9  the Free Software Foundation; either version 3 of the License, or
10  (at your option) any later version.
11 
12  GLC-lib is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU Lesser General Public License for more details.
16 
17  You should have received a copy of the GNU Lesser General Public License
18  along with GLC-lib; if not, write to the Free Software
19  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 
21 *****************************************************************************/
22 
24 
25 #include "glc_circle.h"
26 #include "../glc_openglexception.h"
27 #include "../glc_state.h"
28 
29 using namespace glc;
31 // Constructor destructor
33 
34 GLC_Circle::GLC_Circle(const double &dRadius, double Angle)
35 :GLC_Geometry("Circle", true)
36 , m_Radius(dRadius)
37 , m_Discret(GLC_DISCRET)
38 , m_Angle(Angle)
39 , m_Step(0)
40 {
41 
42 }
43 
44 GLC_Circle::GLC_Circle(const GLC_Circle& sourceCircle)
45 :GLC_Geometry(sourceCircle)
46 , m_Radius(sourceCircle.m_Radius)
47 , m_Discret(sourceCircle.m_Discret)
48 , m_Angle(sourceCircle.m_Angle)
49 , m_Step(sourceCircle.m_Step)
50 {
51 
52 }
54 {
55 
56 }
58 // Get Functions
60 
61 // return the circle bounding box
63 {
64  if (NULL == m_pBoundingBox)
65  {
66  //qDebug() << "GLC_Mesh2::boundingBox create boundingBox";
68  if (m_WireData.isEmpty()) createWire();
71  }
72  return *m_pBoundingBox;
73 }
74 
75 // Return a copy of the current geometry
77 {
78  return new GLC_Circle(*this);
79 }
80 
82 // Set Functions
84 
85 // Set Circle diameter
87 {
88  Q_ASSERT(!qFuzzyCompare(D, 0.0));
89  setRadius(D / 2);
90 }
91 
92 // Set Circle Radius
93 void GLC_Circle::setRadius(double R)
94 {
95  Q_ASSERT(!qFuzzyCompare(R, 0.0));
96  if (!qFuzzyCompare(R - m_Radius, 0.0))
97  { // Radius is changing
98  m_Radius= R;
99 
101  }
102 }
103 
104 // Set Circle discret
105 void GLC_Circle::setDiscretion(int TargetDiscret)
106 {
107  Q_ASSERT(TargetDiscret > 0);
108  if (TargetDiscret != m_Discret)
109  {
110  m_Discret= TargetDiscret;
111  if (m_Discret < 6) m_Discret= 6;
112 
114  }
115 }
116 
117 // Set Circle Angle
118 void GLC_Circle::setAngle(double AngleRadians) // Angle in Radians
119 {
120  Q_ASSERT((!qFuzzyCompare(AngleRadians, 0.0)) && (AngleRadians < 2 * PI));
121  if (!qFuzzyCompare(AngleRadians - m_Angle, 0.0))
122  { // Angle is changing
123  m_Angle= AngleRadians;
124 
126  }
127 }
128 
130 // OpenGL Functions
132 
133 // Circle drawing
134 void GLC_Circle::glDraw(const GLC_RenderProperties& renderProperties)
135 {
136  if (m_WireData.isEmpty())
137  {
138  createWire();
139  }
140 
141  m_WireData.glDraw(renderProperties, GL_LINE_STRIP);
142 }
143 
144 // Create the wire
146 {
147  Q_ASSERT(m_WireData.isEmpty());
148 
149  m_Step= static_cast<GLuint>(static_cast<double>(m_Discret) * (m_Angle / (2 * glc::PI)));
150  if (m_Step < 2) m_Step= 2;
151 
152  // Float vector
153  GLfloatVector floatVector;
154 
155  // Resize the Vertex vector
156  const int size= (m_Step + 1) * 3;
157  floatVector.resize(size);
158  // Fill Vertex Vector
159  const double angleOnStep= m_Angle / static_cast<double>(m_Step);
160  for (GLuint i= 0; i <= m_Step; ++i)
161  {
162  floatVector[(i * 3)]= static_cast<float>(m_Radius * cos(static_cast<double>(i) * angleOnStep));
163  floatVector[(i * 3) + 1]= static_cast<float>(m_Radius * sin(static_cast<double>(i) * angleOnStep));
164  floatVector[(i * 3) + 2]= 0.0f;
165  }
166  GLC_Geometry::addVerticeGroup(floatVector);
167 }

©2005-2013 Laurent Ribon