Game Development Reference
In-Depth Information
Understanding the square geometry code
We have added a new geometry, a square. This geometry will be used to render our
texture. Open
SquareGeometry.js
from the
primitive
folder in your editor.
The
SquareGeometry
class defines four corner vertices and four UV coordinates.
Then we declare our two faces of two triangles. The indices of the two triangles for
each face are [0,1,2] and [2,1,3]:
SquareGeometry = inherit(Geometry, function ()
{
superc(this);
this.vertices=[
-1.0,-1.0,0.0,//0
1.0,-1.0,0.0,//1
-1.0, 1.0,0.0,//2
1.0, 1.0,0.0//3
];
var uvs=[ 0.0, 0.0,
1.0, 0.0,
0.0, 1.0,1.0,1.0];
var face = new Face();
face.a=0;
face.b=1;
face.c=2;
this.faces.push( face );
var face = new Face();
face.a=2;
face.b=1;
face.c=3;
this.uvs[0]=uvs;
this.indicesFromFaces();
});
The other class we have added is
Square
which inherits the
StageObject
class.
Open
Square.js
from the
primitive
folder in your editor. We just added this class
to keep the architecture intact and also to reuse the buffer creation code:
Square= inherit(StageObject, function (){
superc(this);
this.geometry=new SquareGeometry();
this.materialFile="framebuffer";
});