Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 44 additions & 13 deletions src.ts/control/ray_cast_vehicle_controller.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {RawDynamicRayCastVehicleController} from "../raw";
import {Vector, VectorOps} from "../math";
import {scratchBuffer, Vector, VectorOps} from "../math";
import {
BroadPhase,
Collider,
Expand Down Expand Up @@ -163,11 +163,17 @@ export class DynamicRayCastVehicleController {
/*
* Getters + setters
*/

/**
* The position of the i-th wheel, relative to the chassis.
*
* @param {number} i
* @param {Vector?} target - The object to be populated. If provided,
* the function returns this object instead of creating a new one.
*/
public wheelChassisConnectionPointCs(i: number): Vector | null {
return VectorOps.fromRaw(this.raw.wheel_chassis_connection_point_cs(i));
public wheelChassisConnectionPointCs(i: number, target?: Vector): Vector | null {
const exists = this.raw.wheel_chassis_connection_point_cs(i, scratchBuffer);
return exists ? VectorOps.fromBuffer(scratchBuffer, target) : null;
}

/**
Expand Down Expand Up @@ -331,9 +337,14 @@ export class DynamicRayCastVehicleController {
* The direction of the i-th wheel’s suspension, relative to the chassis.
*
* The ray-casting will happen following this direction to detect the ground.
*
* @param {number} i
* @param {Vector?} target - The object to be populated. If provided,
* the function returns this object instead of creating a new one.
*/
public wheelDirectionCs(i: number): Vector | null {
return VectorOps.fromRaw(this.raw.wheel_direction_cs(i));
public wheelDirectionCs(i: number, target?: Vector): Vector | null {
const exists = this.raw.wheel_direction_cs(i, scratchBuffer);
return exists ? VectorOps.fromBuffer(scratchBuffer, target) : null;
}

/**
Expand All @@ -351,9 +362,14 @@ export class DynamicRayCastVehicleController {
* The i-th wheel’s axle axis, relative to the chassis.
*
* The axis index defined as 0 = X, 1 = Y, 2 = Z.
*
* @param {number} i
* @param {Vector?} target - The object to be populated. If provided,
* the function returns this object instead of creating a new one.
*/
public wheelAxleCs(i: number): Vector | null {
return VectorOps.fromRaw(this.raw.wheel_axle_cs(i));
public wheelAxleCs(i: number, target?: Vector): Vector | null {
const exists = this.raw.wheel_axle_cs(i, scratchBuffer);
return exists ? VectorOps.fromBuffer(scratchBuffer, target) : null;
}

/**
Expand Down Expand Up @@ -439,16 +455,26 @@ export class DynamicRayCastVehicleController {

/**
* The (world-space) contact normal between the i-th wheel and the floor.
*
* @param {number} i
* @param {Vector?} target - The object to be populated. If provided,
* the function returns this object instead of creating a new one.
*/
public wheelContactNormal(i: number): Vector | null {
return VectorOps.fromRaw(this.raw.wheel_contact_normal_ws(i));
public wheelContactNormal(i: number, target?: Vector): Vector | null {
const exists = this.raw.wheel_contact_normal_ws(i, scratchBuffer);
return exists ? VectorOps.fromBuffer(scratchBuffer, target) : null;
}

/**
* The (world-space) point hit by the wheel’s ray-cast for the i-th wheel.
*
* @param {number} i
* @param {Vector?} target - The object to be populated. If provided,
* the function returns this object instead of creating a new one.
*/
public wheelContactPoint(i: number): Vector | null {
return VectorOps.fromRaw(this.raw.wheel_contact_point_ws(i));
public wheelContactPoint(i: number, target?: Vector): Vector | null {
const exists = this.raw.wheel_contact_point_ws(i, scratchBuffer);
return exists ? VectorOps.fromBuffer(scratchBuffer, target) : null;
}

/**
Expand All @@ -460,9 +486,14 @@ export class DynamicRayCastVehicleController {

/**
* The (world-space) starting point of the ray-cast for the i-th wheel.
*
* @param {number} i
* @param {Vector?} target - The object to be populated. If provided,
* the function returns this object instead of creating a new one.
*/
public wheelHardPoint(i: number): Vector | null {
return VectorOps.fromRaw(this.raw.wheel_hard_point_ws(i));
public wheelHardPoint(i: number, target?: Vector): Vector | null {
const exists = this.raw.wheel_hard_point_ws(i, scratchBuffer);
return exists ? VectorOps.fromBuffer(scratchBuffer, target) : null;
}

/**
Expand Down
34 changes: 25 additions & 9 deletions src.ts/dynamics/impulse_joint.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Rotation, Vector, VectorOps, RotationOps} from "../math";
import {Rotation, Vector, VectorOps, RotationOps, scratchBuffer} from "../math";
import {
RawGenericJoint,
RawImpulseJointSet,
Expand Down Expand Up @@ -149,19 +149,27 @@ export class ImpulseJoint {
// #if DIM3
/**
* The rotation quaternion that aligns this joint's first local axis to the `x` axis.
*
* @param {Rotation?} target - The object to be populated. If provided,
* the function returns this object instead of creating a new one.
*/
public frameX1(): Rotation {
return RotationOps.fromRaw(this.rawSet.jointFrameX1(this.handle));
public frameX1(target?: Rotation): Rotation {
this.rawSet.jointFrameX1(this.handle, scratchBuffer);
return RotationOps.fromBuffer(scratchBuffer, target);
}

// #endif

// #if DIM3
/**
* The rotation matrix that aligns this joint's second local axis to the `x` axis.
*
* @param {Rotation?} target - The object to be populated. If provided,
* the function returns this object instead of creating a new one.
*/
public frameX2(): Rotation {
return RotationOps.fromRaw(this.rawSet.jointFrameX2(this.handle));
public frameX2(target?: Rotation): Rotation {
this.rawSet.jointFrameX2(this.handle, scratchBuffer);
return RotationOps.fromBuffer(scratchBuffer, target);
}

// #endif
Expand All @@ -171,19 +179,27 @@ export class ImpulseJoint {
*
* The first anchor gives the position of the application point on the
* local frame of the first rigid-body it is attached to.
*
* @param {Vector?} target - The object to be populated. If provided,
* the function returns this object instead of creating a new one.
*/
public anchor1(): Vector {
return VectorOps.fromRaw(this.rawSet.jointAnchor1(this.handle));
public anchor1(target?: Vector): Vector {
this.rawSet.jointAnchor1(this.handle, scratchBuffer);
return RotationOps.fromBuffer(scratchBuffer, target);
}

/**
* The position of the second anchor of this joint.
*
* The second anchor gives the position of the application point on the
* local frame of the second rigid-body it is attached to.
*
* @param {Vector?} target - The object to be populated. If provided,
* the function returns this object instead of creating a new one.
*/
public anchor2(): Vector {
return VectorOps.fromRaw(this.rawSet.jointAnchor2(this.handle));
public anchor2(target?: Vector): Vector {
this.rawSet.jointAnchor2(this.handle, scratchBuffer);
return RotationOps.fromBuffer(scratchBuffer, target);
}

/**
Expand Down
Loading