refactor: physics restructuring
This commit is contained in:
parent
caf69e3333
commit
e0319c0d2f
39
packages/physics/dummy/body.js
Normal file
39
packages/physics/dummy/body.js
Normal file
|
@ -0,0 +1,39 @@
|
|||
import * as I from 'immutable';
|
||||
|
||||
import {compose} from '@avocado/core';
|
||||
import {Rectangle, Vector} from '@avocado/math';
|
||||
import {EventEmitter} from '@avocado/mixins';
|
||||
|
||||
const decorate = compose(
|
||||
EventEmitter,
|
||||
Vector.Mixin('position', 'x', 'y', {
|
||||
default: [0, 0],
|
||||
track: true,
|
||||
}),
|
||||
);
|
||||
|
||||
class BodyBase {
|
||||
|
||||
constructor(shape) {
|
||||
this.force = [0, 0];
|
||||
this.impulse = [0, 0];
|
||||
this.contacts = I.Set();
|
||||
this.shape = shape;
|
||||
}
|
||||
|
||||
get aabb() {
|
||||
return Rectangle.translated(this.shape.aabb, this.position);
|
||||
}
|
||||
|
||||
applyForce(vector) {
|
||||
this.force = Vector.add(this.force, vector);
|
||||
}
|
||||
|
||||
applyImpulse(vector) {
|
||||
this.impulse = Vector.add(this.impulse, vector);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export class Body extends decorate(BodyBase) {}
|
||||
|
|
@ -1,41 +1,9 @@
|
|||
import * as I from 'immutable';
|
||||
|
||||
import {arrayUnique, compose} from '@avocado/core';
|
||||
import {arrayUnique} from '@avocado/core';
|
||||
import {Rectangle, QuadTree, Vector} from '@avocado/math';
|
||||
import {EventEmitter} from '@avocado/mixins';
|
||||
|
||||
const decorate = compose(
|
||||
EventEmitter,
|
||||
Vector.Mixin('position', 'x', 'y', {
|
||||
default: [0, 0],
|
||||
track: true,
|
||||
}),
|
||||
);
|
||||
|
||||
class BodyBase {
|
||||
|
||||
constructor(shape) {
|
||||
this.force = [0, 0];
|
||||
this.impulse = [0, 0];
|
||||
this.contacts = I.Set();
|
||||
this.shape = shape;
|
||||
}
|
||||
|
||||
get aabb() {
|
||||
return Rectangle.translated(this.shape.aabb, this.position);
|
||||
}
|
||||
|
||||
applyForce(vector) {
|
||||
this.force = Vector.add(this.force, vector);
|
||||
}
|
||||
|
||||
applyImpulse(vector) {
|
||||
this.impulse = Vector.add(this.impulse, vector);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export class Body extends decorate(BodyBase) {}
|
||||
import {Body} from './body';
|
||||
|
||||
export class World {
|
||||
|
Loading…
Reference in New Issue
Block a user