移除物理引擎
This commit is contained in:
@@ -6710,183 +6710,6 @@ var es;
|
||||
}());
|
||||
es.ShapeCollisions = ShapeCollisions;
|
||||
})(es || (es = {}));
|
||||
var es;
|
||||
(function (es) {
|
||||
var Particle = (function () {
|
||||
function Particle() {
|
||||
this.mass = 1;
|
||||
this.radius = 0;
|
||||
this.collidesWithColliders = true;
|
||||
}
|
||||
Particle.prototype.applyForce = function (force) {
|
||||
this.acceleration.add(es.Vector2.divide(force, new es.Vector2(this.mass)));
|
||||
};
|
||||
return Particle;
|
||||
}());
|
||||
es.Particle = Particle;
|
||||
})(es || (es = {}));
|
||||
var es;
|
||||
(function (es) {
|
||||
var VerletWorld = (function () {
|
||||
function VerletWorld(simulationBounds) {
|
||||
if (simulationBounds === void 0) { simulationBounds = null; }
|
||||
this.gravity = new es.Vector2(0, 980);
|
||||
this.constraintIterations = 3;
|
||||
this.maximumStepIterations = 5;
|
||||
this.allowDragging = true;
|
||||
this._composites = [];
|
||||
this._tempCircle = new es.Circle(1);
|
||||
this._leftOverTime = 0;
|
||||
this._fixedDeltaTime = 1 / 60;
|
||||
this._iterationSteps = 0;
|
||||
this._fixedDeltaTimeSq = 0;
|
||||
this.simulationBounds = simulationBounds;
|
||||
this._fixedDeltaTimeSq = Math.pow(this._fixedDeltaTimeSq, 2);
|
||||
}
|
||||
VerletWorld.prototype.update = function () {
|
||||
this.updateTiming();
|
||||
if (this.allowDragging)
|
||||
this.handleDragging();
|
||||
for (var iteration = 1; iteration <= this._iterationSteps; iteration++) {
|
||||
for (var i = this._composites.length - 1; i >= 0; i--) {
|
||||
var composite = this._composites[i];
|
||||
for (var s = 0; s < this.constraintIterations; s++)
|
||||
composite.solveConstraints();
|
||||
composite.updateParticles(this._fixedDeltaTimeSq, this.gravity);
|
||||
composite.handleConstraintCollisions();
|
||||
for (var j = 0; j < composite.particles.length; j++) {
|
||||
var p = composite.particles[j];
|
||||
if (this.simulationBounds) {
|
||||
this.constrainParticleToBounds(p);
|
||||
}
|
||||
if (p.collidesWithColliders)
|
||||
this.handleCollisions(p, composite.collidesWithLayers);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
VerletWorld.prototype.handleCollisions = function (p, collidesWithLayers) {
|
||||
var collidedCount = es.Physics.overlapCircleAll(p.position, p.radius, VerletWorld._colliders, collidesWithLayers);
|
||||
for (var i = 0; i < collidedCount; i++) {
|
||||
var collider = VerletWorld._colliders[i];
|
||||
if (collider.isTrigger)
|
||||
continue;
|
||||
var collisionResult = new es.CollisionResult();
|
||||
if (p.radius < 2) {
|
||||
if (collider.shape.pointCollidesWithShape(p.position, collisionResult)) {
|
||||
p.position.subtract(collisionResult.minimumTranslationVector);
|
||||
}
|
||||
}
|
||||
else {
|
||||
this._tempCircle.radius = p.radius;
|
||||
this._tempCircle.position = p.position;
|
||||
if (this._tempCircle.collidesWithShape(collider.shape, collisionResult)) {
|
||||
p.position.subtract(collisionResult.minimumTranslationVector);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
VerletWorld.prototype.constrainParticleToBounds = function (p) {
|
||||
var tempPos = p.position;
|
||||
var bounds = this.simulationBounds;
|
||||
if (p.radius == 0) {
|
||||
if (tempPos.y > bounds.height)
|
||||
tempPos.y = bounds.height;
|
||||
else if (tempPos.y < bounds.y)
|
||||
tempPos.y = bounds.y;
|
||||
if (tempPos.x < bounds.x)
|
||||
tempPos.x = bounds.x;
|
||||
else if (tempPos.x > bounds.width)
|
||||
tempPos.x = bounds.width;
|
||||
}
|
||||
else {
|
||||
if (tempPos.y < bounds.y + p.radius)
|
||||
tempPos.y = 2 * (bounds.y + p.radius) - tempPos.y;
|
||||
if (tempPos.y > bounds.height - p.radius)
|
||||
tempPos.y = 2 * (bounds.height - p.radius) - tempPos.y;
|
||||
if (tempPos.x > bounds.width - p.radius)
|
||||
tempPos.x = 2 * (bounds.width - p.radius) - tempPos.x;
|
||||
if (tempPos.x < bounds.x + p.radius)
|
||||
tempPos.x = 2 * (bounds.x + p.radius) - tempPos.x;
|
||||
}
|
||||
p.position = tempPos;
|
||||
};
|
||||
VerletWorld.prototype.updateTiming = function () {
|
||||
this._leftOverTime += es.Time.deltaTime;
|
||||
this._iterationSteps = Math.floor(Math.trunc(this._leftOverTime / this._fixedDeltaTime));
|
||||
this._leftOverTime -= this._iterationSteps * this._fixedDeltaTime;
|
||||
this._iterationSteps = Math.min(this._iterationSteps, this.maximumStepIterations);
|
||||
};
|
||||
VerletWorld.prototype.addComposite = function (composite) {
|
||||
this._composites.push(composite);
|
||||
return composite;
|
||||
};
|
||||
VerletWorld.prototype.removeComposite = function (composite) {
|
||||
this._composites.remove(composite);
|
||||
};
|
||||
VerletWorld.prototype.handleDragging = function () {
|
||||
};
|
||||
VerletWorld.prototype.debugRender = function (camera) {
|
||||
for (var i = 0; i < this._composites.length; i++)
|
||||
this._composites[i].debugRender(camera);
|
||||
};
|
||||
VerletWorld._colliders = new Array(4);
|
||||
return VerletWorld;
|
||||
}());
|
||||
es.VerletWorld = VerletWorld;
|
||||
})(es || (es = {}));
|
||||
var es;
|
||||
(function (es) {
|
||||
var Composite = (function () {
|
||||
function Composite() {
|
||||
this.friction = new es.Vector2(0.98, 1);
|
||||
this.collidesWithLayers = es.Physics.allLayers;
|
||||
this.particles = [];
|
||||
this._constraints = [];
|
||||
}
|
||||
Composite.prototype.solveConstraints = function () {
|
||||
for (var i = this._constraints.length - 1; i >= 0; i--) {
|
||||
this._constraints[i].solve();
|
||||
}
|
||||
};
|
||||
Composite.prototype.updateParticles = function (deltaTimeSquared, gravity) {
|
||||
for (var j = 0; j < this.particles.length; j++) {
|
||||
var p = this.particles[j];
|
||||
if (p.isPinned) {
|
||||
p.position = p.pinnedPosition;
|
||||
continue;
|
||||
}
|
||||
p.applyForce(es.Vector2.multiply(new es.Vector2(p.mass), gravity));
|
||||
var vel = es.Vector2.subtract(p.position, p.lastPosition).multiply(this.friction);
|
||||
var nextPos = es.Vector2.add(p.position, vel).add(es.Vector2.multiply(new es.Vector2(0.5 * deltaTimeSquared), p.acceleration));
|
||||
p.lastPosition = p.position;
|
||||
p.position = nextPos;
|
||||
p.acceleration.x = p.acceleration.y = 0;
|
||||
}
|
||||
};
|
||||
Composite.prototype.handleConstraintCollisions = function () {
|
||||
for (var i = this._constraints.length - 1; i >= 0; i--) {
|
||||
if (this._constraints[i].collidesWithColliders)
|
||||
this._constraints[i].handleCollisions(this.collidesWithLayers);
|
||||
}
|
||||
};
|
||||
Composite.prototype.debugRender = function (camera) {
|
||||
};
|
||||
return Composite;
|
||||
}());
|
||||
es.Composite = Composite;
|
||||
})(es || (es = {}));
|
||||
var es;
|
||||
(function (es) {
|
||||
var Constraint = (function () {
|
||||
function Constraint() {
|
||||
this.collidesWithColliders = true;
|
||||
}
|
||||
Constraint.prototype.handleCollisions = function (collidesWithLayers) { };
|
||||
return Constraint;
|
||||
}());
|
||||
es.Constraint = Constraint;
|
||||
})(es || (es = {}));
|
||||
var ArrayUtils = (function () {
|
||||
function ArrayUtils() {
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user