1.
PRINCIPLES OF
COMPUTER GRAPHICS
Instructors :
RAFFAELE DE AMICIS,
GIUSEPPE CONTI
Final Project : 3-D Arkonoid
Student :
ORUC HUSEYIN GURSOY
2.
1. INTRODUCTION OF THE GAME DARKONOID :
Darkonoid is the 3-d version of the old game Arkonoid.(3-D
Arkonoid=Darkonoid)
In Arkonoid you had everything as 2-d objects. Your base was a thick line-
shaped object, ball was circle, items to destroy was rectangles and all of the
movements were in 2-d.
So in Darkonoid everything is in 3-d. In picture-1 you can see the
difference.
Picture-1 : Difference of Arkonoid and Darkonoid.
In Darkonoid every object is typically 6-gon prism, but there is a little
difference in your ball. The ball is modified to make it spehere-like shape. You
can see a general picture of these objects in picture-2
You can control your base with the mouse, and you can move your point
of view with the keyboard.
Your mission is to destroy the items which are colored red, green and
blue. Red is 5 points, Blue is 3 points, Green is 1 point.
The scoreboard and other information is displayed in a seperate window.
When the game starts the ball will start to move and bounce from the
walls and the items. You must not miss the ball towards youerself. If so you will
loose 1 life and you have 3 lives. If you loose all of them the game is over.
3.
Picture 2.The objects in Darkonoid.
2. THE CLASSES:
A. Class MATRIX :
Members :
public int satir; // #rows
public int sutun; // #columns
public double[][] sayi; // matrix items
Construction :
public Matrix(int satir, int sutun)
public Matrix(Point3D p)
The class matrix is used for matrix related operations. it has three
members : the number of rows, the number of columns and the array which
holds the matrix's items. It can be created by just giving the row and column or
giving a point. If row and column is given, then an identity matrix is created. If
a point is given, then the matrix form ofthe point is created.
Methods .
public void sifirla() : makes this matrix identity
public void Esitle(Matrix e) : makes this matrix equal to e
public void MultiplyWith(Matrix m) : multiplies with m
public void transMatrix(double a,double b,double c) : makes this matrix a
translation matrix
public void scaleMatrix(double sx, double sy, double sz) : makes this
matrix a scaling matrix
public void rotateAroundY(double theta) : makes this matrix a rotation
matrix
4.
public void rotateMatrixAroundPoint(Point3D p, double theta) : makes this
matrix a rotation around a Point
public void strToConsole() : writes matrix to console
B. Class Geometry :
The class Geometry is the base geometry for all of the objects. Every
object can have its own matrix.
Every geometry has its own display, applyTtansform, range and coloring
(renk) method.
C. Class Point3D :
Members :
public double x;
public double y; COORDINATES OF THE POINT
public double z;
public double r;
public double g; COLOR OF THE POINT
public double b;
Methods :
public void renkRandom() // Random coloring of the point.
Point3D is the primitive class in the project. Every thing is created from
Point3D. It has the coordinates and the color as the members. The renkRandom
is used for coloring the point randomly.
D. Class N_gon3D :
Members;
public int n; // n of Ngon
public Point3D Points[]; // points of Ngon
public Point3D center; // center point
Construction
public N_gon3D(Point3D center, double r1,double r2, int n)
center : center point
r1 : radius 1
r2 : radius 2
n : n of N_gon3D
N_gon3D, has a ceter point and set of points which forms the Ngon. It is
constructed by giving n, radius 1, radius 2 and the center pont. So the shape of
the Ngon can be elliptical if r1is not equal to r2. If r1==r2 then it is circular.
5.
E. Class Obj3D :
Members;
public N_gon3D alt;
public N_gon3D ust;
public int n;
public double r1;
public double r2;
public double h;
Construction
public Obj3D(int n, double r1,double r2, double h)
h : height of object
Obj3D is formed by two N_gon3D s. One is placed at the bottom and the
other at the top. h is the range between them.
3. HOW IT WORKS :
A. Creating The Objects :
All of the objects are created at the initialization phase. The objects are
first created and moved to their locations. The items are located randomly in
the game volume.
The ball is also Obj3D but it is modified for transforming it into sphere-like
shape. The center ponts of the N_gon3D at the bottom and the top, are moved
towards outside.
The game volume and the base are displayed by lines in order to make
the game playable.
At each mouse movement, the base is moved to the location of the
mouse on its plane.
B. Main Algorithm :
At each display following actions are done;
1: get the ball,
2: apply its own transformation matrix,
3: if collision with the walls
take back the movement,
change the transformation matrix properly,
apply new transformation,
4: if inside an item
take back the movement,
change the transformation matrix properly,
apply new transformation,
5: if life lost
do appropriate actions.
6.
C. Info About Code :
1. Rage from a plane :
In this project, the range from a point to a plane is needed to be
calculated for understanding the collision between the objects. The form of this
method is as follows :
double rangeFromPlane(Point3D p, Point3D p1,Point3D p2,Point3D p3)
In order to calculate the range the plane has to be calculated in the form :
ax+by+cz+d=0. This is done by solving an equations system. This system is
shown in picture 3.
Picture 3. Equation system of the plane. x,y,z are the coordinates of
p1,p2 and p3.
Whe you get a,b,c,d the distance becomes to
If you don't take the absolute value, then you can determine the point is in the
normal's side or not.
2. Reflection from a plane :
Some can do this by setting the normal of the wall on one of the
axes, then rotating 180 degrees or scaling with -1 according to that axis and
setting the normal back to the original.(Of course you have to negate the
vector.) There are lots of matrix multiplications in this way.
However my way is a bit different and faster. It is faster because you
don't need to do lots ofmutrix multiplications.
Here is the algorithm :
● get the normal of the plane
● get the projection of your vector on the normal and negate it
● add the 2 x result to your vector
In picture 4 Reflection from a plane is demonstrated.
7.
Picture 4 : Reflection from a plane.
3. Round-like shaped base :
In order to increase the playabality of the game, a minor control of
the ball is added to the game.
If the ball hits the center of the base no change at the direction of the
ball occurs. If it hits far from the center, then the reflection is a bit changed
against the center point. This is shown in picture 5.
Picture 5 : Reflection from the base.
This is done with a trick : by just adjusting the normal according to the
range between the center of the base and the hitting point.
4. Information about other parts :
The collision detection of the ball and the items, requires a lot of
calculations. In order to avoid this a pre-check of the range is done. First the
range between a point on the ball and one of the center points on the item is
checked. If it is below a value then further check is done. This make the game
run faster.
Be the first to comment