-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathKleinBottle.cpp
More file actions
68 lines (55 loc) · 1.43 KB
/
KleinBottle.cpp
File metadata and controls
68 lines (55 loc) · 1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include "KleinBottle.h"
#include "Point.h"
#include <glm/gtc/constants.hpp>
#include <glm/vec3.hpp>
#include <glm/glm.hpp>
KleinBottle::KleinBottle(QOpenGLShaderProgram* prog, float radius, unsigned int nSlices, unsigned int nStacks, unsigned int sMax, unsigned int tMax) :
ParametricSurface(prog, nSlices, nStacks, sMax, tMax),
_radius(radius)
{
setAutoIncrName("Klein Bottle");
buildMesh();
}
KleinBottle::~KleinBottle()
{
}
TriangleMesh* KleinBottle::clone()
{
return new KleinBottle(_prog, _radius, _slices, _stacks, _sMax, _tMax);
}
float KleinBottle::firstUParameter() const
{
return 0.0;
}
float KleinBottle::lastUParameter() const
{
return glm::two_pi<float>();
}
float KleinBottle::firstVParameter() const
{
return 0.0;
}
float KleinBottle::lastVParameter() const
{
return glm::two_pi<float>();
}
Point KleinBottle::pointAtParameter(const float& u, const float& v)
{
Point P;
float x, y, z;
//http://paulbourke.net/geometry/toroidal/
// Klein Bottle
// Where u = 0 - 2PI and v = 0 - 2PI
float r = 4 * (1 - cos(u) / 2);
if (u >= 0 && u < glm::pi<float>())
x = -_radius / 6 * (6 * cos(u) * (1 + sin(u)) + r * cos(u) * cos(v));
else
x = -_radius / 6 * (6 * cos(u) * (1 + sin(u)) + r * cos(v + glm::pi<float>()));
if (u >= 0 && u < glm::pi<float>())
z = -_radius / 6 * (16 * sin(u) + r * sin(u) * cos(v));
else
z = -_radius / 6 * (16 * sin(u));
y = -_radius / 6 * (r * sin(v));
P.setParam(x, y, z);
return P;
}