glc_box.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00026
00027 #include "glc_box.h"
00028 #include "../glc_openglexception.h"
00029 #include "../glc_state.h"
00030
00032
00034
00035 GLC_Box::GLC_Box(double dLx, double dLy, double dlz)
00036 :GLC_Mesh()
00037 , m_dLgX(dLx)
00038 , m_dLgY(dLy)
00039 , m_dLgZ(dlz)
00040 {
00041
00042 }
00043
00044 GLC_Box::GLC_Box(const GLC_Box& box)
00045 :GLC_Mesh(box)
00046 , m_dLgX(box.m_dLgX)
00047 , m_dLgY(box.m_dLgY)
00048 , m_dLgZ(box.m_dLgZ)
00049 {
00050
00051 }
00052 GLC_Box::~GLC_Box()
00053 {
00054
00055 }
00056
00058
00060
00061
00062 const GLC_BoundingBox& GLC_Box::boundingBox(void)
00063 {
00064 if (GLC_Mesh::isEmpty())
00065 {
00066 createMeshAndWire();
00067 }
00068 return GLC_Mesh::boundingBox();
00069 }
00070
00071
00072 GLC_Geometry* GLC_Box::clone() const
00073 {
00074 return new GLC_Box(*this);
00075 }
00076
00077
00079
00081
00082
00083 void GLC_Box::setLgX(double LgX)
00084 {
00085 Q_ASSERT(LgX > 0);
00086 m_dLgX= LgX;
00087
00088 GLC_Mesh::clearMeshWireAndBoundingBox();
00089 }
00090
00091
00092 void GLC_Box::setLgY(double LgY)
00093 {
00094 Q_ASSERT(LgY > 0);
00095 m_dLgY= LgY;
00096
00097 GLC_Mesh::clearMeshWireAndBoundingBox();
00098 }
00099
00100
00101 void GLC_Box::setLgZ(double LgZ)
00102 {
00103 Q_ASSERT(LgZ > 0);
00104 m_dLgZ= LgZ;
00105
00106 GLC_Mesh::clearMeshWireAndBoundingBox();
00107 }
00108
00110
00112
00113
00114 void GLC_Box::glDraw(const GLC_RenderProperties& renderProperties)
00115 {
00116 if (GLC_Mesh::isEmpty())
00117 {
00118 createMeshAndWire();
00119 }
00120
00121 GLC_Mesh::glDraw(renderProperties);
00122 }
00123
00124 void GLC_Box::createMeshAndWire()
00125 {
00126 Q_ASSERT(GLC_Mesh::isEmpty());
00127 createWire();
00128
00129 const GLfloat lgX= static_cast<const GLfloat>(m_dLgX / 2.0);
00130 const GLfloat lgY= static_cast<const GLfloat>(m_dLgY / 2.0);
00131 const GLfloat lgZ= static_cast<const GLfloat>(m_dLgZ / 2.0);
00132
00133 GLfloatVector verticeVector;
00134 GLfloatVector normalsVector;
00135 GLfloatVector texelVector;
00136
00137
00138 verticeVector << -lgX; verticeVector << -lgY; verticeVector << lgZ;
00139 normalsVector << 0.0f; normalsVector << 0.0f; normalsVector << 1.0f;
00140 texelVector << 0.0f; texelVector << 0.0f;
00141
00142 verticeVector << lgX; verticeVector << -lgY; verticeVector << lgZ;
00143 normalsVector << 0.0f; normalsVector << 0.0f; normalsVector << 1.0f;
00144 texelVector << 1.0f; texelVector << 0.0f;
00145
00146 verticeVector << lgX; verticeVector << lgY; verticeVector << lgZ;
00147 normalsVector << 0.0f; normalsVector << 0.0f; normalsVector << 1.0f;
00148 texelVector << 1.0f; texelVector << 1.0f;
00149
00150 verticeVector << -lgX; verticeVector << lgY; verticeVector << lgZ;
00151 normalsVector << 0.0f; normalsVector << 0.0f; normalsVector << 1.0f;
00152 texelVector << 0.0f; texelVector << 1.0f;
00153
00154
00155 verticeVector << lgX; verticeVector << -lgY; verticeVector << lgZ;
00156 normalsVector << 1.0f; normalsVector << 0.0f; normalsVector << 0.0f;
00157 texelVector << 0.0f; texelVector << 0.0f;
00158
00159 verticeVector << lgX; verticeVector << -lgY; verticeVector << -lgZ;
00160 normalsVector << 1.0f; normalsVector << 0.0f; normalsVector << 0.0f;
00161 texelVector << 1.0f; texelVector << 0.0f;
00162
00163 verticeVector << lgX; verticeVector << lgY; verticeVector << -lgZ;
00164 normalsVector << 1.0f; normalsVector << 0.0f; normalsVector << 0.0f;
00165 texelVector << 1.0f; texelVector << 1.0f;
00166
00167 verticeVector << lgX; verticeVector << lgY; verticeVector << lgZ;
00168 normalsVector << 1.0f; normalsVector << 0.0f; normalsVector << 0.0f;
00169 texelVector << 0.0f; texelVector << 1.0f;
00170
00171
00172 verticeVector << -lgX; verticeVector << -lgY; verticeVector << -lgZ;
00173 normalsVector << -1.0f; normalsVector << 0.0f; normalsVector << 0.0f;
00174 texelVector << 0.0f; texelVector << 0.0f;
00175
00176 verticeVector << -lgX; verticeVector << -lgY; verticeVector << lgZ;
00177 normalsVector << -1.0f; normalsVector << 0.0f; normalsVector << 0.0f;
00178 texelVector << 1.0f; texelVector << 0.0f;
00179
00180 verticeVector << -lgX; verticeVector << lgY; verticeVector << lgZ;
00181 normalsVector << -1.0f; normalsVector << 0.0f; normalsVector << 0.0f;
00182 texelVector << 1.0f; texelVector << 1.0f;
00183
00184 verticeVector << -lgX; verticeVector << lgY; verticeVector << -lgZ;
00185 normalsVector << -1.0f; normalsVector << 0.0f; normalsVector << 0.0f;
00186 texelVector << 0.0f; texelVector << 1.0f;
00187
00188
00189 verticeVector << lgX; verticeVector << -lgY; verticeVector << -lgZ;
00190 normalsVector << 0.0f; normalsVector << 0.0f; normalsVector << -1.0f;
00191 texelVector << 0.0f; texelVector << 0.0f;
00192
00193 verticeVector << -lgX; verticeVector << -lgY; verticeVector << -lgZ;
00194 normalsVector << 0.0f; normalsVector << 0.0f; normalsVector << -1.0f;
00195 texelVector << 1.0f; texelVector << 0.0f;
00196
00197 verticeVector << -lgX; verticeVector << lgY; verticeVector << -lgZ;
00198 normalsVector << 0.0f; normalsVector << 0.0f; normalsVector << -1.0f;
00199 texelVector << 1.0f; texelVector << 1.0f;
00200
00201 verticeVector << lgX; verticeVector << lgY; verticeVector << -lgZ;
00202 normalsVector << 0.0f; normalsVector << 0.0f; normalsVector << -1.0f;
00203 texelVector << 0.0f; texelVector << 1.0f;
00204
00205
00206 verticeVector << -lgX; verticeVector << lgY; verticeVector << lgZ;
00207 normalsVector << 0.0f; normalsVector << 1.0f; normalsVector << 0.0f;
00208 texelVector << 0.0f; texelVector << 0.0f;
00209
00210 verticeVector << lgX; verticeVector << lgY; verticeVector << lgZ;
00211 normalsVector << 0.0f; normalsVector << 1.0f; normalsVector << 0.0f;
00212 texelVector << 1.0f; texelVector << 0.0f;
00213
00214 verticeVector << lgX; verticeVector << lgY; verticeVector << -lgZ;
00215 normalsVector << 0.0f; normalsVector << 1.0f; normalsVector << 0.0f;
00216 texelVector << 1.0f; texelVector << 1.0f;
00217
00218 verticeVector << -lgX; verticeVector << lgY; verticeVector << -lgZ;
00219 normalsVector << 0.0f; normalsVector << 1.0f; normalsVector << 0.0f;
00220 texelVector << 0.0f; texelVector << 1.0f;
00221
00222
00223 verticeVector << -lgX; verticeVector << -lgY; verticeVector << -lgZ;
00224 normalsVector << 0.0f; normalsVector << -1.0f; normalsVector << 0.0f;
00225 texelVector << 0.0f; texelVector << 0.0f;
00226
00227 verticeVector << lgX; verticeVector << -lgY; verticeVector << -lgZ;
00228 normalsVector << 0.0f; normalsVector << -1.0f; normalsVector << 0.0f;
00229 texelVector << 1.0f; texelVector << 0.0f;
00230
00231 verticeVector << lgX; verticeVector << -lgY; verticeVector << lgZ;
00232 normalsVector << 0.0f; normalsVector << -1.0f; normalsVector << 0.0f;
00233 texelVector << 1.0f; texelVector << 1.0f;
00234
00235 verticeVector << -lgX; verticeVector << -lgY; verticeVector << lgZ;
00236 normalsVector << 0.0f; normalsVector << -1.0f; normalsVector << 0.0f;
00237 texelVector << 0.0f; texelVector << 1.0f;
00238
00239
00240 GLC_Mesh::addVertice(verticeVector);
00241 GLC_Mesh::addNormals(normalsVector);
00242 GLC_Mesh::addTexels(texelVector);
00243
00244
00245 GLC_Material* pMaterial;
00246 if (hasMaterial())
00247 {
00248 pMaterial= this->firstMaterial();
00249 }
00250 else
00251 {
00252 pMaterial= new GLC_Material();
00253 }
00254
00255 IndexList index;
00256
00257 index << 0 << 1 << 3 << 2;
00258 GLC_Mesh::addTrianglesStrip(pMaterial, index);
00259 index.clear();
00260
00261 index << 4 << 5 << 7 << 6;
00262 GLC_Mesh::addTrianglesStrip(pMaterial, index);
00263 index.clear();
00264
00265 index << 8 << 9 << 11 << 10;
00266 GLC_Mesh::addTrianglesStrip(pMaterial, index);
00267 index.clear();
00268
00269 index << 12 << 13 << 15 << 14;
00270 GLC_Mesh::addTrianglesStrip(pMaterial, index);
00271 index.clear();
00272
00273 index << 16 << 17 << 19 << 18;
00274 GLC_Mesh::addTrianglesStrip(pMaterial, index);
00275 index.clear();
00276
00277 index << 20 << 21 << 23 << 22;
00278 GLC_Mesh::addTrianglesStrip(pMaterial, index);
00279 index.clear();
00280
00281 GLC_Mesh::finish();
00282 }
00283
00284
00285 void GLC_Box::createWire()
00286 {
00287 Q_ASSERT(m_WireData.isEmpty());
00288
00289 const GLfloat lgX= static_cast<const GLfloat>(m_dLgX / 2.0);
00290 const GLfloat lgY= static_cast<const GLfloat>(m_dLgY / 2.0);
00291 const GLfloat lgZ= static_cast<const GLfloat>(m_dLgZ / 2.0);
00292
00293
00294 GLfloatVector floatVector;
00295 floatVector << lgX << lgY << lgZ;
00296 floatVector << lgX << lgY << -lgZ;
00297 floatVector << -lgX << lgY << -lgZ;
00298 floatVector << -lgX << lgY << lgZ;
00299 floatVector << lgX << lgY << lgZ;
00300 GLC_Geometry::addPolyline(floatVector);
00301 floatVector.clear();
00302
00303 floatVector << lgX << -lgY << lgZ;
00304 floatVector << lgX << -lgY << -lgZ;
00305 floatVector << -lgX << -lgY << -lgZ;
00306 floatVector << -lgX << -lgY << lgZ;
00307 floatVector << lgX << -lgY << lgZ;
00308 GLC_Geometry::addPolyline(floatVector);
00309 floatVector.clear();
00310
00311 floatVector << lgX << lgY << lgZ;
00312 floatVector << lgX << -lgY << lgZ;
00313 GLC_Geometry::addPolyline(floatVector);
00314 floatVector.clear();
00315
00316 floatVector << lgX << lgY << -lgZ;
00317 floatVector << lgX << -lgY << -lgZ;
00318 GLC_Geometry::addPolyline(floatVector);
00319 floatVector.clear();
00320
00321 floatVector << -lgX << lgY << -lgZ;
00322 floatVector << -lgX << -lgY << -lgZ;
00323 GLC_Geometry::addPolyline(floatVector);
00324 floatVector.clear();
00325
00326 floatVector << -lgX << lgY << lgZ;
00327 floatVector << -lgX << -lgY << lgZ;
00328 GLC_Geometry::addPolyline(floatVector);
00329 floatVector.clear();
00330 }
00331