-
Notifications
You must be signed in to change notification settings - Fork 2
/
Cup.cpp
165 lines (150 loc) · 4.92 KB
/
Cup.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
/*
* Caleb Everett
* Graphics Final
*
* Cup.cpp
*/
#if !defined(CUP_CPP)
#define CUP_CPP
#include "Cup.h"
// not used
const float Cup::sideBottomVertex[sideBottom_length][3] = {
{ 15, 0, 1.5},
{ 15, 2, 1.5},
{16.5, 0, 1.5},
{16.5, 2, 1.5},
{16.5, 0, -1.5},
{16.5, 2, -1.5},
{ 15, 0, -1.5},
{ 15, 2, -1.5}
};
const float Cup::sideWallVertex[sideWall_length][3] = {
{ 1.5,-2, 15},
{ 1.5, 2, 15},
{ 1.5,-2,19},
{ 1.5, 2,19},
{ -1.5,-2,19},
{ -1.5, 2,19},
{ -1.5,-2, 15},
{ -1.5, 2, 15}
};
// not used
const float Cup::cornerBottomVertex[cornerBottom_length][3] = {
{ 15, 0, 1.5},
{ 15, 2, 1.5},
{16.5, 0, 1.5},
{16.5, 2, 1.5},
{16.5, 0, -1.5},
{16.5, 2, -1.5},
{ 15, 0, -1.5},
{ 15, 2, -1.5}
};
const float Cup::cornerWallVertex[cornerWall_length][3] = {
{27.878, -2, 15},
{27.878, 2, 15},
{30, -2, 17.121},
{30, 2, 17.121},
{32.121, -2, 15},
{32.121, 2, 15},
{30 , -2, 12.878},
{30 , 2, 12.878},
};
Cup::Cup()
{
;
}
void Cup::add(btDiscreteDynamicsWorld *world)
{
// builds a collison mesh out of the vertex arrays.
btTriangleMesh *mWallTriMesh = new btTriangleMesh();
for (int i = 0, length = sideWall_length - 2; i < length; i++)
{
mWallTriMesh->addTriangle(
btVector3(sideWallVertex[i][0], sideWallVertex[i][1], sideWallVertex[i][2]),
btVector3(sideWallVertex[i + 1][0], sideWallVertex[i + 1][1], sideWallVertex[i + 1][2]),
btVector3(sideWallVertex[i + 2][0], sideWallVertex[i + 2][1], sideWallVertex[i + 2][2])
);
mWallTriMesh->addTriangle(
btVector3(sideWallVertex[i][0], sideWallVertex[i][1], -sideWallVertex[i][2]),
btVector3(sideWallVertex[i + 1][0], sideWallVertex[i + 1][1], -sideWallVertex[i + 1][2]),
btVector3(sideWallVertex[i + 2][0], sideWallVertex[i + 2][1], -sideWallVertex[i + 2][2])
);
}
for (int i = 0, length = cornerWall_length - 2; i < length; i++)
{
mWallTriMesh->addTriangle(
btVector3(cornerWallVertex[i][0], cornerWallVertex[i][1], cornerWallVertex[i][2]),
btVector3(cornerWallVertex[i + 1][0], cornerWallVertex[i + 1][1], cornerWallVertex[i + 1][2]),
btVector3(cornerWallVertex[i + 2][0], cornerWallVertex[i + 2][1], cornerWallVertex[i + 2][2])
);
mWallTriMesh->addTriangle(
btVector3(cornerWallVertex[i][0], cornerWallVertex[i][1], -cornerWallVertex[i][2]),
btVector3(cornerWallVertex[i + 1][0], cornerWallVertex[i + 1][1], -cornerWallVertex[i + 1][2]),
btVector3(cornerWallVertex[i + 2][0], cornerWallVertex[i + 2][1], -cornerWallVertex[i + 2][2])
);
mWallTriMesh->addTriangle(
btVector3(-cornerWallVertex[i][0], cornerWallVertex[i][1], cornerWallVertex[i][2]),
btVector3(-cornerWallVertex[i + 1][0], cornerWallVertex[i + 1][1], cornerWallVertex[i + 1][2]),
btVector3(-cornerWallVertex[i + 2][0], cornerWallVertex[i + 2][1], cornerWallVertex[i + 2][2])
);
mWallTriMesh->addTriangle(
btVector3(-cornerWallVertex[i][0], cornerWallVertex[i][1], -cornerWallVertex[i][2]),
btVector3(-cornerWallVertex[i + 1][0], cornerWallVertex[i + 1][1], -cornerWallVertex[i + 1][2]),
btVector3(-cornerWallVertex[i + 2][0], cornerWallVertex[i + 2][1], -cornerWallVertex[i + 2][2])
);
}
wallShape = new btBvhTriangleMeshShape(mWallTriMesh,true);
wallMotionState =
new btDefaultMotionState(btTransform(btQuaternion(0,0,0,1),btVector3(0,0,0)));
btRigidBody::btRigidBodyConstructionInfo
wallRigidBodyCI(0,wallMotionState,wallShape,btVector3(0,0,0));
wallRigidBody = new btRigidBody(wallRigidBodyCI);
wallRigidBody->setRestitution(1.0); // sets it so that the balls bounce off
wallRigidBody->setFriction(0.0); // low friction so the balls do not stop rotating when they hit the wall
world->addRigidBody(wallRigidBody);
}
void Cup::draw()
{
glPushMatrix();
//glPolygonMode(GL_FRONT_AND_BACK,GL_LINE);
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
glColor3f(0.5, 0.2, 0.0); // green
glBegin(GL_TRIANGLE_STRIP);
for (int i = 0; i < sideWall_length; i++)
{
glVertex3f( sideWallVertex[i][0], sideWallVertex[i][1], sideWallVertex[i][2]);
}
glEnd();
glBegin(GL_TRIANGLE_STRIP);
for (int i = 0; i < sideWall_length; i++)
{
glVertex3f( sideWallVertex[i][0], sideWallVertex[i][1], -sideWallVertex[i][2]);
}
glEnd();
glBegin(GL_TRIANGLE_STRIP);
for (int i = 0; i < cornerWall_length; i++)
{
glVertex3f( cornerWallVertex[i][0], cornerWallVertex[i][1], cornerWallVertex[i][2]);
}
glEnd();
glBegin(GL_TRIANGLE_STRIP);
for (int i = 0; i < cornerWall_length; i++)
{
glVertex3f( cornerWallVertex[i][0], cornerWallVertex[i][1], -cornerWallVertex[i][2]);
}
glEnd();
glBegin(GL_TRIANGLE_STRIP);
for (int i = 0; i < cornerWall_length; i++)
{
glVertex3f( -cornerWallVertex[i][0], cornerWallVertex[i][1], cornerWallVertex[i][2]);
}
glEnd();
glBegin(GL_TRIANGLE_STRIP);
for (int i = 0; i < cornerWall_length; i++)
{
glVertex3f( -cornerWallVertex[i][0], cornerWallVertex[i][1], -cornerWallVertex[i][2]);
}
glEnd();
glPopMatrix();
}
#endif