SLProject  4.2.000
A platform independent 3D computer graphics framework for desktop OS, Android, iOS and online in web browsers
SLCone.cpp
Go to the documentation of this file.
1 /**
2  * \file SLCone.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 <SLCone.h>
11 
12 //-----------------------------------------------------------------------------
13 /*!
14 SLCone::SLCone ctor for conic revolution object around the z-axis
15 */
17  SLfloat coneRadius,
18  SLfloat coneHeight,
19  SLuint stacks,
20  SLuint slices,
21  SLbool hasBottom,
22  SLstring name,
23  SLMaterial* mat) : SLRevolver(assetMgr, name)
24 {
25  assert(slices >= 3 && "Error: Not enough slices.");
26  assert(slices > 0 && "Error: Not enough stacks.");
27 
28  _radius = coneRadius;
29  _height = coneHeight;
30  _stacks = stacks;
32 
33  _slices = slices;
35  _smoothLast = false;
36  _revAxis.set(0, 0, 1);
37  SLuint nPoints = stacks + 1;
38  if (hasBottom) nPoints += 2;
39  _revPoints.reserve(nPoints);
40 
41  SLfloat dHeight = coneHeight / stacks;
42  SLfloat h = 0;
43  SLfloat dRadius = coneRadius / stacks;
44  SLfloat r = coneRadius;
45 
46  if (hasBottom)
47  { // define double points for sharp edges
48  _revPoints.push_back(SLVec3f(0, 0, 0));
49  _revPoints.push_back(SLVec3f(coneRadius, 0, 0));
50  }
51  for (SLuint i = 0; i <= stacks; ++i)
52  {
53  _revPoints.push_back(SLVec3f(r, 0, h));
54  h += dHeight;
55  r -= dRadius;
56  }
57 
58  buildMesh(mat);
59 }
60 //-----------------------------------------------------------------------------
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.
SLbool hasBottom()
Definition: SLCone.h:41
SLCone(SLAssetManager *assetMgr, SLfloat coneRadius, SLfloat coneHeight, SLuint stacks=36, SLuint slices=36, SLbool hasBottom=true, SLstring name="cone mesh", SLMaterial *mat=nullptr)
Definition: SLCone.cpp:16
SLbool _hasBottom
Flag if cone has a bottom.
Definition: SLCone.h:46
SLfloat _height
height of cone
Definition: SLCone.h:45
SLfloat _radius
radius of cone
Definition: SLCone.h:44
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