程序代写代做代考 scheme c++ algorithm CS104 Fundamentals of Computer Graphics Faculty of Information Technology

CS104 Fundamentals of Computer Graphics Faculty of Information Technology
Macau University of Science and Technology Project
An Interactive 3D Maze Game November 2016 (Fall Semester)
Due day: 3rd Jan 2017 (Tuesday) 17:30
Objective
In this project, you are required to write An Interactive 3D Maze Game. You will need to integrate almost all OpenGL features that we have discussed in the tutorial series so far to complete it. Player will control the object (mouse, for example) with the mouse and navigate inside the maze to find the door out. To encourage creativity, we do not fix the object and the texture you are going to use. As a result, you can make your own 3D maze game with object or texture you prefer.
Useful Stuff To Get You Started
We provide bitmap.h and bitmap.cpp for reading the BMP files, and project.cpp which containing the skeleton of program. We also provide the BMP files, namely, wall.bmp, floor.bmp, door.bmp for drawing the wall, floor, and door of the maze. A sample implementation sample.exe and a sample map map.dat are also available. You can get these files from the course FTP.
Project Specification
Here we give some suggestions for the implementation, however, you may design one all by yourself.
How To Getting Started
First, you can have a look on the program project.cpp and the sample.exe.
Construct a Structure For Your Object
You need to construct a structure to store the player object’s current information as follow (actually we have done it for you):
typedef struct _playerInfo {
GLfloat degree; /* the Object Orientation */ GLfloat forward,spin;
GLfloat pos[3]; /* User Position */
1

GLfloat mySize;
GLfloat forwardStepSize; GLfloat spinStepSize;
} playerInfo; playerInfo _player;
/* User Radial Size */ /* Step size */
/* Rotate step size */
Also, a function to read in the map is needed, and the map may place in to following variables:
#define MAX_MAZESIZE 20
static int _mapx,_mapz; /* Size of the Maze */
static int _map[MAX_MAZESIZE][MAX_MAZESIZE]; int _initpos[2]; /* initial position of the player */
The Maze Map
Our maze is formed by rectangular area blocks, and the 2D overhead view map is stored in the 2D array “_map”. If the value _map[i][j] is 1, it means a wall exists at position (i, j). Here is an example of a 4×4 map y
z
1
1
1
1
1
2
0
1
1
0
0
1
1
1
3
1
2

Its value means:
When the value is 2, the player should be located at the center of that block.
When the value is 3, a sign of exit should be drawn there. Therefore when the player reaches this block, the game will complete.
Please notice that we use z here (which we usually use y), because we will use y as the upward direction for a 3D environment in OpenGL.
The Object Motions
The object has 2 kinds of motion, one is horizontally rotate about its own center (by clicking right or left mouse button), another is moving forwards (by clicking both right and left buttons). They correspond to the “spin” and “forward” fields in the structure respectively.
Draw the Ground
You have to draw a ground plane with size of whole area of the maze. The plane dimension should be (_wallScale * _mapx) x (_wallScale * _mapz). _wallScale is the scale of the wall. _mapx and _mapy are the size of the maze. It would be a better idea to set it at the level y = 0. It is required to texture map the floor to enhance the appearance.
Draw the Walls
For the area block with value 1, you should draw walls on the boundary of that block, so that the player cannot find the goal easily. Draw the blocks of walls according to the 2D map. The width and height of the wall for display are scaled by _wallScale and _wallHeight. They are the scale of the width and the height of the wall, respectively. You need to set these parameters by yourself. It is required to texture map the wall to enhance the appearance.
Draw the Player
You can draw the player as what you like, in the debugging state, it will be a better idea to draw just a wire/solid sphere. No complicated object is required. Also texture mapping the object is optional. However, you must set the material properties of the object in order to enhance its appearance.
0
Vacant
1
Wall
2
Player’s initial position
3
The Exit
3

Make Your Initialization in Init()
You need to do your initialization in Init() function. If you try to use some features such as Fog Effect, Lighting, their initialization should be included here.
Implement Collision Detection
Collision detection is an important technique in Computer Animation and Computer Game community. OpenGL is only a graphical library for displaying objects, so collision detection functions are not provided. As a result, you will find the object can go through the wall. Therefore, you need to write a function to detect whether the collision is occurred or not. Moreover, you should correct the position so as to prevent player from passing through the wall.
There are several methods for collision detection, here we introduce one simple method to handle our case.
The player object boundary is assumed to be in spherical shape. You may assume the size of object smaller than 1 block area. Also, the unit step size of object is smaller than its own size.
As there is no vertical movement (move in y-axis) of object, and the walls are rectangular blocks, so we can simplify the collision only occur in a 2D.
Step 1:
Since the maze is formed by grids, your object will only hit any wall if it is intersecting any grid line(s), so now our first problem is to check whether there is intersection of the sphere with the grid lines.
The equation for sphere:
(x – Cx)2 + (y – Cy)2 = r 2
to check if it intersects the surrounding 4 grid lines
x=Gx,x=Gx +wallScale
y=Gy,y=Gy +wallScale
we can substitute a value to it , for example to check whether it intersect x = Gx.
(Gx – Cx)2 + (y – Cy)2 = r 2
y2 – 2 Cy* y + Cy 2 + (Gx – Cy)2 – r 2 = 0
For this equation to have solution, we can calculate its determinant
Det = 4 Cy 2 – 4 * (Cy 2 + (Gx – Cx)2 – r 2) Det = 4 * ((Gx – Cx)2 – r 2)
If Det >= 0, it means intersection occurs, otherwise, it doesn’t. 4

Step 2:
If you find intersection with the grid line, it is possible that a collision with walls occurred. However, you must also check whether a wall exists at that position, so you may lookup the array _map to confirm.
Here, we just an outline one method briefly. It is highly recommended that you can design your own.
Using the Interface
1. Clicking left button for rotating your object left horizontally about its own center. 2. Clicking right button for rotating your object right horizontally about its own
center.
3. Clicking both left and right buttons for moving the object forwards.
Submission
1. You are required to submit a softcopy of your report. For your finished program,
please zip your source code, *.sln, *.vcproj, *.dat, *.bmp, *.bat files and then sent it to my E-mail box (hcwong@must.edu.mo) with the subject title “Project”. Your name and the student ID number should be included in both your report and program. Missing any above item will be lead to mark deduction.
2. A complete program should be free of any typing mistakes, compilation errors, warnings under Microsoft Visual C++ .NET. Incomplete program is regarded as incomplete project.
3. An English written report is required, and NO mark will be given to Chinese reports.
5

4. Plagiarism is strictly monitored and punished if proven. Lending your work to others for reference is considered as supplying a source for copying which is subjected to the SAME penalty. Being a mature participant in this course, you are supposed to be able to differentiate between teaching others, discussion and partial/full copying.
5. For your written report you need to include at least the following sections: a) Design outline;
b) Key code fragments or algorithms of your program;
c) How to use your program;
d) Experimental Results;
e) Your feelings or opinions about this project.
Grading Scheme
Your project will be graded by the following marking scheme:
Display Objects, Ground and Wall 8% Texture mapping the Wall and Ground 6% Using Lighting and Material 4% Using Fog Effect 2% English Written Report (softcopy) 10%
Total 30%
Collision Detection (bonus) 5%
Maximum 35%
Acknowledgement/Credit
This project description was originally written by Dr. T.-T. Wong for a graphics course at the Department of Computer Science and Engineering, Chinese University of Hong Kong, China.
6