SLProject  4.2.000
A platform independent 3D computer graphics framework for desktop OS, Android, iOS and online in web browsers
SLTriangle.cpp
Go to the documentation of this file.
1 /**
2  * \file SLTriangle.cpp
3  * \date July 2014
4  * \remarks Please use clangformat to format the code. See more code style on
5  * https://github.com/cpvrlab/SLProject4/wiki/SLProject-Coding-Style
6  * \authors Philipp Jueni, Marcus Hudritsch
7  * \copyright http://opensource.org/licenses/GPL-3.0
8 */
9 
10 #include <SLTriangle.h>
11 
12 //-----------------------------------------------------------------------------
14  SLMaterial* material,
15  const SLstring& name,
16  const SLVec3f& p0,
17  const SLVec3f& p1,
18  const SLVec3f& p2,
19  const SLVec2f& t0,
20  const SLVec2f& t1,
21  const SLVec2f& t2) : SLMesh(assetMgr, name)
22 {
23  p[0] = p0;
24  p[1] = p1;
25  p[2] = p2;
26 
27  t[0] = t0;
28  t[1] = t1;
29  t[2] = t2;
30 
31  mat(material);
32 
33  _isVolume = false;
34 
35  buildMesh(material);
36 }
37 //-----------------------------------------------------------------------------
38 //! Builds the mesh by copying the vertex info into the arrays of SLMescj
40 {
41  deleteData();
42 
43  P.clear();
44  P.resize(3); // Vector for positions
45  N.clear();
46  N.resize(P.size()); // Vector for vertex normals (opt.)
47  UV[0].clear();
48  UV[0].resize(P.size()); // Vector for vertex tex. coords. (opt.)
49  UV[1].clear();
50  I16.clear();
51  I16.resize(3); // Vector for vertex indices 16 bit
52 
53  // vertex positions
54  P[0] = p[0];
55  P[1] = p[1];
56  P[2] = p[2];
57 
58  // vertex texture coordinates
59  UV[0][0] = t[0];
60  UV[0][1] = t[1];
61  UV[0][2] = t[2];
62 
63  // indices
64  I16[0] = 0;
65  I16[1] = 1;
66  I16[2] = 2;
67 
68  // normals
69  SLVec3f n = (p[1] - p[0]) ^ (p[2] - p[0]);
70  n.normalize();
71  N[0] = n;
72  N[1] = n;
73  N[2] = n;
74 }
75 //-----------------------------------------------------------------------------
string SLstring
Definition: SL.h:158
Toplevel holder of the assets meshes, materials, textures and shaders.
Defines a standard CG material with textures and a shader program.
Definition: SLMaterial.h:56
An SLMesh object is a triangulated mesh, drawn with one draw call.
Definition: SLMesh.h:134
SLVushort I16
Vector of vertex indices 16 bit.
Definition: SLMesh.h:214
SLbool _isVolume
Flag for RT if mesh is a closed volume.
Definition: SLMesh.h:253
SLVVec3f N
Vector for vertex normals (opt.) layout (location = 1)
Definition: SLMesh.h:204
virtual void deleteData()
SLMesh::deleteData deletes all mesh data and vbo's.
Definition: SLMesh.cpp:88
SLVVec2f UV[2]
Array of 2 Vectors for tex. coords. (opt.) layout (location = 2)
Definition: SLMesh.h:205
SLVVec3f P
Vector for vertex positions layout (location = 0)
Definition: SLMesh.h:203
SLMaterial * mat() const
Definition: SLMesh.h:177
void buildMesh(SLMaterial *mat)
Builds the mesh by copying the vertex info into the arrays of SLMescj.
Definition: SLTriangle.cpp:39
SLTriangle(SLAssetManager *assetMgr, SLMaterial *mat, const SLstring &name="triangle mesh", const SLVec3f &p0=SLVec3f(0, 0, 0), const SLVec3f &p1=SLVec3f(1, 0, 0), const SLVec3f &p2=SLVec3f(0, 1, 0), const SLVec2f &t0=SLVec2f(0, 0), const SLVec2f &t1=SLVec2f(1, 0), const SLVec2f &t2=SLVec2f(0, 1))
Definition: SLTriangle.cpp:13
SLVec2f t[3]
Array of 3 vertex tex. coords. (opt.)
Definition: SLTriangle.h:43
SLVec3f p[3]
Array of 3 vertex positions.
Definition: SLTriangle.h:42
SLVec3 & normalize()
Definition: SLVec3.h:124