SLProject  4.2.000
A platform independent 3D computer graphics framework for desktop OS, Android, iOS and online in web browsers
SLArrow.h
Go to the documentation of this file.
1 /**
2  * \file SLArrow.h
3  * \date July 2014
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 #ifndef SLARROW_H
11 #define SLARROW_H
12 
13 #include <SLRevolver.h>
14 
15 //-----------------------------------------------------------------------------
16 /**
17  * @brief SLArrow is creates an arrow mesh based on its SLRevolver methods
18  * @remarks It is important that during instantiation NO OpenGL functions (gl*)
19  * get called because this constructor will be most probably called in a parallel
20  * thread from within an SLScene::registerAssetsToLoad or SLScene::assemble
21  * function. All objects that get rendered have to do their OpenGL initialization
22  * when they are used the first time during rendering in the main thread.
23  * For this SLMesh it means that the objects for OpenGL drawing (_vao, _vaoP,
24  * _vaoN, _vaoT and _vaoS) remain unused until the first frame is rendered.
25  */
26 class SLArrow : public SLRevolver
27 {
28 public:
30  SLfloat arrowCylinderRadius,
31  SLfloat length,
32  SLfloat headLength,
33  SLfloat headWidth,
34  SLuint slices,
35  const SLstring& name = "arrow mesh",
36  SLMaterial* mat = nullptr) : SLRevolver(assetMgr, name)
37  {
38  assert(slices >= 3 && "Error: Not enough slices.");
39  assert(headLength < length);
40  assert(headWidth > arrowCylinderRadius);
41 
42  _radius = arrowCylinderRadius;
43  _length = length;
44  _headLength = headLength;
45  _headWidth = headWidth;
46  _slices = slices;
47  _revAxis.set(0, 0, 1);
48 
49  // Add revolving polyline points with double points for sharp edges
50  _revPoints.reserve(8);
51  _revPoints.push_back(SLVec3f(0, 0, 0));
52  _revPoints.push_back(SLVec3f(_headWidth, 0, _headLength));
53  _revPoints.push_back(SLVec3f(_headWidth, 0, _headLength));
54  _revPoints.push_back(SLVec3f(_radius, 0, _headLength));
55  _revPoints.push_back(SLVec3f(_radius, 0, _headLength));
56  _revPoints.push_back(SLVec3f(_radius, 0, _length));
57  _revPoints.push_back(SLVec3f(_radius, 0, _length));
58  _revPoints.push_back(SLVec3f(0, 0, _length));
59 
60  buildMesh(mat);
61  }
62 
63 private:
64  SLfloat _radius; //!< radius of arrow cylinder
65  SLfloat _length; //!< length of arrow
66  SLfloat _headLength; //!< length of arrow head
67  SLfloat _headWidth; //!< width of arrow head
68 };
69 //-----------------------------------------------------------------------------
70 #endif // SLARROW_H
float SLfloat
Definition: SL.h:173
unsigned int SLuint
Definition: SL.h:171
string SLstring
Definition: SL.h:158
SLVec3< SLfloat > SLVec3f
Definition: SLVec3.h:318
SLArrow is creates an arrow mesh based on its SLRevolver methods.
Definition: SLArrow.h:27
SLfloat _radius
radius of arrow cylinder
Definition: SLArrow.h:64
SLArrow(SLAssetManager *assetMgr, SLfloat arrowCylinderRadius, SLfloat length, SLfloat headLength, SLfloat headWidth, SLuint slices, const SLstring &name="arrow mesh", SLMaterial *mat=nullptr)
Definition: SLArrow.h:29
SLfloat _length
length of arrow
Definition: SLArrow.h:65
SLfloat _headLength
length of arrow head
Definition: SLArrow.h:66
SLfloat _headWidth
width of arrow head
Definition: SLArrow.h:67
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
SLMaterial * mat() const
Definition: SLMesh.h:177
const SLstring & name() const
Definition: SLObject.h:38
SLRevolver is an SLMesh object built out of revolving points.
Definition: SLRevolver.h:38
SLVec3f _revAxis
axis of revolution
Definition: SLRevolver.h:59
SLuint slices()
Definition: SLRevolver.h:55
SLuint _slices
NO. of slices.
Definition: SLRevolver.h:61
void buildMesh(SLMaterial *mat=nullptr)
Definition: SLRevolver.cpp:43
SLVVec3f _revPoints
Array revolving points.
Definition: SLRevolver.h:58
void set(const T X, const T Y, const T Z)
Definition: SLVec3.h:59