SLProject  4.2.000
A platform independent 3D computer graphics framework for desktop OS, Android, iOS and online in web browsers
SLCylinder.cpp
Go to the documentation of this file.
1 /**
2  * \file SLCylinder.cpp
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 #include <SLCylinder.h>
11 
12 #include <utility>
13 
14 //-----------------------------------------------------------------------------
15 /*!
16 SLCylinder::SLCylinder ctor for cylindric revolution object around the z-axis.
17 */
19  SLfloat cylinderRadius,
20  SLfloat cylinderHeight,
21  SLuint stacks,
22  SLuint slices,
23  SLbool hasTop,
24  SLbool hasBottom,
25  SLstring name,
26  SLMaterial* mat) : SLRevolver(assetMgr, std::move(name))
27 {
28  assert(slices >= 3 && "Error: Not enough slices.");
29  assert(slices > 0 && "Error: Not enough stacks.");
30 
31  _radius = cylinderRadius;
32  _height = cylinderHeight;
33  _hasTop = hasTop;
35 
36  _stacks = stacks;
37  _slices = slices;
40  _revAxis.set(0, 0, 1);
41  SLuint nPoints = stacks + 1;
42  if (hasTop) nPoints += 2;
43  if (hasBottom) nPoints += 2;
44  _revPoints.reserve(nPoints);
45 
46  SLfloat dHeight = cylinderHeight / stacks;
47  SLfloat h = 0;
48 
49  if (hasBottom)
50  { // define double points for sharp edges
51  _revPoints.push_back(SLVec3f(0, 0, 0));
52  _revPoints.push_back(SLVec3f(cylinderRadius, 0, 0));
53  }
54 
55  for (SLuint i = 0; i <= stacks; ++i)
56  {
57  _revPoints.push_back(SLVec3f(cylinderRadius, 0, h));
58  h += dHeight;
59  }
60 
61  if (hasTop)
62  { // define double points for sharp edges
63  _revPoints.push_back(SLVec3f(cylinderRadius, 0, cylinderHeight));
64  _revPoints.push_back(SLVec3f(0, 0, cylinderHeight));
65  }
66 
67  buildMesh(mat);
68 }
69 //-----------------------------------------------------------------------------
float SLfloat
Definition: SL.h:173
unsigned int SLuint
Definition: SL.h:171
bool SLbool
Definition: SL.h:175
string SLstring
Definition: SL.h:158
SLVec3< SLfloat > SLVec3f
Definition: SLVec3.h:318
Toplevel holder of the assets meshes, materials, textures and shaders.
SLfloat _height
height of cylinder
Definition: SLCylinder.h:47
SLCylinder(SLAssetManager *assetMgr, SLfloat cylinderRadius, SLfloat cylinderHeight, SLuint stacks=1, SLuint slices=16, SLbool hasTop=true, SLbool hasBottom=true, SLstring name="cylinder mesh", SLMaterial *mat=nullptr)
Definition: SLCylinder.cpp:18
SLbool _hasBottom
Flag if cylinder has a bottom.
Definition: SLCylinder.h:49
SLbool hasTop()
Definition: SLCylinder.h:42
SLbool hasBottom()
Definition: SLCylinder.h:43
SLfloat _radius
radius of cylinder
Definition: SLCylinder.h:46
SLbool _hasTop
Flag if cylinder has a top.
Definition: SLCylinder.h:48
Defines a standard CG material with textures and a shader program.
Definition: SLMaterial.h:56
SLMaterial * mat() const
Definition: SLMesh.h:177
SLRevolver is an SLMesh object built out of revolving points.
Definition: SLRevolver.h:38
SLbool _smoothLast
flag if the normal of the last point is eqaual to revAxis
Definition: SLRevolver.h:67
SLVec3f _revAxis
axis of revolution
Definition: SLRevolver.h:59
SLuint stacks()
Definition: SLRevolver.h:54
SLuint slices()
Definition: SLRevolver.h:55
SLbool _smoothFirst
flag if the normal of the first point is eqaual to -revAxis
Definition: SLRevolver.h:64
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
SLuint _stacks
No. of stacks (mostly used)
Definition: SLRevolver.h:60
void set(const T X, const T Y, const T Z)
Definition: SLVec3.h:59