Game Development Reference
In-Depth Information
return this._dw;
}
TerrainData.prototype.get_dh=function() {
return this._dh;
}
TerrainData.prototype.get_sw=function() {
return this._segmentsW;
}
TerrainData.prototype.get_sh=function() {
return this._segmentsH;
}
TerrainData.prototype.get_heights=function(i1,j1) {
return this.geomtery.getHeights(i1,j1);
}
TerrainData.prototype.get_maxHeight=function(){
return this._maxHeight;
}
The preceding class holds the complete information of the terrain, height,
width, segment information, and also the depth of each segment. We pass the
TerrainData
object to the physics engine and the engine checks for collisions
with the provided information.
Open
Plane.js
from
primitive/game
to see the use of the
TerrainData
object. We
have added a new function,
initializeRigidBody
. The following is a code snippet
from the
Plane.js
file:
Plane= inherit(StageObject, function (width, height,
widthOfSegments, heightOfSegments,textureName,modifyHeight){
...
this.geometry=new PlaneGeometry(width, height, widthOfSegments,
heightOfSegments,this.modifyGeometry);
...
});
The preceding code initializes the geometry, and it PlaneGeometry
constructor initializes the heights[[]] array.
Plane.prototype.initializeRigidBody=function(){
var pos=jigLib.Vector3DUtil.create( 0, 0,0,0 );
var matrix3D = new jigLib.Matrix3D();
matrix3D.appendRotation(0, jigLib.Vector3DUtil.X_AXIS);
var terrain=new TerrainData(this.width,
this.height,this.ws,this.wh,this.geometry);
this.rigidBody=new jigLib.JTerrain(terrain);
this.rigidBody.moveTo(pos);
this.rigidBody.setOrientation(matrix3D);
}