UNPKG

the-world-engine

Version:

three.js based, unity like game engine for browser

72 lines (70 loc) 1.65 kB
import { Vector2 } from "three/src/Three"; import { Vec2 } from "../../../box2d.ts/build/index"; export class ContactPoint2D { di=null; pi=null; Ci=null; vi=null; bi=null; Vi=new Vector2; gr=new Vector2; mr=new Vector2; vr=0; Vr=0; yr=0; setData(t, e, r, i, n, o) { this.di = t; const s = t.GetFixtureA(); const l = t.GetFixtureB(); this.pi = s.GetUserData(); this.Ci = s.GetBody().GetUserData().rigidbody; this.vi = l.GetUserData(); this.bi = l.GetBody().GetUserData().rigidbody; if (o) { this.Vi.copy(o); } else { const t = ContactPoint2D._tempVec.Copy(s.GetBody().GetLinearVelocity()); const e = t.SelfSub(l.GetBody().GetLinearVelocity()); this.Vi.set(e.x, e.y); } this.gr.set(i.x, i.y); this.mr.set(r.x, r.y); this.vr = e.normalImpulse; this.Vr = e.tangentImpulse; this.yr = n; } static _tempVec=new Vec2; get enabled() { return this.di?.IsEnabled() ?? false; } get collider() { return this.pi; } get rigidbody() { return this.Ci; } get otherCollider() { return this.vi; } get otherRigidbody() { return this.bi; } get relativeVelocity() { return this.Vi; } get point() { return this.gr; } get normal() { return this.mr; } get normalImpulse() { return this.vr; } get tangentImpulse() { return this.Vr; } get separation() { return this.yr; } }