MCPcopy
hub / github.com/piqnt/planck.js / runRayCast

Function runRayCast

example/DynamicTreeTest.ts:86–123  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

84}
85
86function runRayCast() {
87 rayCastResult.actor = null;
88 rayCastResult.output = null;
89
90 rayCastResult.input = {
91 p1: Vec2.clone(rayCastInput.p1),
92 p2: Vec2.clone(rayCastInput.p2),
93 maxFraction: rayCastInput.maxFraction,
94 };
95
96 // Ray cast against the dynamic tree.
97 tree.rayCast(rayCastResult.input, rayCastCallback);
98
99 // Brute force ray cast.
100 let bruteActor: Actor | null = null;
101 let bruteOutput: RayCastOutput | null = null;
102
103 for (let i = 0; i < actors.length; ++i) {
104 const actor = actors[i];
105 if (actor.proxyId == null) {
106 continue;
107 }
108
109 const output = {} as RayCastOutput;
110 const hit = actor.aabb.rayCast(output, rayCastResult.input);
111 if (hit) {
112 bruteActor = actor;
113 bruteOutput = output;
114 rayCastResult.input.maxFraction = output.fraction;
115 }
116 }
117
118 if (bruteActor != null) {
119 // console.assert(bruteOutput?.fraction == rayCastOutput.fraction);
120 }
121
122 return rayCastResult;
123}
124
125testbed.step = function () {
126 for (let i = 0; i < actors.length; ++i) {

Callers 1

DynamicTreeTest.tsFile · 0.85

Calls 2

cloneMethod · 0.45
rayCastMethod · 0.45

Tested by

no test coverage detected