55 assert(
slices >= 3 &&
"Error: Not enough slices.");
56 assert(
slices > 0 &&
"Error: Not enough stacks.");
98 SLfloat diopterBot = (
SLfloat)((nLens - nOut) * diameter / radiusBot);
99 SLfloat diopterTop = (
SLfloat)((nOut - nLens) * diameter / radiusTop);
122 assert(
slices >= 3 &&
"Error: Not enough slices.");
123 assert(
slices > 0 &&
"Error: Not enough stacks.");
169 cout <<
"error in lens calculation: (x = " << x <<
")" << endl;
172 cout <<
"invalid lens diameter: " <<
_diameter << endl;
196 SLfloat dAlphaRAD = (alphaRAD * 0.5f) / halfStacks;
200 SLfloat radiusAmount1 = radius;
201 SLfloat yTranslate1 = radius - sagitta;
208 radiusAmount1 = -radius;
209 yTranslate1 = radius;
218 if (
_pointOutput) cout << currentAlphaDEG <<
" x: " << x <<
" y: " << y << endl;
221 for (
int i = 0; i < halfStacks; i++)
224 currentAlphaRAD += dAlphaRAD;
228 x = cos(currentAlphaRAD) * radiusAmount1;
231 if ((i + 1 == halfStacks) && (radius >= 0))
234 y = ((sin(currentAlphaRAD)) * radiusAmount1 + yTranslate1);
236 if (
_pointOutput) cout << currentAlphaDEG <<
" x: " << x <<
" y: " << y << endl;
250 for (
int i = 0; i <= halfStacks - 1; i++)
261 <<
" x: " << x <<
" y: " << y <<
" _B" << endl;
286 SLfloat radiusAmount2 = radius;
287 SLfloat yTranslate2 = -radius + sagitta;
290 betaAsin = (betaAsin > 1) ? 1 : betaAsin;
291 betaAsin = (betaAsin < -1) ? -1 : betaAsin;
300 radiusAmount2 = -radius;
301 yTranslate2 = -radius;
305 SLfloat dBetaRAD = (betaRAD * 0.5f) / halfStacks;
313 if (
_pointOutput) cout << currentBetaDEG <<
" x: " << x <<
" y: " << y << endl;
316 for (
int i = 0; i < halfStacks; i++)
319 currentBetaRAD += dBetaRAD;
323 y = (((sin(currentBetaRAD)) * (radiusAmount2)) + yTranslate2 +
_thickness);
326 if ((i + 1 == halfStacks))
333 x = cos(currentBetaRAD) * radiusAmount2;
335 if (
_pointOutput) cout << currentBetaDEG <<
" x: " << x <<
" y: " << y << endl;
349 for (
int i = halfStacks - 1; i >= 0; i--)
360 <<
" x: " << x <<
" y: " << y <<
" _T" << endl;
377 SLfloat radiusAmount = (radius < 0) ? -radius : radius;
382 SLfloat part = radiusAmount * radiusAmount - l * l;
385 SLfloat sagitta = (part >= 0) ? (radiusAmount - sqrt(part)) : -1;
float SLfloat
analog to GLfloat
unsigned int SLuint
analog to GLuint
string SLstring
Redefinition of standard types for platform independence.
Toplevel holder of the assets meshes, materials, textures and shaders.
void initLens(SLfloat diopterBot, SLfloat diopterTop, SLfloat diameter, SLfloat thickness, SLuint stacks, SLuint slices, SLMaterial *mat)
Initialize the lens.
SLfloat _radiusTop
The radius of the top (back) side of the lens.
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...
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.
SLfloat generateLensTop(SLfloat radius)
Generate the top (back) part of the lens.
void generateLens(SLfloat radiusBot, SLfloat radiusTop, SLMaterial *mat)
Generate the lens with given front and back radius.
SLbool _pointOutput
debug helper
SLfloat _thickness
The space between the primary planes of lens sides.
SLfloat _diameter
The diameter of the lens.
SLfloat generateLensBot(SLfloat radius)
Generate the bottom (front) part of the lens.
SLfloat _radiusBot
The radius of the bot (front) side of the lens.
Defines a standard CG material with textures and a shader program.
SLRevolver is an SLMesh object built out of revolving points.
SLbool _smoothLast
flag if the normal of the last point is eqaual to revAxis
SLVec3f _revAxis
axis of revolution
SLbool _smoothFirst
flag if the normal of the first point is eqaual to -revAxis
SLuint _slices
NO. of slices.
void buildMesh(SLMaterial *mat=nullptr)
SLVVec3f _revPoints
Array revolving points.
SLuint _stacks
No. of stacks (mostly used)
void set(const T X, const T Y, const T Z)
static const float HALFPI
T clamp(T a, T min, T max)
static const float RAD2DEG