Game Development Reference
In-Depth Information
Drawing our dart
Our dart will be a stretched version of the octahedron we rendered in our previous demo, using only two
colors, gold and blue.
...
octahedronVertexPositionBuffer = null,
octahedronVertexColorBuffer = null,
octahedronVertexIndexBuffer = null,
dartScale = .5,
dartWidth = .2 * dartScale
dartHeight = 2.0 * dartScale,
dartSkew = .5,
dart_x = 0.0,
dart_y = 0.0,
dart_z = 0.0,
dart_z_velocity = 0.0,
DART_START = [0.5, -0.5, -2.0],
...
We now have formally set variables for the dart properties. Next we initialize the dart buffer, as shown in
Listing 7-28.
Listing 7-28. Initializing the Dart Buffer
function initOctahedronBuffer(){
octahedronVertexPositionBuffer = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER, octahedronVertexPositionBuffer);
var vertices = [
// top faces
0.0, dartHeight, 0.0,
dartWidth, 0.0, dartWidth,
-dartWidth, 0.0, dartWidth,
0.0, dartHeight, 0.0,
dartWidth, 0.0, -dartWidth,
-dartWidth, 0.0, -dartWidth,
0.0, dartHeight, 0.0,
dartWidth, 0.0, dartWidth,
dartWidth, 0.0, -dartWidth,
0.0, dartHeight, 0.0,
-dartWidth, 0.0, dartWidth,
-dartWidth, 0.0, -dartWidth,
//bottom faces
0.0, -dartHeight * dartSkew, 0.0,
dartWidth, 0.0, dartWidth,
-dartWidth, 0.0, dartWidth,
0.0, -dartHeight * dartSkew, 0.0,
dartWidth, 0.0, -dartWidth,
 
Search WWH ::




Custom Search