Game Development Reference
In-Depth Information
Values of i and j
x coordinate
y coordinate
For i = 0 and j = 2
x = 2 * 64/3 - 32
y = 0 * 64/3 - 32
For i = 0 and j = 3
x = 3 * 64/3 - 32
y = 0 * 64/3 - 32
For i = 1 and j = 0
x = 0 * 64/3 - 32
y = 1 * 64/3 - 32
For i = 1 and j = 1
x = 1 * 64/3 - 32
y = 1 * 64/3 - 32
For i = 1 and j = 2
x = 2 * 64/3 - 32
y = 1 * 64/3 - 32
For i = 1 and j = 3
x = 3 * 64/3 - 32
y = 1 * 64/3 - 32
If you look at the preceding list, the value of y is 1 * 64/3 - 32, which is negative of
the derived value that we got. Hence, we push this negative value in the code using
the this.vertices.push(- y) statement.
Notice that we have inherited our Geometry class, which means we have all the
variables ( this.vertices , this.faces ) already defined. So, we simply push the
calculated vertices on our vertices array.
Also, as our plane lies in the XY plane, the z axis is our normal for each vertex. Hence,
we have also defined our normal ( var normal = vec3.fromValues( 0, 0, 1 ); ).
Let's now calculate the indices that make our triangles.
If you see the order in which we push the vertices on our array, you will realize that
we do it in the row-major order. Hence, (0, 0), (0, 1), (0, 2), (0, 3),..........., (0, n ) are
indexed as (0, 1, 2, 3,..... n ). The following diagram shows the vertex to index mapping
of the plane segments:
0
1
2
3
(0,0)
(0,1)
(0,2)
4
5
6
7
(1,0)
(1,1)
(1,2)
8
9
10
11
Search WWH ::




Custom Search