3rd Assignment
Collision Detection Game (" BuZz BAll")
Well BuZz BAll, this is how i named the game, is really a simple game, You are supposed to move a ball from its original position to its final destination, with as little collision with boxes as possible, since once you collide, your ball will be damaged and if you have hit the maximum damage, the game is over. if you notice that there is a number counting down, it is the timer, you have to be in the final destination before it counts down to 0, failing to reach destination on both way will lead to game over.
I am sorry that i dont really have much time to make BuZz BAll more attractive, so it is gonna be another boring 3D game after a while. But i trust you that the code and collision detection method can be reused easily in any other game or even for improvement of this game.
Basic collison detection method i used in the game are bounding volume, spatial subdivison and some mathematical equation to produce collision detection and resolution.
There are 2 basic elements in the game, ball and box, the two are using different
bounding volume, i used sphere as bounding volume for the ball and Axis-Aligned
Bounding Box for the boxes. Collision detection method are some mathematical
equation to compare whether the ball hits the boxes. All this calculations
are done offline, only moving ball coordinate is computed online for its collision
detection.
Codes to create boxes and to calculate collision are made standard, instead
of specifying every vertices, array vertices is used, thus it reduces complexity
and redundant repetition of vertex declaration.
collision detection is computed using mathematical equation, which includes some comparison between points of interest, this points are bounding boxes points, such as radius, xmin, xmax, zmin, zmax, you might wonder why i did not really consider y axis, there is no other reason but y is not of our interest in the game, our character does not go across y axis, it stays in a certain y coordinate. only when we want to make our character to be able to jump, than y axis will be included into consideration.
void DrawPlantBox(GLfloat
*BoxOne)
{ glBindTexture(GL_TEXTURE_2D, texture[0]);
glBegin(GL_QUADS); // Draw A Quad
glTexCoord2f(0.0f, 0.0f); glVertex3f( BoxOne[0], BoxOne[2], BoxOne[5]); //
Top Right Of The Quad (Top)
glTexCoord2f(1.0f, 0.0f); glVertex3f( BoxOne[1], BoxOne[2], BoxOne[5]); //
Top Left Of The Quad (Top)
glTexCoord2f(1.0f, 1.0f); glVertex3f( BoxOne[1], BoxOne[3], BoxOne[5]); //
Bottom Left Of The Quad (Top)
glTexCoord2f(0.0f, 1.0f); glVertex3f( BoxOne[0], BoxOne[3], BoxOne[5]); //
Bottom Right Of The Quad (Top)
......................................
void collisionTest1(GLfloat
*x, GLfloat *y, GLfloat *z, GLfloat *SpeedX, GLfloat *SpeedZ,GLfloat radius,
GLfloat *BoxOne)
{
//collison with boxif((*z-radius) <BoxOne[5] && (*z+radius) >
BoxOne[4])
{ if((*x-radius) < BoxOne[1] && (*x+radius)>BoxOne[0]){
hit = TRUE;
*SpeedX=0.0;
if((*x+radius) > BoxOne[1] && (*x-radius) < (BoxOne[1]+radius)
)
*x=(BoxOne[1]+radius);
if((*x+radius) > (BoxOne[0]-radius) && (*x-radius)< BoxOne[0])
*x=(BoxOne[0]-radius);}
*SpeedX=0.05;}
...................................
I also prepare the program to be extendable. collision detection method is
implemented on spatial subdivision across the gaming area, currently there
is only one spatial subdivision, because the game is small, in case for future
improvement, we decide to make the gaming area huge this spatial subdivision
for collision detection will come in handy. The reason is simple, it is just
very expensive to do brute force method to detect collision between all object
in the game. In spatial subdivision, we still need to do bruteforce method
to detect collision but, not to all objects in the game, we only calculate
collision in a certain area(subdivided area). thus it is very efficient method
for computing point of view
Subdivision Layout
switch(RegionTest(x,z)){
case 1 : //region 1collisionTest1(&x, &y, &z,&SpeedX, &SpeedZ,
radius, BoxOne);
collisionTest1(&x, &y, &z,&SpeedX, &SpeedZ, radius, BoxTwo
..........................................
int RegionTest(GLfloat x, GLfloat z)
{if( x>=15.0 && x<30.0 && z>=15.0 && z<30
)
return 1;
..................................................
I hope you will enjoy the game!!! and please feel free to drop me feed back
Before you play, please read "readme" file for instruction
Download
executable
file and code for BuZz
BAll
Acknowledgement
I would like to thank you everyone who have helped me through out this assignment.
Prof Edmond Prakash
Like Gobeawan.
The following are link to website that I have been
visiting for consultation or some reading in order to complete this assignment.
http://apron.morrowland.com/
http://nehe.gamedev.net/
http://www.darwin3d.com/gdm1999.htm#gdm0199