-
Notifications
You must be signed in to change notification settings - Fork 0
/
Torus.cpp
215 lines (174 loc) · 4.63 KB
/
Torus.cpp
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
#include "stdafx.h"
#include "Torus.h"
#include "TorusControl.h"
#include "ProtoHaptic.h"
#include <GL/GLUT.h>
CTorus::CTorus(void)
{
// Set Default parameters
m_radiusMajor= 1.0;
m_radiusMinor= 0.25;
m_drawnFraction= 1.0; //i.e. Complete
m_sizeX= 1.0; m_sizeY= 1.0; m_sizeZ= 1.0;
setLocation(0.0,0.0,0.0);
m_control= new CTorusControl(this);
}
CTorus::~CTorus(void)
{
}
/** Get radius of outer loop spine */
float CTorus::getRadiusMajor ( )
{
return m_radiusMajor;
}
/** Set radius of outer loop spine */
void CTorus::setRadiusMajor ( float r )
{
m_radiusMajor= r;
}
/** Get radius of outer loop */
float CTorus::getRadiusMinor ( )
{
return m_radiusMinor;
}
/** Set radius of outer loop */
void CTorus::setRadiusMinor ( float r )
{
m_radiusMinor= r;
}
CShape* CTorus::clone()
{
CTorus* cloned;
cloned= new CTorus();
cloned->setLocation(m_locationX,m_locationY,m_locationZ);
cloned->setRotation(m_rotation);
cloned->setSize(m_sizeX,m_sizeY,m_sizeZ);
cloned->setColour(m_colourRed,m_colourGreen,m_colourBlue);
cloned->setDampening(m_dampening);
cloned->setDynamicFriction(m_dynamic_friction);
cloned->setStaticFriction(m_static_friction);
cloned->setStiffness(m_stiffness);
cloned->m_surfaceFriction= m_surfaceFriction;
cloned->m_mass= m_mass;
cloned->m_proxyDynamic= m_proxyDynamic;
cloned->m_collisionDynamic= m_collisionDynamic;
cloned->m_logical= m_logical;
cloned->m_stiffnessString= m_stiffnessString;
cloned->m_dampeningString= m_dampeningString;
cloned->m_staticFString= m_staticFString;
cloned->m_dynamicFString= m_dynamicFString;
cloned->m_radiusMajor= m_radiusMajor;
cloned->m_radiusMinor= m_radiusMinor;
cloned->m_name= m_name;
return (CShape*)cloned;
}
/** Get radius of outer loop */
float CTorus::getRadius ( )
{
return 0.0;
}
/** Set radius of outer loop */
void CTorus::setRadius ( float r )
{
//m_radius= r;
}
/* Some <math.h> files do not define M_PI... */
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
void
doughnut(GLfloat r, GLfloat R, GLint nsides, GLint rings, float complete)
{
int i, j;
GLfloat theta, phi, theta1;
GLfloat cosTheta, sinTheta;
GLfloat cosTheta1, sinTheta1;
GLfloat ringDelta, sideDelta;
ringDelta = 2.0 * M_PI / rings;
sideDelta = 2.0 * M_PI / nsides;
theta = 0.0;
cosTheta = 1.0;
sinTheta = 0.0;
int drawnRings= rings * complete;
for (i = drawnRings - 1; i >= 0; i--) {
theta1 = theta + ringDelta;
cosTheta1 = cos(theta1);
sinTheta1 = sin(theta1);
glBegin(GL_QUAD_STRIP);
phi = 0.0;
for (j = nsides; j >= 0; j--) {
GLfloat cosPhi, sinPhi, dist;
phi += sideDelta;
cosPhi = cos(phi);
sinPhi = sin(phi);
dist = R + r * cosPhi;
glNormal3f(cosTheta1 * cosPhi, -sinTheta1 * cosPhi, sinPhi);
glVertex3f(cosTheta1 * dist, -sinTheta1 * dist, r * sinPhi);
glNormal3f(cosTheta * cosPhi, -sinTheta * cosPhi, sinPhi);
glVertex3f(cosTheta * dist, -sinTheta * dist, r * sinPhi);
}
glEnd();
theta = theta1;
cosTheta = cosTheta1;
sinTheta = sinTheta1;
}
}
void CTorus::drawGLScene()
{
PreRender();
glPushMatrix();
glTranslatef(m_locationX,
m_locationY,
m_locationZ);
glMultMatrixf(m_rotation);
glScalef(m_sizeX, m_sizeY, m_sizeZ );
glColor3f(m_colourRed,
m_colourGreen,
m_colourBlue);
int stacks= ((CProtoHapticApp*)AfxGetApp())->getStacks();
doughnut ( m_radiusMinor, m_radiusMajor, stacks, stacks, m_drawnFraction );
glPopMatrix();
}
void CTorus::drawHapticScene(bool primary_context)
{
hlMaterialf(HL_FRONT_AND_BACK, HL_STIFFNESS, m_stiffness);
hlMaterialf(HL_FRONT_AND_BACK, HL_DAMPING, m_dampening);
hlMaterialf(HL_FRONT_AND_BACK, HL_STATIC_FRICTION, m_static_friction);
hlMaterialf(HL_FRONT_AND_BACK, HL_DYNAMIC_FRICTION, m_dynamic_friction);
if(primary_context)
hlBeginShape(HL_SHAPE_FEEDBACK_BUFFER, m_shapeID);
else
hlBeginShape(HL_SHAPE_FEEDBACK_BUFFER, m_shapeID_1);
drawGLScene();
hlEndShape();
}
int CTorus::getType() { return SHAPE_TORUS; }
CString CTorus::drawGLCode()
{
CString s= "// !!Torus Code Not Implimented!! \r\n";
return s;
}
void CTorus::Serialize(CArchive& ar)
{
CShape::Serialize(ar);
if(ar.IsStoring())
{
ar << m_radiusMajor;
ar << m_radiusMinor;
}
else
{
ar >> m_radiusMajor;
ar >> m_radiusMinor;
}
}
/** Get drawn fraction of outer loop */
float CTorus::getFraction ( )
{
return m_drawnFraction;
}
/** Set drawn fraction of outer loop */
void CTorus::setFraction ( float f )
{
m_drawnFraction= f;
}