SLProject  4.2.000
A platform independent 3D computer graphics framework for desktop OS, Android, iOS and online in web browsers
SLCoordAxisArrow.cpp
Go to the documentation of this file.
1 /**
2  * \file SLCoordAxisArrow.cpp
3  * \date April 2020
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 Jan Dellsperger, Marcus Hudritsch
7  * \copyright http://opensource.org/licenses/GPL-3.0
8 */
9 
10 #include <SLCoordAxisArrow.h>
11 
12 //-----------------------------------------------------------------------------
14  SLMaterial* material,
15  SLfloat arrowThickness,
16  SLfloat arrowHeadLenght,
17  SLfloat arrowHeadWidth)
18  : SLMesh(assetMgr, "Coord-Axis-Arrow Mesh")
19 {
20  _arrowThickness = arrowThickness;
21  _arrowHeadLength = arrowHeadLenght;
22  _arrowHeadWidth = arrowHeadWidth;
23  buildMesh(material);
24 }
25 //-----------------------------------------------------------------------------
27 {
28  // allocate new vectors of SLMesh
29  P.clear();
30  N.clear();
31  C.clear();
32  UV[0].clear();
33  UV[1].clear();
34  I16.clear();
35  I32.clear();
36 
37  mat(material);
38 
39  SLushort i = 0, v1 = 0, v2 = 0, v3 = 0, v4 = 0;
40  SLfloat t = _arrowThickness * 0.5f;
42  SLfloat w = _arrowHeadWidth * 0.5f;
43 
44  // clang-format off
45  P.push_back(SLVec3f( t, t, t)); v1=i; i++;
46  P.push_back(SLVec3f( t,1-h, t)); v2=i; i++;
47  P.push_back(SLVec3f( t,1-h,-t)); v3=i; i++;
48  P.push_back(SLVec3f( t, t,-t)); v4=i; i++;
49  I16.push_back(v1); I16.push_back(v3); I16.push_back(v2);
50  I16.push_back(v1); I16.push_back(v4); I16.push_back(v3);
51 
52  P.push_back(SLVec3f(-t, t, t)); v1=i; i++;
53  P.push_back(SLVec3f(-t,1-h, t)); v2=i; i++;
54  P.push_back(SLVec3f( t,1-h, t)); v3=i; i++;
55  P.push_back(SLVec3f( t, t, t)); v4=i; i++;
56  I16.push_back(v1); I16.push_back(v3); I16.push_back(v2);
57  I16.push_back(v1); I16.push_back(v4); I16.push_back(v3);
58 
59  P.push_back(SLVec3f(-t, t,-t)); v1=i; i++;
60  P.push_back(SLVec3f(-t,1-h,-t)); v2=i; i++;
61  P.push_back(SLVec3f(-t,1-h, t)); v3=i; i++;
62  P.push_back(SLVec3f(-t, t, t)); v4=i; i++;
63  I16.push_back(v1); I16.push_back(v3); I16.push_back(v2);
64  I16.push_back(v1); I16.push_back(v4); I16.push_back(v3);
65 
66  P.push_back(SLVec3f( t, t,-t)); v1=i; i++;
67  P.push_back(SLVec3f( t,1-h,-t)); v2=i; i++;
68  P.push_back(SLVec3f(-t,1-h,-t)); v3=i; i++;
69  P.push_back(SLVec3f(-t, t,-t)); v4=i; i++;
70  I16.push_back(v1); I16.push_back(v3); I16.push_back(v2);
71  I16.push_back(v1); I16.push_back(v4); I16.push_back(v3);
72 
73  P.push_back(SLVec3f( w,1-h, w)); v1=i; i++;
74  P.push_back(SLVec3f( 0, 1, 0)); v2=i; i++;
75  P.push_back(SLVec3f( w,1-h,-w)); v3=i; i++;
76  I16.push_back(v1); I16.push_back(v3); I16.push_back(v2);
77 
78  P.push_back(SLVec3f( w,1-h, w)); v1=i; i++;
79  P.push_back(SLVec3f(-w,1-h, w)); v2=i; i++;
80  P.push_back(SLVec3f( 0, 1, 0)); v3=i; i++;
81  I16.push_back(v1); I16.push_back(v3); I16.push_back(v2);
82  P.push_back(SLVec3f(-w,1-h, w)); v1=i; i++;
83  P.push_back(SLVec3f(-w,1-h,-w)); v2=i; i++;
84  P.push_back(SLVec3f( 0, 1, 0)); v3=i; i++;
85  I16.push_back(v1); I16.push_back(v3); I16.push_back(v2);
86 
87  P.push_back(SLVec3f(-w,1-h,-w)); v1=i; i++;
88  P.push_back(SLVec3f( w,1-h,-w)); v2=i; i++;
89  P.push_back(SLVec3f( 0, 1, 0)); v3=i; i++;
90  I16.push_back(v1); I16.push_back(v3); I16.push_back(v2);
91 
92  P.push_back(SLVec3f( w,1-h, w)); v1=i; i++;
93  P.push_back(SLVec3f( w,1-h,-w)); v2=i; i++;
94  P.push_back(SLVec3f(-w,1-h,-w)); v3=i; i++;
95  P.push_back(SLVec3f(-w,1-h, w)); v4=i; i++;
96  I16.push_back(v1); I16.push_back(v3); I16.push_back(v2);
97  I16.push_back(v1); I16.push_back(v4); I16.push_back(v3);
98 
99  P.push_back(SLVec3f( t, -t, t)); v1=i; i++;
100  P.push_back(SLVec3f( t, -t,-t)); v2=i; i++;
101  P.push_back(SLVec3f(-t, -t,-t)); v3=i; i++;
102  P.push_back(SLVec3f(-t, -t, t)); v4=i; i++;
103  I16.push_back(v1); I16.push_back(v3); I16.push_back(v2);
104  I16.push_back(v1); I16.push_back(v4); I16.push_back(v3);
105 }
106 //-----------------------------------------------------------------------------
float SLfloat
Definition: SL.h:173
unsigned short SLushort
Definition: SL.h:169
SLVec3< SLfloat > SLVec3f
Definition: SLVec3.h:318
Toplevel holder of the assets meshes, materials, textures and shaders.
void buildMesh(SLMaterial *material=nullptr)
SLfloat _arrowHeadWidth
Width of the arrow head.
SLfloat _arrowHeadLength
Lenght of the arrow head.
SLfloat _arrowThickness
Thickness of the arrow.
SLCoordAxisArrow(SLAssetManager *assetMgr, SLMaterial *material=nullptr, SLfloat arrowThickness=0.05f, SLfloat arrowHeadLenght=0.2f, SLfloat arrowHeadWidth=0.1f)
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
SLVuint I32
Vector of vertex indices 32 bit.
Definition: SLMesh.h:215
SLVushort I16
Vector of vertex indices 16 bit.
Definition: SLMesh.h:214
SLVCol4f C
Vector of vertex colors (opt.) layout (location = 4)
Definition: SLMesh.h:206
SLVVec3f N
Vector for vertex normals (opt.) layout (location = 1)
Definition: SLMesh.h:204
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
V3 v3(float x, float y, float z)
Definition: WAIMath.h:38