SLProject  4.2.000
A platform independent 3D computer graphics framework for desktop OS, Android, iOS and online in web browsers
SLSpheric.cpp
Go to the documentation of this file.
1 /**
2  * \file SLSpheric.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 <SLSpheric.h>
11 
12 #include <utility>
13 
14 //-----------------------------------------------------------------------------
15 /*!
16 SLSpheric::SLSpheric ctor for spheric revolution object around the z-axis.
17 */
19  SLfloat sphereRadius,
20  SLfloat thetaStartDEG,
21  SLfloat thetaEndDEG,
22  SLuint stacks,
23  SLuint slices,
24  SLstring name,
25  SLMaterial* mat) : SLRevolver(assetMgr, std::move(name))
26 {
27  assert(slices >= 3 && "Error: Not enough slices.");
28  assert(slices > 0 && "Error: Not enough stacks.");
29  assert(thetaStartDEG >= 0.0f && thetaStartDEG < 180.0f &&
30  "Error: Polar start angle < 0 or > 180");
31  assert(thetaEndDEG > 0.0f && thetaEndDEG <= 180.0f &&
32  "Error: Polar end angle < 0 or > 180");
33  assert(thetaStartDEG < thetaEndDEG &&
34  "Error: Polar start angle > end angle");
35 
36  _radius = sphereRadius;
37  _thetaStartDEG = thetaStartDEG;
38  _thetaEndDEG = thetaEndDEG;
39 
40  _stacks = stacks;
41  _slices = slices;
42  _smoothFirst = (thetaStartDEG == 0.0f);
43  _smoothLast = (thetaEndDEG == 180.0f);
44  _isVolume = (thetaStartDEG == 0.0f && thetaEndDEG == 180.0f);
45  _revAxis.set(0, 0, 1);
46  _revPoints.reserve(stacks + 1);
47 
48  SLfloat theta = -Utils::PI + thetaStartDEG * Utils::DEG2RAD;
49  SLfloat phi = 0;
50  SLfloat dTheta = (thetaEndDEG - thetaStartDEG) * Utils::DEG2RAD / stacks;
51 
52  for (SLuint i = 0; i <= stacks; ++i)
53  {
54  SLVec3f p;
55  p.fromSpherical(sphereRadius, theta, phi);
56  _revPoints.push_back(p);
57  theta += dTheta;
58  }
59 
60  buildMesh(mat);
61 }
62 //-----------------------------------------------------------------------------
float SLfloat
Definition: SL.h:173
unsigned int SLuint
Definition: SL.h:171
string SLstring
Definition: SL.h:158
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
SLbool _isVolume
Flag for RT if mesh is a closed volume.
Definition: SLMesh.h:253
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
SLfloat _thetaStartDEG
Polar start angle 0-180deg.
Definition: SLSpheric.h:37
SLfloat _thetaEndDEG
Polar end angle 1-180deg.
Definition: SLSpheric.h:38
SLfloat _radius
radius of the sphere
Definition: SLSpheric.h:36
SLSpheric(SLAssetManager *assetMgr, SLfloat radius, SLfloat thetaStartDEG, SLfloat thetaEndDEG, SLuint stacks=32, SLuint slices=32, SLstring name="spheric mesh", SLMaterial *mat=nullptr)
Definition: SLSpheric.cpp:18
void set(const T X, const T Y, const T Z)
Definition: SLVec3.h:59
void fromSpherical(T r, T theta, T phi)
Calculates the vector from spherical coords r, theta & phi in radians.
Definition: SLVec3.h:185
static const float DEG2RAD
Definition: Utils.h:239
static const float PI
Definition: Utils.h:237