SLProject  4.2.000
A platform independent 3D computer graphics framework for desktop OS, Android, iOS and online in web browsers
SLLens.h
Go to the documentation of this file.
1 /**
2  * \file SLLens.h
3  * \date October 2014
4  * \authors Marcus Hudritsch
5  * \copyright http://opensource.org/licenses/GPL-3.0
6 */
7 
8 #ifndef SLLENS_H
9 #define SLLENS_H
10 
11 #include <SLRevolver.h>
12 
13 //-----------------------------------------------------------------------------
14 //! SLLens creates a lens mesh based on SLRevolver
15 /*!
16 SLLens creates a lens mesh based on SLRevolver.
17 Different constructors allow to either create the lens from the values
18 written in the eyeglass prescription card or from the radius of the lens.<br>
19 <br>
20 <b>Lens types:</b>
21 @image html images/LensTypes.png
22 <b>Myopia</b> ( http://en.wikipedia.org/wiki/Myopia )<br>
23 The eye is too long for its optical power.<br>
24 To correct myopic (short-sightedness) a diverging lens is needed.
25 @image html images/Myopia.png
26 <b>Hypermetropia</b> ( http://en.wikipedia.org/wiki/Hyperopia )<br>
27 The eye is too short for its optical power.<br>
28 To correct presbyopic (far-sightedness) a converging lens is needed.
29 @image html images/Hypermetropia.png
30 */
31 class SLLens : public SLRevolver
32 {
33 public:
34  //! Create a lens with given sphere, cylinder, diameter and thickness
35  SLLens(SLAssetManager* assetMgr,
36  double sphere,
37  double cylinder,
38  SLfloat diameter,
39  SLfloat thickness,
40  SLuint stacks = 32,
41  SLuint slices = 32,
42  SLstring name = "lens mesh",
43  SLMaterial* mat = nullptr);
44 
45  //! Create a lens with given radius, diameter and thickness
46  SLLens(SLAssetManager* assetMgr,
47  SLfloat radiusBot,
48  SLfloat radiusTop,
49  SLfloat diameter,
50  SLfloat thickness,
51  SLuint stacks = 32,
52  SLuint slices = 32,
53  SLstring name = "lens mesh",
54  SLMaterial* mat = nullptr);
55 
56 private:
57  void initLens(SLfloat diopterBot,
58  SLfloat diopterTop,
59  SLfloat diameter,
60  SLfloat thickness,
61  SLuint stacks,
62  SLuint slices,
63  SLMaterial* mat);
64  void generateLens(SLfloat radiusBot,
65  SLfloat radiusTop,
66  SLMaterial* mat);
69  SLfloat calcSagitta(SLfloat radius);
70 
71  SLfloat _diameter; //!< The diameter of the lens
72  SLfloat _thickness; //!< The space between the primary planes of lens sides
73  SLfloat _radiusBot; //!< The radius of the bot (front) side of the lens
74  SLfloat _radiusTop; //!< The radius of the top (back) side of the lens
75  SLbool _pointOutput; //!< debug helper
76 };
77 //-----------------------------------------------------------------------------
78 #endif // SLLENS_H
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
Toplevel holder of the assets meshes, materials, textures and shaders.
SLLens creates a lens mesh based on SLRevolver.
Definition: SLLens.h:32
void initLens(SLfloat diopterBot, SLfloat diopterTop, SLfloat diameter, SLfloat thickness, SLuint stacks, SLuint slices, SLMaterial *mat)
Initialize the lens.
Definition: SLLens.cpp:114
SLfloat _radiusTop
The radius of the top (back) side of the lens.
Definition: SLLens.h:74
SLfloat calcSagitta(SLfloat radius)
Calculate the sagitta (s) for a given radius (r) and diameter (l+l) where l is half of the lens diame...
Definition: SLLens.cpp:374
SLLens(SLAssetManager *assetMgr, double sphere, double cylinder, SLfloat diameter, SLfloat thickness, SLuint stacks=32, SLuint slices=32, SLstring name="lens mesh", SLMaterial *mat=nullptr)
Create a lens with given sphere, cylinder, diameter and thickness.
Definition: SLLens.cpp:45
SLfloat generateLensTop(SLfloat radius)
Generate the top (back) part of the lens.
Definition: SLLens.cpp:272
void generateLens(SLfloat radiusBot, SLfloat radiusTop, SLMaterial *mat)
Generate the lens with given front and back radius.
Definition: SLLens.cpp:155
SLbool _pointOutput
debug helper
Definition: SLLens.h:75
SLfloat _thickness
The space between the primary planes of lens sides.
Definition: SLLens.h:72
SLfloat _diameter
The diameter of the lens.
Definition: SLLens.h:71
SLfloat generateLensBot(SLfloat radius)
Generate the bottom (front) part of the lens.
Definition: SLLens.cpp:180
SLfloat _radiusBot
The radius of the bot (front) side of the lens.
Definition: SLLens.h:73
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
SLuint stacks()
Definition: SLRevolver.h:54
SLuint slices()
Definition: SLRevolver.h:55