GLC_lib  2.5.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
glc_rectangle.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_rectangle.h"
26 #include "../glc_state.h"
27 
29 :GLC_Mesh()
30 , m_L1(1.0)
31 , m_L2(1.0)
32 {
33 
34 }
35 
36 GLC_Rectangle::GLC_Rectangle(double l1, double l2)
37 :GLC_Mesh()
38 , m_L1(l1)
39 , m_L2(l2)
40 {
41 
42 }
43 
45 :GLC_Mesh(rect)
46 , m_L1(rect.m_L1)
47 , m_L2(rect.m_L2)
48 {
49 
50 }
51 
52 
54 {
55 
56 }
58 // Get Functions
60 
62 {
63  return new GLC_Rectangle(*this);
64 }
65 
66 // return the rectangle bounding box
68 {
69  if (GLC_Mesh::isEmpty())
70  {
72  }
73  return GLC_Mesh::boundingBox();
74 }
75 
77 // Set Functions
79 
81 {
82  m_L1= l1;
83  m_L2= l2;
84 
86 
87  return *this;
88 }
89 
90 void GLC_Rectangle::setLength1(double value)
91 {
92  m_L1= value;
93 
95 }
96 
97 void GLC_Rectangle::setLength2(double value)
98 {
99  m_L2= value;
100 
102 }
103 
105 // Private OpenGL Functions
107 
108 void GLC_Rectangle::glDraw(const GLC_RenderProperties& renderProperties)
109 {
110  if (GLC_Mesh::isEmpty())
111  {
113  }
114 
115  GLC_Mesh::glDraw(renderProperties);
116 }
117 
119 // Private services Functions
121 
123 {
124  Q_ASSERT(GLC_Mesh::isEmpty());
125 
126  const GLfloat lgX= static_cast<const GLfloat>(m_L1 / 2.0);
127  const GLfloat lgY= static_cast<const GLfloat>(m_L2 / 2.0);
128 
129  GLfloatVector verticeVector;
130  GLfloatVector normalsVector;
132 
133  // the unique face of this rectangle
134  verticeVector << -lgX; verticeVector << -lgY; verticeVector << 0.0f;
135  normalsVector << 0.0f; normalsVector << 0.0f; normalsVector << 1.0f;
136  texelVector << 0.0f; texelVector << 0.0f;
137 
138  verticeVector << lgX; verticeVector << -lgY; verticeVector << 0.0f;
139  normalsVector << 0.0f; normalsVector << 0.0f; normalsVector << 1.0f;
140  texelVector << 1.0f; texelVector << 0.0f;
141 
142  verticeVector << lgX; verticeVector << lgY; verticeVector << 0.0f;
143  normalsVector << 0.0f; normalsVector << 0.0f; normalsVector << 1.0f;
144  texelVector << 1.0f; texelVector << 1.0f;
145 
146  verticeVector << -lgX; verticeVector << lgY; verticeVector << 0.0f;
147  normalsVector << 0.0f; normalsVector << 0.0f; normalsVector << 1.0f;
148  texelVector << 0.0f; texelVector << 1.0f;
149 
150  // Add bulk data in to the mesh
151  GLC_Mesh::addVertice(verticeVector);
152  GLC_Mesh::addNormals(normalsVector);
153  GLC_Mesh::addTexels(texelVector);
154 
155  // Add the first point of the rectangle for wire
156  verticeVector << -lgX; verticeVector << -lgY; verticeVector << 0.0f;
157  GLC_Geometry::addVerticeGroup(verticeVector);
158 
159  // Set the material to use
160  GLC_Material* pMaterial;
161  if (hasMaterial())
162  {
163  pMaterial= this->firstMaterial();
164  }
165  else
166  {
167  pMaterial= new GLC_Material();
168  }
169 
170  IndexList index;
171  // Face 1
172  index << 0 << 1 << 3 << 2;
173  GLC_Mesh::addTrianglesStrip(pMaterial, index);
174 
176 }
177 
178 

©2005-2013 Laurent Ribon