-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathKleinBottle.cpp
More file actions
66 lines (51 loc) · 1.33 KB
/
Copy pathKleinBottle.cpp
File metadata and controls
66 lines (51 loc) · 1.33 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
#include "KleinBottle.h"
#include "Point.h"
#include <glm/gtc/constants.hpp>
#include <glm/vec3.hpp>
#include <glm/glm.hpp>
KleinBottle::KleinBottle(QOpenGLShaderProgram* prog, GLfloat radius, GLuint nSlices, GLuint nStacks) :
ParametricSurface(prog, nSlices, nStacks),
_radius(radius)
{
_name = "Klein Bottle";
buildMesh(nSlices, nStacks);
}
KleinBottle::~KleinBottle()
{
}
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;
}