-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathkolor.html
More file actions
299 lines (245 loc) · 13.1 KB
/
kolor.html
File metadata and controls
299 lines (245 loc) · 13.1 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
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
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Kolor | Priyank Jain </title>
<script src="https://use.fontawesome.com/21d3028b6a.js"></script>
<link href="https://fonts.googleapis.com/css?family=Arvo:400,700" rel="stylesheet" type="text/css">
<link href="https://fonts.googleapis.com/css?family=Open+Sans:400italic,600italic,400,300,600,700" rel="stylesheet" type="text/css">
<link rel="stylesheet" href="resources/css/normalize.min.css">
<link rel="stylesheet" href="resources/css/base.css">
<link rel="stylesheet" href="resources/css/layout.css">
<link rel="stylesheet" href="resources/css/skeleton.css">
<link rel="stylesheet" href="resources/css/screen.css">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
</head>
<body>
<header>
<div class="container">
<div class="navigation-inner clearfix">
<div class="seven columns">
<a href="index.html">
<div id="name"> Priyank Jain </div>
<div id="title"> Bringing Ideas to life </div>
</a>
</div>
<div class="nine columns">
<ul class="menu primary-menu clearfix">
<li><a href="index.html">Home</a></li>
<li><a href="about.html">About</a></li>
</ul>
</div>
</div>
</div>
</header>
<div class="container">
<div class="page clearfix">
<div class="sixteen columns">
<h2> Kolor </h2>
<!-- <img class="cover-photo" src="resources/imgs/wordsAway/wordsAway.png"> -->
</div>
<div class="six columns">
<iframe src="https://player.vimeo.com/video/12312013?portrait=0" width="100%" height="260" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>
</div>
<div class="ten columns">
<p>Kolor is a first-person 3D shooter game developed using only C++ & OpenGL. The objective of the game is to gain dominance in the world by coloring other players to your own color. Players belong to a team, represented by a captain and his color. You can Kolor(paint) all the players on the team or just kolor the master to claim the team.</p>
<p>I built a prototype using C# & XNA to determine if the game would be fun. XNA takes care of a lot of details, which forced me to dig deeper into the math involved. This motivated me to adopt C++/OpenGL as the only tools. This turned out to be a huge undertaking. As a part of this, I implemented my own COLLADA DAE model library.</p>
<p>
Interesting things I did along the way:
<ul class="circle">
<li> <a href = "#3DModels"> COLLADA DAE loader </a> </li>
<li> <a href = "#MoveWorld"> How do I move in this world ? (FrameTransform) </a> </li>
<li> <a href = "#Camera"> First-Person View (my own gluLookAt) </a> </li>
<li> <a href = "#Collision"> Coloring Players </a> </li>
<li> <a href = "#Architecture"> Team architecture </a> </li>
</ul>
<hr>
</p>
</div>
<div class="twelve columns">
<p>
<a name="3DModels">COLLADA DAE Model Library </a> <br>
I needed a way to load & render 3D models for players/weapons/world. I was advised to use COLLADA DAE since it's the industry standard. I had to write my own Collada importer since there was no open source library at the time. I interpreted DAE's Directed Acyclic Graph into my own scene-graph. Take a look at:
<ul class="circle">
<li> VSGNode & VSceneGraph.h / cpp (DAE Model is accessed using this facade)</li>
</ul>
The collada format is very extensive so I only implemented the required subset. My library supported the following:
<ul class="circle">
<li> Scene Graph </li>
<li> Model Mesh information (organised in a tree structure) </li>
<li> Node in scenegraph can have the following operations defined in DAE (VSGNode.h / cpp):
<ul class="disc">
<li> Lookat </li>
<li> Transformation defined by a 4x4 matrix </li>
<li> Translate along X / Y or Z axis </li>
<li> Rotation at a given angle about an arbitrary axis </li>
<li> Scale / Skew </li>
</ul>
</li>
<li> Primitives supported:
<ul class="disc">
<li> Triangle List </li>
<li> Polygon List </li>
</ul>
</li>
<li> Vertex (.h) represents the heart of the model which stores data attributes as boost::hash_map { Semantic, (float*) } </li>
</ul>
</p>
<p>
<a name="RenderModel" > Indexed Vertex Buffer Objects </a>
<br>
Initially, I was using glBegin/glEnd to render models. However, when I loaded a high poly count model, the FPS crippled. I resorted to using Indexed Vertex Buffer Objects (VBOs) which helped FPS. For generating vertex indices, I ran the list of vertices through a hash-map and assign a unique index for each vertex. This can be seen in GeomMesh.cpp constructor and bool VertexExists(...) function.
<a href="#Top"> Top </a>
</p>
<p>
<a name="MoveWorld">
FrameTransform
</a>
<br>
Once the model was rendered, I wanted to create a "player" who could move around in the world, keeping track of its position and orientation. This gave birth to FrameTransform. I did this using three vectors:
<ul class="circle">
<li> Origin </li>
<li> Up </li>
<li> Forward vector </li>
</ul>
Using right hand thumb rule, I wrote functions that would let the entity move or rotate in the world. I manage the transformation matrix on the opengl stack manually! The details can be found in FrameTransform.h/cpp.
<br>
FrameTransform was generic in nature and players could fly. PlayerTransform restricts this behavior by enabling movement only along the X/Z axis:
<ul class="circle">
<li> Move (..) </li>
<li> Rotate(...) </li>
</ul>
</p>
<a href="#Top"> Top </a>
<hr>
<p>
<a name="Camera" > My own gluLookAt </a>
<br> <br>
For the First-person view, I needed to position world and everything else relative to player's coordinate system. Camera class uses the OpenGL transformation stack to transform everything as per player's Coordinate system. It is a 'friend' of (Human)Player, since the camera is tightly coupled to the player.
<pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%">
<code> class FrameTransform (6 DOF)
- glm::vec3 m_Origin;
- glm::vec3 m_Forward;
- glm::vec3 m_Up;
• MoveForward/Right/Up ( amt )
• RotateAround X/Y/Z ( amt )
• void ApplyActorTransform () => calls glMultMatrix(..)
class Player : public GameObject
- FrameTransform m_Transform; => Coordinate system w.r.t the world CS
class World : public GameObject (level class)
- FrameTransform m_Transform; => Coordinate system w.r.t the world CS
</code>
</pre>
A first person camera helps to view the world from the player’s eyes. Thus, we need a transformation which enables the view from player’s reference. <br>
Example:
<ul class="circle">
<li> WCS (0, 0)W </li>
<li> PCS (2, 2)W => Player is at 2, 2 in the world coordinate system => PW<=P (2, 2) </li>
<li> Chair P = (.5, .5)P </li>
<li> => Chair W = PW<=P * ChairP = (2.5, 2.5)W </li>
</ul>
This way we can get everything in World’s frame of reference. For First Person Camera, everything needs to be brought into Player’s coordinate system.
<br>
Player.m_Transform represents PW<=P . If we invert this matrix, we get P’P<-W which brings everything from World coordinate space to Player Coordinate space.
<pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"><code>void Camera :: ApplyCameraTransform()
{
glm::mat4 l_TransformationMatrix;
m_Player->m_Transformation.GetTransformation(l_TransformationMatrix, false);
l_TransformationMatrix = glm::core::function::matrix::inverse(l_TransformationMatrix);
glMultMatrixf(glm::value_ptr(l_TransformationMatrix));
}</code></pre>
It is invoked as follows:
<pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"><code>
void GameGL :: paintGL()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
mp_Camera->ApplyCameraTransform();
std::list<GameObject*>::iterator it_GameObjs;
for(it_GameObjs = m_GameObjectList.begin(); it_GameObjs != m_GameObjectList.end(); it_GameObjs++) {
(*it_GameObjs)->Render();
}
...
}</code></pre>
</p>
<a href="#Top"> Top </a>
<hr>
<p>
<a name="Collision" >
Coloring Players - When player and bullet collide!
</a>
As players move about and fire bullets, I manage collision detection/resolution by splitting it into broad and narrow phase.
<br>
The involved actors are :-
<ul class="circle">
<li> Players are approximated by a bounding sphere, located at a position and moving with a velocity. Player can potentially collide with weapons, world & bullets. </li>
<li> Bullets are represented by a segment with a start point & end point (using posn, posn + vel). Bullet can hit other fired bullets, players or world.</li>
</ul>
As each player and bullet is created, reference to each entity is stored within CollisionMgr. On each update frame, this happens:
<ul class="circle">
<li> For each player, find Cell(s); it is associated with :=> list< Cell* > PlayerCells </li>
<li> For each Bullet (segment), find Cell(s); it is associated with :=> list< Cell* > BulletCells </li>
<li> For each entity, the cell(s) can be found out based on the entity.
<ul class="disc">
<li> Player: Bounding sphere: The grid size are uniformly sized cell(M) such that, M = 2R. At any given time, the bounding sphere can be in contact with max 4 cells. To determine the cells associated, find the 8 points for a given sphere (each at 45 degrees X,Y,Z axis along 8 octants). (And then find out, in which grid cell does each of the point lie. This could return max 4 cells).</li>
<li>Bullet: Segmented Ray with endpoints at: Posn and (Posn + vel). All the cells that the line passes through would yield the cells. </li>
</ul>
</li>
<li> Cell can be a structure like:
<pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"><code>Cell {
List < Player*>
List < Bullet* >
Value (x,y,z) => unique value based on these three coordinates
}</code></pre></li>
</ul>
The hash-map iteration yields all possible pair of colliding players & bullets in a given cell. These are resolved using narrow-phase collision. Narrow phase would be a Bounding-Sphere/Segment (Player/Bullet) collision check. This required me to compute the bounding sphere for the given DAE model:
<ul class="disc">
<li> Iterate through all the points on the model tracking min/max point</li>
<li> Compute Sphere center & radius = distance(minimumPt, maximumPt) * 0.5; </li>
<li> This is run recursively on the scenegraph to return a hierarchy of bounding spheres </li>
<li> The resulting bounding spheres tight-approximation for the underlying model </li>
</ul>
</p>
<a href="#Top"> Top </a>
<hr>
<p>
<a name="Architecture" > Team architecture </a> <br/>
<img src= "http://yuml.me/diagram/scruffy/class/[TeamMgr]++-[Team],[Team]++-[Players]" > <br>
<img src= "http://yuml.me/diagram/scruffy/class/ [Team|TeamColor;Master;NumPlayers; PlayerList|AddPlayer(Player*)]">
<img src="http://yuml.me/diagram/scruffy/class/[Player]^[Human], [Player]^[Bot]">
</p>
</div>
</div> <!-- page clearfix -->
</div> <!-- container -->
<footer>
<div class="container">
<div class="footer-inner">
<div class="icons">
<span class="icon"> <a href="https://twitter.com/brainydexter"> <i class="fa fa-twitter"></i> </a> </span>
<span class="icon"> <a href="https://www.linkedin.com/in/brainydexter"> <i class="fa fa-linkedin"></i> </a></span>
<span class="icon"> <a href="https://github.com/brainydexter"> <i class="fa fa-github"></i> </a></span>
<span class="icon"> <a href="mailto:fly2priyank@gmail.com"> <i class="fa fa-envelope"></i> </a></span>
</div>
<div class="copyright">© Priyank Jain</div>
</div>
</div>
</footer>
<!-- Start of StatCounter Code for Default Guide -->
<script type="text/javascript">
var sc_project=5744193;
var sc_invisible=1;
var sc_security="6e56ab81";
var scJsHost = (("https:" == document.location.protocol) ?
"https://secure." : "http://www.");
document.write("<sc"+"ript type='text/javascript' src='" +
scJsHost+
"statcounter.com/counter/counter.js'></"+"script>");
</script>
<noscript><div class="statcounter"><a title="shopify stats"
href="http://statcounter.com/shopify/" target="_blank"><img
class="statcounter"
src="//c.statcounter.com/5744193/0/6e56ab81/1/" alt="shopify
stats"></a></div></noscript>
<!-- End of StatCounter Code for Default Guide -->
</body>
</html>