Code_TYMPAN  4.4.0
Industrial site acoustic simulation
OGLRectangleMesh.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) <2012-2024> <EDF-DTG> <FRANCE>
3  * This file is part of Code_TYMPAN (R).
4  * Code_TYMPAN (R) is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  * Code_TYMPAN (R) is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11  * See the GNU General Public License for more details.
12  * You should have received a copy of the GNU General Public License along
13  * with Code_TYMPAN (R). If not, see <https://www.gnu.org/licenses/>.
14  */
15 
16 #include "OGLRectangleMesh.h"
17 #include "gui/tools/OGLMesh.h"
19 #include "models/common/3d.h"
20 #include <qsize.h>
21 #include <qvector3d.h>
22 
23 OGLRectangleMesh::OGLRectangleMesh(const QSizeF& dimensions)
24 {
26  _textureCoordinates = {{0, 0}, {1, 0}, {1, 1}, {0, 1}};
28  _normals = {{0, 0, 1}, {0, 0, 1}, {0, 0, 1}, {0, 0, 1}};
29  _indices = {0, 1, 2, 3};
30 }
31 
32 OGLRectangleMesh::OGLRectangleMesh(const std::array<std::array<double, 3>, 4>& verticesCoords)
33 {
34  setVertices(verticesCoords);
35  _textureCoordinates = {{0, 0}, {1, 0}, {1, 1}, {0, 1}};
37  _normals = {{0, 0, 1}, {0, 0, 1}, {0, 0, 1}, {0, 0, 1}};
38  _indices = {0, 1, 2, 3};
39 }
40 
41 void OGLRectangleMesh::setDimensions(const QSizeF& dimensions)
42 {
44  QSizeF halfSize = dimensions / 2;
45  float width = halfSize.width();
46  float height = halfSize.height();
47 
48  // 8 corners of the rectangle
49  _vertices = {
50  QVector3D(-width, -height, 0), // 0
51  QVector3D(width, -height, 0), // 1
52  QVector3D(width, height, 0), // 2
53  QVector3D(-width, height, 0), // 3
54  };
55 
57 }
58 
59 const QSizeF& OGLRectangleMesh::dimensions() const
60 {
61  return _dimensions;
62 }
63 
64 void OGLRectangleMesh::setVertices(const std::array<std::array<double, 3>, 4>& verticesCoords)
65 {
66  _vertices.clear();
67  for (const auto& v : verticesCoords)
68  {
69  _vertices.push_back(QVector3D(v[0], v[1], v[2]));
70  }
72 }
All base classes related to 3D manipulation.
std::vector< QVector3D > _vertices
Definition: OGLMesh.h:101
OGLPrivimitiveType _primitiveType
Definition: OGLMesh.h:107
std::vector< unsigned int > _indices
Definition: OGLMesh.h:105
std::vector< QVector3D > _normals
Definition: OGLMesh.h:103
std::vector< QVector2D > _textureCoordinates
Definition: OGLMesh.h:104
void recomputeBoundingBox()
Definition: OGLMesh.cpp:59
void setDimensions(const QSizeF &dimensions)
void setVertices(const std::array< std::array< double, 3 >, 4 > &verticesCoords)
Set vertices from coords.
const QSizeF & dimensions() const
OGLRectangleMesh(const QSizeF &dimensions)