新增shape形状
This commit is contained in:
@@ -5,6 +5,8 @@ class Composite {
|
||||
public drawParticles: boolean = true;
|
||||
public drawConstraints: boolean = true;
|
||||
public particles: Particle[] = [];
|
||||
public collidesWithLayers = -1;
|
||||
|
||||
/**
|
||||
* 处理解决所有约束条件
|
||||
*/
|
||||
@@ -48,6 +50,13 @@ class Composite {
|
||||
}
|
||||
}
|
||||
|
||||
public handleConstraintCollisions(){
|
||||
for (let i = this._constraints.length - 1; i >= 0; i --){
|
||||
if (this._constraints[i].collidesWithColliders)
|
||||
this._constraints[i].handleCollisions(this.collidesWithLayers);
|
||||
}
|
||||
}
|
||||
|
||||
public debugRender(graphics: egret.Graphics){
|
||||
if (this.drawConstraints){
|
||||
for (let i = 0; i < this._constraints.length; i ++){
|
||||
|
||||
@@ -4,5 +4,9 @@ abstract class Constraint {
|
||||
|
||||
public abstract solve();
|
||||
|
||||
public handleCollisions(collidesWithLayers: number){
|
||||
|
||||
}
|
||||
|
||||
public debugRender(graphics: egret.Graphics) {}
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
///<reference path="../../Shapes/Polygon.ts"/>
|
||||
class DistanceConstraint extends Constraint {
|
||||
public stiffness: number = 0;
|
||||
public restingDistance: number = 0;
|
||||
@@ -5,6 +6,7 @@ class DistanceConstraint extends Constraint {
|
||||
|
||||
private _particleOne: Particle;
|
||||
private _particleTwo: Particle;
|
||||
private static _polygon = new Polygon(2, 1);
|
||||
|
||||
constructor(first: Particle, second: Particle, stiffness: number, distance = -1){
|
||||
super();
|
||||
@@ -25,6 +27,14 @@ class DistanceConstraint extends Constraint {
|
||||
return this;
|
||||
}
|
||||
|
||||
public handleCollisions(collidersWithLayers){
|
||||
let minX = Math.min(this._particleOne.position.x, this._particleTwo.position.x);
|
||||
let maxX = Math.max(this._particleOne.position.x, this._particleTwo.position.x);
|
||||
let minY = Math.min(this._particleOne.position.y, this._particleTwo.position.y);
|
||||
let maxY = Math.max(this._particleOne.position.y, this._particleTwo.position.y);
|
||||
// DistanceConstraint._polygon.bounds = Rectangle.
|
||||
}
|
||||
|
||||
public solve() {
|
||||
let diff = Vector2.subtract(this._particleOne.position, this._particleTwo.position);
|
||||
let d = diff.length();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* 基于verlet 物理引擎进行改造的物理引擎 ts重写
|
||||
* 基于verlet进行改造的物理引擎 ts重写
|
||||
* https://github.com/subprotocol/verlet-js
|
||||
*/
|
||||
class VerletWorld {
|
||||
@@ -34,6 +34,8 @@ class VerletWorld {
|
||||
|
||||
composite.updateParticles(this._fixedDeltaTimeSq, this.gravity);
|
||||
|
||||
composite.handleConstraintCollisions();
|
||||
|
||||
for (let j = 0; j < composite.particles.length; j ++){
|
||||
let p = composite.particles[j];
|
||||
|
||||
|
||||
Reference in New Issue
Block a user