Game Development Reference
In-Depth Information
The modifyGeometry function is a straightforward function. It takes the x and y
values based on the range of the x and y values and returns the z value from
25 to 0. Hence, the PlaneGeometry class uses this function to calculate the z value
of the vertices:
Plane.prototype.modifyGeometry=function(x,y){
if((x>=0&&x<100)&&(y>=0&&y<100)){
return 25;
}
else if((x>=100&&x<150)&&(y>=100&&y<150)){
return 20;
}
else if((x>=150&&x<200)&&(y>=150&&y<200)){
return 15;
}
else if((x>=200&&x<250)&&(y>=200&&y<250)){
return 10;
}
else if((x>=250&&x<300)&&(y>=250&&y<300)){
return 5;
}
else{
return 0;
}
}
Modifying a geometry is pretty straightforward, but informing the physics engine
of it is a bit of challenge. There is an existing class, jigLib.JTerrain ; its constructor
takes a parameter of the type ITerrain .
var Jterrain=function(tr)
The ITerrain interface is not implemented in JigLibJS; we will have to implement it.
Basically, the implementation of ITerrain informs the JigLib collision detection code
of the structure of the terrain. Let's first understand the ITerrain interface:
public interface ITerrain
{
//Min of coordinate horizontally;
function get_minW():Number;
//Min of coordinate vertically;
function get_minH():Number;
//Max of coordinate horizontally;
function get_maxW():Number;
//Max of coordinate vertically;
function get_maxH():Number;
 
Search WWH ::




Custom Search