|
1 | 1 | import {RawKinematicCharacterController, RawCharacterCollision} from "../raw"; |
2 | | -import {Rotation, Vector, VectorOps} from "../math"; |
| 2 | +import {Rotation, Vector, VectorOps, scratchBuffer} from "../math"; |
3 | 3 | import { |
4 | 4 | BroadPhase, |
5 | 5 | Collider, |
@@ -333,8 +333,9 @@ export class KinematicCharacterController { |
333 | 333 | /** |
334 | 334 | * The movement computed by the last call to `this.computeColliderMovement`. |
335 | 335 | */ |
336 | | - public computedMovement(): Vector { |
337 | | - return VectorOps.fromRaw(this.raw.computedMovement()); |
| 336 | + public computedMovement(target?: Vector): Vector { |
| 337 | + this.raw.computedMovement(scratchBuffer); |
| 338 | + return VectorOps.fromBuffer(scratchBuffer, target); |
338 | 339 | } |
339 | 340 |
|
340 | 341 | /** |
@@ -368,17 +369,25 @@ export class KinematicCharacterController { |
368 | 369 | } else { |
369 | 370 | let c = this.rawCharacterCollision; |
370 | 371 | out = out ?? new CharacterCollision(); |
371 | | - out.translationDeltaApplied = VectorOps.fromRaw( |
372 | | - c.translationDeltaApplied(), |
| 372 | + c.translationDeltaApplied(scratchBuffer); |
| 373 | + out.translationDeltaApplied = VectorOps.fromBuffer( |
| 374 | + scratchBuffer, |
| 375 | + out.translationDeltaApplied, |
373 | 376 | ); |
374 | | - out.translationDeltaRemaining = VectorOps.fromRaw( |
375 | | - c.translationDeltaRemaining(), |
| 377 | + c.translationDeltaRemaining(scratchBuffer); |
| 378 | + out.translationDeltaRemaining = VectorOps.fromBuffer( |
| 379 | + scratchBuffer, |
| 380 | + out.translationDeltaRemaining, |
376 | 381 | ); |
377 | 382 | out.toi = c.toi(); |
378 | | - out.witness1 = VectorOps.fromRaw(c.worldWitness1()); |
379 | | - out.witness2 = VectorOps.fromRaw(c.worldWitness2()); |
380 | | - out.normal1 = VectorOps.fromRaw(c.worldNormal1()); |
381 | | - out.normal2 = VectorOps.fromRaw(c.worldNormal2()); |
| 383 | + c.worldWitness1(scratchBuffer); |
| 384 | + out.witness1 = VectorOps.fromBuffer(scratchBuffer, out.witness1); |
| 385 | + c.worldWitness2(scratchBuffer); |
| 386 | + out.witness2 = VectorOps.fromBuffer(scratchBuffer, out.witness2); |
| 387 | + c.worldNormal1(scratchBuffer); |
| 388 | + out.normal1 = VectorOps.fromBuffer(scratchBuffer, out.normal1); |
| 389 | + c.worldNormal2(scratchBuffer); |
| 390 | + out.normal2 = VectorOps.fromBuffer(scratchBuffer, out.normal2); |
382 | 391 | out.collider = this.colliders.get(c.handle()); |
383 | 392 | return out; |
384 | 393 | } |
|
0 commit comments