



mapTable = {
id: 'id',
position: ['x', 'y'],
velocity: ['vx', 'vy'],
mass: 'm',
angle: 'rotZ'
}
Improvements
It is possible to select different space model gravitation in scenario.xml. This value will be used during creating P2 world on simulationInitialize AOR event (please see ../Physics2D/script).
Code example:
...this.simulationInitialize = function (initialState) { this.state = initialState; this.spaceModel = initialState.spaceModel; this.gravity = this.spaceModel.gravity ? -this.spaceModel.gravity : -9.81; this.world = new p2.World({gravity: [0, this.gravity]});...
Default gravitation value is -9.81
Improvements
AOR Simulation Framework supports different kinds of object shapes. E.g. Rectangle, Circle, Polygon.
It is possible now to create corresponded P2 shapes.
Supported shapes are:
Additionally, Plane is supported in P2 as well, but it requires AOR xml scheme improvements. Now physical engine takes the name of the AOR object and if it is equal to 'Plane' creates Plane P2 shape.
Improvements
Code example (../Physics2d/script):
this.createP2Shape = function (object) {
var name = object.name,
width = object.width,
height = object.height,
type = this.getShapeType(object.shape2D),
shape = new p2[type](width, height);
// create Plane shape if the name of the object equal to "Plane"
if (object.name === 'Plane') {
shape = new p2.Plane();
}
// NOTE: now for Rectangle, Circle and Plane only
this.p2shapes.push(shape);
};
Improvements
Each AOR PhysicalAgent can have perception properties such as:
Improvements
this.createP2Shape = function (object) {
...
// create sensor shape if perception is presented
if (object.perceptionRadius) {
shape.sensor = true;
shape.boundingRadius = object.perceptionRadius;
shape.perceptionAngle = object.perceptionAngle;
}
...
};Improvements
this.world.on('postBroadphase', this.postBroadphaseCallBack.bind(this));Improvements
var sensorBody = data.pairs[1],
sensorShape = sensorBody.shapes[0],
sensorPerceptionRadius = sensorShape.boundingRadius,
sensorPerceptionAngle = sensorShape.perceptionAngle < 180 ?
sensorShape.perceptionAngle :
180,
sensorPerceptionAngleRad = sensorPerceptionAngle * (Math.PI / 180),
sensorX = sensorBody.position[0],
sensorY = sensorBody.position[1],
sensorSectorLeftBorder = sensorX - Math.sin(sensorPerceptionAngleRad / 2) * sensorPerceptionRadius,
sensorSectorRightBorder = sensorX + Math.sin(sensorPerceptionAngleRad / 2) * sensorPerceptionRadius,
collisionTargetBody = data.pairs[0],
collisionTargetShape = collisionTargetBody.shapes[0],
targetBoundingRadius = collisionTargetShape.boundingRadius,
targetX = collisionTargetBody.position[0],
targetY = collisionTargetBody.position[1],
collisionX =
((sensorX * targetBoundingRadius) +
(targetX * sensorPerceptionRadius)) /
(sensorPerceptionRadius + targetBoundingRadius),
collisionY =
((sensorY * targetBoundingRadius) +
(targetY * sensorPerceptionRadius)) /
(sensorPerceptionRadius + targetBoundingRadius);
if (collisionX > sensorSectorLeftBorder &&
collisionX < sensorSectorRightBorder &&
collisionY < sensorY){
sensorShape.sensor = false;
} else {
sensorShape.sensor = true;
}