-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSpring.cpp
More file actions
66 lines (51 loc) · 1.3 KB
/
Spring.cpp
File metadata and controls
66 lines (51 loc) · 1.3 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 "Spring.h"
#include "Point.h"
#include <glm/gtc/constants.hpp>
#include <glm/vec3.hpp>
#include <glm/glm.hpp>
Spring::Spring(QOpenGLShaderProgram* prog, GLfloat sectionRadius, GLfloat coilRadius, GLfloat pitch, GLfloat turns, GLuint nSlices, GLuint nStacks) :
ParametricSurface(prog, nSlices, nStacks),
_sectionRadius(sectionRadius),
_coilRadius(coilRadius),
_pitch(pitch),
_turns(turns)
{
_name = "Spring";
buildMesh(nSlices, nStacks);
}
Spring::~Spring()
{
}
float Spring::firstUParameter() const
{
return 0.0;
}
float Spring::lastUParameter() const
{
return _turns * glm::two_pi<float>();
}
float Spring::firstVParameter() const
{
return 0.0;
}
float Spring::lastVParameter() const
{
return glm::two_pi<float>();
}
Point Spring::pointAtParameter(const float& u, const float& v)
{
Point P;
float x, y, z;
//http://paulbourke.net/geometry/spiral/
// Spring
float h = (1 / glm::pi<float>()) / _sectionRadius * _pitch;
x = (_coilRadius + _sectionRadius * cos(v)) * cos(u);
y = (_coilRadius + _sectionRadius * cos(v)) * sin(u);
z = _sectionRadius * (sin(v) + u * h);
P.setParam(x, y, z);
return P;
}
void Spring::buildMesh(GLuint nSlices, GLuint nStacks)
{
ParametricSurface::buildMesh(nSlices * _turns, nStacks);
}