Game Development Reference
In-Depth Information
The following code uses the glMatrix library to calculate the perspective matrix using
the preceding parameters:
var mat=mat4.create()
mat4.perspective(30, gl.viewportWidth / gl.viewportHeight, 0.1,
1000.0, pMatrix);
Learning the basics of 3D graphics
We want to save our world in 5000 AD, and we have very little time. So, let's quickly
jump into the code and understand the basics along with it.
Understanding mesh, polygon, and vertices
A model in a 3D game is called a mesh . Each facet in a mesh is called a polygon . A
polygon is made up of three or more corners, and each corner is called a vertex . The
objective of the code provided in this chapter is to render a basic primitive quad.
The code creates a mesh with a single polygon and the polygon has four vertices.
A polygon with four vertices will form a quad. Each vertex is denoted by a location
on the screen. A location on the screen can be represented by using 2 or 3 axes. Each
location is defined by using vectors.
In the following example code, we have created an array of vertices with 12 float
values (3 per vertex).The following diagram shows the mapping of the coordinates:
(-3,3,0)
(3,3,0)
(-3,-3,0)
(3,-3,0)
Local Coordinates
and global Coordinates
 
Search WWH ::




Custom Search