SLProject  4.2.000
A platform independent 3D computer graphics framework for desktop OS, Android, iOS and online in web browsers
SLCoordAxis.cpp
Go to the documentation of this file.
1 /**
2  * \file SLCoordAxis.cpp
3  * \date June 2016
4  * \authors Marcus Hudritsch
5  * \copyright http://opensource.org/licenses/GPL-3.0
6  * \remarks Please use clangformat to format the code. See more code style on
7  * https://github.com/cpvrlab/SLProject4/wiki/SLProject-Coding-Style
8 */
9 
10 #include <SLCoordAxis.h>
11 
12 //-----------------------------------------------------------------------------
13 //! SLAxis::SLAxis ctor with the arrow dimensions
15  SLfloat arrowThickness,
16  SLfloat arrowHeadLenght,
17  SLfloat arrowHeadWidth) : SLMesh(assetMgr, "Coord-Axis Mesh")
18 {
19  _arrowThickness = arrowThickness;
20  _arrowHeadLength = arrowHeadLenght;
21  _arrowHeadWidth = arrowHeadWidth;
22  buildMesh();
23 }
24 //-----------------------------------------------------------------------------
25 //! SLCoordAxis::buildMesh fills in the underlying arrays from the SLMesh object
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  // Set one default material index
38  // In SLMesh::init this will be set automatically to SLMaterial::diffuseAttrib
39  mat(nullptr);
40 
41  SLushort i = 0, v1 = 0, v2 = 0, v3 = 0, v4 = 0;
42  SLfloat t = _arrowThickness * 0.5f;
44  SLfloat w = _arrowHeadWidth * 0.5f;
45 
46  // predefined normals
50 
51  // clang-format off
52  // arrow towards +x
53  P.push_back(SLVec3f( t, t, t)); C.push_back(r); v1=i; i++;
54  P.push_back(SLVec3f(1-h, t, t)); C.push_back(r); v2=i; i++;
55  P.push_back(SLVec3f(1-h, t,-t)); C.push_back(r); v3=i; i++;
56  P.push_back(SLVec3f( t, t,-t)); C.push_back(r); v4=i; i++;
57  I16.push_back(v1); I16.push_back(v2); I16.push_back(v3);
58  I16.push_back(v1); I16.push_back(v3); I16.push_back(v4);
59 
60  P.push_back(SLVec3f( t,-t, t)); C.push_back(r); v1=i; i++;
61  P.push_back(SLVec3f(1-h,-t, t)); C.push_back(r); v2=i; i++;
62  P.push_back(SLVec3f(1-h, t, t)); C.push_back(r); v3=i; i++;
63  P.push_back(SLVec3f( t, t, t)); C.push_back(r); v4=i; i++;
64  I16.push_back(v1); I16.push_back(v2); I16.push_back(v3);
65  I16.push_back(v1); I16.push_back(v3); I16.push_back(v4);
66 
67  P.push_back(SLVec3f( t,-t,-t)); C.push_back(r); v1=i; i++;
68  P.push_back(SLVec3f(1-h,-t,-t)); C.push_back(r); v2=i; i++;
69  P.push_back(SLVec3f(1-h,-t, t)); C.push_back(r); v3=i; i++;
70  P.push_back(SLVec3f( t,-t, t)); C.push_back(r); v4=i; i++;
71  I16.push_back(v1); I16.push_back(v2); I16.push_back(v3);
72  I16.push_back(v1); I16.push_back(v3); I16.push_back(v4);
73 
74  P.push_back(SLVec3f( t, t,-t)); C.push_back(r); v1=i; i++;
75  P.push_back(SLVec3f(1-h, t,-t)); C.push_back(r); v2=i; i++;
76  P.push_back(SLVec3f(1-h,-t,-t)); C.push_back(r); v3=i; i++;
77  P.push_back(SLVec3f( t,-t,-t)); C.push_back(r); v4=i; i++;
78  I16.push_back(v1); I16.push_back(v2); I16.push_back(v3);
79  I16.push_back(v1); I16.push_back(v3); I16.push_back(v4);
80 
81  P.push_back(SLVec3f(1-h, w, w)); C.push_back(r); v1=i; i++;
82  P.push_back(SLVec3f( 1, 0, 0)); C.push_back(r); v2=i; i++;
83  P.push_back(SLVec3f(1-h, w,-w)); C.push_back(r); v3=i; i++;
84  I16.push_back(v1); I16.push_back(v2); I16.push_back(v3);
85  P.push_back(SLVec3f(1-h, w, w)); C.push_back(r); v1=i; i++;
86  P.push_back(SLVec3f(1-h,-w, w)); C.push_back(r); v2=i; i++;
87  P.push_back(SLVec3f( 1, 0, 0)); C.push_back(r); v3=i; i++;
88  I16.push_back(v1); I16.push_back(v2); I16.push_back(v3);
89  P.push_back(SLVec3f(1-h,-w, w)); C.push_back(r); v1=i; i++;
90  P.push_back(SLVec3f(1-h,-w,-w)); C.push_back(r); v2=i; i++;
91  P.push_back(SLVec3f( 1, 0, 0)); C.push_back(r); v3=i; i++;
92  I16.push_back(v1); I16.push_back(v2); I16.push_back(v3);
93  P.push_back(SLVec3f(1-h,-w,-w)); C.push_back(r); v1=i; i++;
94  P.push_back(SLVec3f(1-h, w,-w)); C.push_back(r); v2=i; i++;
95  P.push_back(SLVec3f( 1, 0, 0)); C.push_back(r); v3=i; i++;
96  I16.push_back(v1); I16.push_back(v2); I16.push_back(v3);
97  P.push_back(SLVec3f(1-h, w, w)); C.push_back(r); v1=i; i++;
98  P.push_back(SLVec3f(1-h, w,-w)); C.push_back(r); v2=i; i++;
99  P.push_back(SLVec3f(1-h,-w,-w)); C.push_back(r); v3=i; i++;
100  P.push_back(SLVec3f(1-h,-w, w)); C.push_back(r); v4=i; i++;
101  I16.push_back(v1); I16.push_back(v2); I16.push_back(v3);
102  I16.push_back(v1); I16.push_back(v3); I16.push_back(v4);
103 
104  P.push_back(SLVec3f( -t, t, t)); C.push_back(r); v1=i; i++;
105  P.push_back(SLVec3f( -t, t,-t)); C.push_back(r); v2=i; i++;
106  P.push_back(SLVec3f( -t,-t,-t)); C.push_back(r); v3=i; i++;
107  P.push_back(SLVec3f( -t,-t, t)); C.push_back(r); v4=i; i++;
108  I16.push_back(v1); I16.push_back(v2); I16.push_back(v3);
109  I16.push_back(v1); I16.push_back(v3); I16.push_back(v4);
110 
111  // arrow towards +y
112  P.push_back(SLVec3f( t, t, t)); C.push_back(g); v1=i; i++;
113  P.push_back(SLVec3f( t,1-h, t)); C.push_back(g); v2=i; i++;
114  P.push_back(SLVec3f( t,1-h,-t)); C.push_back(g); v3=i; i++;
115  P.push_back(SLVec3f( t, t,-t)); C.push_back(g); v4=i; i++;
116  I16.push_back(v1); I16.push_back(v3); I16.push_back(v2);
117  I16.push_back(v1); I16.push_back(v4); I16.push_back(v3);
118 
119  P.push_back(SLVec3f(-t, t, t)); C.push_back(g); v1=i; i++;
120  P.push_back(SLVec3f(-t,1-h, t)); C.push_back(g); v2=i; i++;
121  P.push_back(SLVec3f( t,1-h, t)); C.push_back(g); v3=i; i++;
122  P.push_back(SLVec3f( t, t, t)); C.push_back(g); v4=i; i++;
123  I16.push_back(v1); I16.push_back(v3); I16.push_back(v2);
124  I16.push_back(v1); I16.push_back(v4); I16.push_back(v3);
125 
126  P.push_back(SLVec3f(-t, t,-t)); C.push_back(g); v1=i; i++;
127  P.push_back(SLVec3f(-t,1-h,-t)); C.push_back(g); v2=i; i++;
128  P.push_back(SLVec3f(-t,1-h, t)); C.push_back(g); v3=i; i++;
129  P.push_back(SLVec3f(-t, t, t)); C.push_back(g); v4=i; i++;
130  I16.push_back(v1); I16.push_back(v3); I16.push_back(v2);
131  I16.push_back(v1); I16.push_back(v4); I16.push_back(v3);
132 
133  P.push_back(SLVec3f( t, t,-t)); C.push_back(g); v1=i; i++;
134  P.push_back(SLVec3f( t,1-h,-t)); C.push_back(g); v2=i; i++;
135  P.push_back(SLVec3f(-t,1-h,-t)); C.push_back(g); v3=i; i++;
136  P.push_back(SLVec3f(-t, t,-t)); C.push_back(g); v4=i; i++;
137  I16.push_back(v1); I16.push_back(v3); I16.push_back(v2);
138  I16.push_back(v1); I16.push_back(v4); I16.push_back(v3);
139 
140  P.push_back(SLVec3f( w,1-h, w)); C.push_back(g); v1=i; i++;
141  P.push_back(SLVec3f( 0, 1, 0)); C.push_back(g); v2=i; i++;
142  P.push_back(SLVec3f( w,1-h,-w)); C.push_back(g); v3=i; i++;
143  I16.push_back(v1); I16.push_back(v3); I16.push_back(v2);
144 
145  P.push_back(SLVec3f( w,1-h, w)); C.push_back(g); v1=i; i++;
146  P.push_back(SLVec3f(-w,1-h, w)); C.push_back(g); v2=i; i++;
147  P.push_back(SLVec3f( 0, 1, 0)); C.push_back(g); v3=i; i++;
148  I16.push_back(v1); I16.push_back(v3); I16.push_back(v2);
149  P.push_back(SLVec3f(-w,1-h, w)); C.push_back(g); v1=i; i++;
150  P.push_back(SLVec3f(-w,1-h,-w)); C.push_back(g); v2=i; i++;
151  P.push_back(SLVec3f( 0, 1, 0)); C.push_back(g); v3=i; i++;
152  I16.push_back(v1); I16.push_back(v3); I16.push_back(v2);
153 
154  P.push_back(SLVec3f(-w,1-h,-w)); C.push_back(g); v1=i; i++;
155  P.push_back(SLVec3f( w,1-h,-w)); C.push_back(g); v2=i; i++;
156  P.push_back(SLVec3f( 0, 1, 0)); C.push_back(g); v3=i; i++;
157  I16.push_back(v1); I16.push_back(v3); I16.push_back(v2);
158 
159  P.push_back(SLVec3f( w,1-h, w)); C.push_back(g); v1=i; i++;
160  P.push_back(SLVec3f( w,1-h,-w)); C.push_back(g); v2=i; i++;
161  P.push_back(SLVec3f(-w,1-h,-w)); C.push_back(g); v3=i; i++;
162  P.push_back(SLVec3f(-w,1-h, w)); C.push_back(g); v4=i; i++;
163  I16.push_back(v1); I16.push_back(v3); I16.push_back(v2);
164  I16.push_back(v1); I16.push_back(v4); I16.push_back(v3);
165 
166  P.push_back(SLVec3f( t, -t, t)); C.push_back(g); v1=i; i++;
167  P.push_back(SLVec3f( t, -t,-t)); C.push_back(g); v2=i; i++;
168  P.push_back(SLVec3f(-t, -t,-t)); C.push_back(g); v3=i; i++;
169  P.push_back(SLVec3f(-t, -t, t)); C.push_back(g); v4=i; i++;
170  I16.push_back(v1); I16.push_back(v3); I16.push_back(v2);
171  I16.push_back(v1); I16.push_back(v4); I16.push_back(v3);
172 
173  // arrow towards +z
174  P.push_back(SLVec3f( t, t, t)); C.push_back(b); v1=i; i++;
175  P.push_back(SLVec3f( t, t,1-h)); C.push_back(b); v2=i; i++;
176  P.push_back(SLVec3f( t,-t,1-h)); C.push_back(b); v3=i; i++;
177  P.push_back(SLVec3f( t,-t, t)); C.push_back(b); v4=i; i++;
178  I16.push_back(v1); I16.push_back(v2); I16.push_back(v3);
179  I16.push_back(v1); I16.push_back(v3); I16.push_back(v4);
180 
181  P.push_back(SLVec3f(-t, t, t)); C.push_back(b); v1=i; i++;
182  P.push_back(SLVec3f(-t, t,1-h)); C.push_back(b); v2=i; i++;
183  P.push_back(SLVec3f( t, t,1-h)); C.push_back(b); v3=i; i++;
184  P.push_back(SLVec3f( t, t, t)); C.push_back(b); v4=i; i++;
185  I16.push_back(v1); I16.push_back(v2); I16.push_back(v3);
186  I16.push_back(v1); I16.push_back(v3); I16.push_back(v4);
187 
188  P.push_back(SLVec3f(-t,-t, t)); C.push_back(b); v1=i; i++;
189  P.push_back(SLVec3f(-t,-t,1-h)); C.push_back(b); v2=i; i++;
190  P.push_back(SLVec3f(-t, t,1-h)); C.push_back(b); v3=i; i++;
191  P.push_back(SLVec3f(-t, t, t)); C.push_back(b); v4=i; i++;
192  I16.push_back(v1); I16.push_back(v2); I16.push_back(v3);
193  I16.push_back(v1); I16.push_back(v3); I16.push_back(v4);
194 
195  P.push_back(SLVec3f( t,-t, t)); C.push_back(b); v1=i; i++;
196  P.push_back(SLVec3f( t,-t,1-h)); C.push_back(b); v2=i; i++;
197  P.push_back(SLVec3f(-t,-t,1-h)); C.push_back(b); v3=i; i++;
198  P.push_back(SLVec3f(-t,-t, t)); C.push_back(b); v4=i; i++;
199  I16.push_back(v1); I16.push_back(v2); I16.push_back(v3);
200  I16.push_back(v1); I16.push_back(v3); I16.push_back(v4);
201 
202  P.push_back(SLVec3f( w, w,1-h)); C.push_back(b); v1=i; i++;
203  P.push_back(SLVec3f( 0, 0, 1)); C.push_back(b); v2=i; i++;
204  P.push_back(SLVec3f( w,-w,1-h)); C.push_back(b); v3=i; i++;
205  I16.push_back(v1); I16.push_back(v2); I16.push_back(v3);
206  P.push_back(SLVec3f( w, w,1-h)); C.push_back(b); v1=i; i++;
207  P.push_back(SLVec3f(-w, w,1-h)); C.push_back(b); v2=i; i++;
208  P.push_back(SLVec3f( 0, 0, 1)); C.push_back(b); v3=i; i++;
209  I16.push_back(v1); I16.push_back(v2); I16.push_back(v3);
210 
211  P.push_back(SLVec3f(-w, w,1-h)); C.push_back(b); v1=i; i++;
212  P.push_back(SLVec3f(-w,-w,1-h)); C.push_back(b); v2=i; i++;
213  P.push_back(SLVec3f( 0, 0, 1)); C.push_back(b); v3=i; i++;
214  I16.push_back(v1); I16.push_back(v2); I16.push_back(v3);
215  P.push_back(SLVec3f(-w,-w,1-h)); C.push_back(b); v1=i; i++;
216  P.push_back(SLVec3f( w,-w,1-h)); C.push_back(b); v2=i; i++;
217  P.push_back(SLVec3f( 0, 0, 1)); C.push_back(b); v3=i; i++;
218  I16.push_back(v1); I16.push_back(v2); I16.push_back(v3);
219 
220  P.push_back(SLVec3f( w, w,1-h)); C.push_back(b); v1=i; i++;
221  P.push_back(SLVec3f( w,-w,1-h)); C.push_back(b); v2=i; i++;
222  P.push_back(SLVec3f(-w,-w,1-h)); C.push_back(b); v3=i; i++;
223  P.push_back(SLVec3f(-w, w,1-h)); C.push_back(b); v4=i; i++;
224  I16.push_back(v1); I16.push_back(v2); I16.push_back(v3);
225  I16.push_back(v1); I16.push_back(v3); I16.push_back(v4);
226 
227  P.push_back(SLVec3f( t, t, -t)); C.push_back(b); v1=i; i++;
228  P.push_back(SLVec3f( t,-t, -t)); C.push_back(b); v2=i; i++;
229  P.push_back(SLVec3f(-t,-t, -t)); C.push_back(b); v3=i; i++;
230  P.push_back(SLVec3f(-t, t, -t)); C.push_back(b); v4=i; i++;
231  I16.push_back(v1); I16.push_back(v2); I16.push_back(v3);
232  I16.push_back(v1); I16.push_back(v3); I16.push_back(v4);
233 }
234 //-----------------------------------------------------------------------------
235 
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.
SLfloat _arrowThickness
Thickness of the arrow.
Definition: SLCoordAxis.h:41
SLCoordAxis(SLAssetManager *assetMgr, SLfloat arrowThickness=0.05f, SLfloat arrowHeadLenght=0.2f, SLfloat arrowHeadWidth=0.1f)
SLAxis::SLAxis ctor with the arrow dimensions.
Definition: SLCoordAxis.cpp:14
void buildMesh()
SLCoordAxis::buildMesh fills in the underlying arrays from the SLMesh object.
Definition: SLCoordAxis.cpp:26
SLfloat _arrowHeadLength
Lenght of the arrow head.
Definition: SLCoordAxis.h:42
SLfloat _arrowHeadWidth
Width of the arrow head.
Definition: SLCoordAxis.h:43
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
static SLVec4 GREEN
Definition: SLVec4.h:217
static SLVec4 RED
Definition: SLVec4.h:216
static SLVec4 BLUE
Definition: SLVec4.h:218
V3 v3(float x, float y, float z)
Definition: WAIMath.h:38