For this final project, I created a 3D Go game. A primary goal for doing this project was to obtain more experience with 3D-interaction design and implementation. This 3D Go game allows users to play Go game on a standard Go game board (19X19). Players drag mouse to the target position and place their stone through click. Traditional Go game is very complex for designing related AI, but relatively simple on the visual side. So, I decide to add a little flare to make the game more fun with additional visual effects like stone-popping, laser and explosion.
The main challenge for building a 3D Go game is to get object coordinates on mouse click. Stone placing position are pre-defined based on its index (adjusted to match the texture on board) For this Go game, user can click anywhere on the screen(pixel space). To determine if this click is on the game board or not, I need to calculate the coordinates in the world space to determine. The way is to use glm::unProject function. Because the 2D screen is the projection of 3D world space, so any click on screen actually can represent a line(from near-end to far-end). Since board table is fixed in the world space and stones are place on its top surface(its normal is vec3(0,1,0)), so for determining placing stones, the Y value for this click on board in world space is equal to the Y value of board's top surface. Now I have the world coordinates of near-end and far-end, use board's Y value, I can easily calculate the X and Z value of this click on the board plane to determine if it's an effective click to add stones
In this project, OmegaGo (the cat) can fire laser beam from its eyes and destroy player's stones. To make a laser, I intersect a small quad plane to another(90 degree), and use a laser beam texture on both quads. The desire laser has one fixed source(cat's eye), but the position of its target (stones on board) will change. So, whenever a laser is needed. I calculate the normal of source pointing to target, rotate the laser based on values of this normal, and then translate the laser to the target stone position. the laser itself can be very long along Y axis, so I discard the uncessary parts(behind the eye and beneath the board) in its fragment shader.
Explosion is achieved by modifying the code from Lab10. I disabled the rebirth of particles and modified the start speed and life span. So, now it looks more like an explosion.
In this project, OmegaGo can use its mind to pop its stone up and hit player's stone. The popping stone and the target stone are determined at the beginning of such action. Then the start speed on X and Z direction are calculated based on coordinates of popping stone and target stone. speed on Y is a fixed value, it works with the gravity to make sure two stone hit each other
The explosion can push nearby stones away if their new positions are not occupied. When an explosion happens, all its 8 nearby stones are examined. If their new position is available (for up-left stone A, if A's up-left is empty, meaning it's available), then they will be pushed away. once they moved to the target position, in the stone array, I will mark the old space empty and the new place occupied
This project is really an accumulation of practice and experience from all the labs and programs in 471 class. Fantastic learning experience!
http://myweb.lmu.edu/dondi/share/cg/unproject-explained.pdf