Skip to content

Commit 308b918

Browse files
committed
refactor: opt code
1 parent 3d21a10 commit 308b918

File tree

3 files changed

+19
-19
lines changed

3 files changed

+19
-19
lines changed

packages/core/src/physics/Collision.ts

+13-13
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@ import { ICollision } from "@galacean/engine-design";
55
/**
66
* Describes a contact point where the collision occurs.
77
*/
8-
export interface ContractPoint {
8+
export interface ContactPoint {
99
/** The position of the contact point between the shapes, in world space. */
10-
position: Vector3;
10+
readonly position: Vector3;
1111
/** The normal of the contacting surfaces at the contact point. The normal direction points from the second shape to the first shape. */
12-
normal: Vector3;
12+
readonly normal: Vector3;
1313
/** The impulse applied at the contact point, in world space. Divide by the simulation time step to get a force value. */
14-
impulse: Vector3;
14+
readonly impulse: Vector3;
1515
/** The separation of the shapes at the contact point. A negative separation denotes a penetration. */
16-
separation: number;
16+
readonly separation: number;
1717
}
1818

1919
export class Collision {
@@ -32,22 +32,22 @@ export class Collision {
3232

3333
/**
3434
* Get contact points.
35-
* @param contacts - The result of contact points
35+
* @param outContacts - The result of contact points
3636
* @returns The result of contact points
3737
*/
38-
getContacts(contacts: ContractPoint[]): ContractPoint[] {
39-
const nativeContractPoints = this._nativeCollision.getContacts();
40-
for (let i = 0, n = nativeContractPoints.size(); i < n; i++) {
41-
const nativeContractPoint = nativeContractPoints.get(i);
38+
getContacts(outContacts: ContactPoint[]): ContactPoint[] {
39+
const nativeContactPoints = this._nativeCollision.getContacts();
40+
for (let i = 0, n = nativeContactPoints.size(); i < n; i++) {
41+
const nativeContractPoint = nativeContactPoints.get(i);
4242
const { position, normal, impulse, separation } = nativeContractPoint;
43-
const contact: ContractPoint = {
43+
const contact: ContactPoint = {
4444
position: new Vector3(position.x, position.y, position.z),
4545
normal: new Vector3(normal.x, normal.y, normal.z),
4646
impulse: new Vector3(impulse.x, impulse.y, impulse.z),
4747
separation: separation
4848
};
49-
contacts.push(contact);
49+
outContacts.push(contact);
5050
}
51-
return contacts;
51+
return outContacts;
5252
}
5353
}

packages/core/src/physics/shape/ColliderShape.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -138,20 +138,20 @@ export abstract class ColliderShape implements ICustomClone {
138138
/**
139139
* Get the distance and the closest point on the shape from a point.
140140
* @param point - The point
141-
* @param closestPoint - The closest point on the shape
141+
* @param outClosestPoint - The result of the closest point on the shape
142142
* @returns The distance between the point and the shape
143143
*/
144-
getDistanceAndClosestPointFromPoint(point: Vector3, closestPoint: Vector3): number {
144+
getDistanceAndClosestPointFromPoint(point: Vector3, outClosestPoint: Vector3): number {
145145
const tempQuat = ColliderShape._tempWorldRot;
146146
const tempPos = ColliderShape._tempWorldPos;
147147
Vector3.add(this._collider.entity.transform.position, this._position, tempPos);
148148
Quaternion.fromAngle(this._rotation, tempQuat);
149149
Quaternion.multiply(this._collider.entity.transform.rotationQuaternion, tempQuat, tempQuat);
150150
const res = this._nativeShape.pointDistance(tempPos, tempQuat, point);
151151
const distance = res.distance;
152-
closestPoint.copyFrom(res.closestPoint);
152+
outClosestPoint.copyFrom(res.closestPoint);
153153
if (distance > 0) {
154-
closestPoint.subtract(tempPos);
154+
outClosestPoint.subtract(tempPos);
155155
}
156156
return Math.sqrt(distance);
157157
}

packages/design/src/physics/ICollision.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ export interface ICollision {
1414

1515
interface PhysXVectorPxContactPairPoint {
1616
size(): number;
17-
get(index: number): IContractPoint;
17+
get(index: number): IContactPoint;
1818
}
1919

20-
interface IContractPoint {
20+
interface IContactPoint {
2121
position: {
2222
x: number;
2323
y: number;

0 commit comments

Comments
 (0)