the-world-engine
Version:
three.js based, unity like game engine for browser
45 lines (44 loc) • 1.17 kB
JavaScript
import { RayCastCallback, Vec2 } from "../../../box2d.ts/build/index";
export class RayCastOneCallback extends RayCastCallback {
ta;
ea=false;
sa=null;
$i=new Vec2;
aa=0;
ia=0;
ra=0;
static _tempVec2=new Vec2;
constructor(t) {
super();
this.ta = t;
}
setRaycastData(t, e, s, a, i) {
this.ea = false;
this.sa = t;
this.$i.Copy(e);
this.aa = s;
this.ia = a;
this.ra = i;
}
get hit() {
return this.ea;
}
ReportFixture(t, e, s, a) {
const i = t.GetUserData();
if (!this.ta.queriesHitTriggers && i.isTrigger) return -1;
const r = RayCastOneCallback._tempVec2.Copy(e).SelfSub(this.$i).Length();
if ((i.getThisOrRigidBodyLayer() & this.aa) === 0) return -1;
const _ = i.transform;
const c = _.position.z;
if (c < this.ia || this.ra < c) return -1;
this.sa.setData(e, i, r, a, s, e, t.GetBody().GetUserData().rigidbody, _);
this.ea = true;
return a;
}
ReportParticle() {
return -1;
}
ShouldQueryParticleSystem() {
return false;
}
}