Adjusting mask of body,add note for interface (#4402)

This commit is contained in:
jiaxin.lai
2019-05-11 22:53:13 +08:00
committed by Weiliang Wang
parent 5e3eea8b56
commit eaa5edb199
5 changed files with 71 additions and 37 deletions
@@ -97,23 +97,6 @@ export class ColliderComponentBase extends PhysicsBasedComponent {
}
super.onDestroy();
}
public getGroup () {
return this._body!.getGroup();
}
public setGroup (v: number) {
return this._body!.setGroup(v);
}
public getMask () {
return this._body!.getMask();
}
public setMask (v: number) {
return this._body!.setMask(v);
}
}
@ccclass('cc.BoxColliderComponent')
@@ -46,6 +46,43 @@ export class PhysicsBasedComponent extends Component {
}
}
/**
* @return group ∈ [0, 31] (int)
*/
public getGroup (): number {
return this._body!.getGroup();
}
/**
* @param v ∈ [0, 31] (int)
*/
public setGroup (v: number) {
return this._body!.setGroup(v);
}
/**
* @return (int)
*/
public getMask (): number {
return this._body!.getMask();
}
/**
* this will reset the mask
* @param v ∈ [0, 31] (int)
*/
public setMask (v: number) {
return this._body!.setMask(v);
}
/**
* this will add a mask
* @param v ∈ [0, 31] (int)
*/
public addMask (v: number) {
return this._body!.addMask(v);
}
private _refSharedBody () {
if (this._sharedBody) {
return;
+12 -4
View File
@@ -64,15 +64,23 @@ export interface PhysicsWorldBase {
export interface RigidBodyBase {
// constructor (options?: ICreateBodyOptions);
/** group ∈ [0, 31] */
/** @return group ∈ [0, 31] (int) */
getGroup (): number;
/** group ∈ [0, 31] */
/** @param v ∈ [0, 31] (int) */
setGroup (v: number): void;
/** Mask ∈ [0, 31] */
/** @return (int) */
getMask (): number;
/** Mask ∈ [0, 31] */
/**
* this will reset the mask
* @param v ∈ [0, 31] (int)
*/
setMask (v: number): void;
/**
* this will add a mask
* @param v ∈ [0, 31] (int)
*/
addMask (v: number): void;
/** the body type */
getType (): ERigidBodyType;
+9 -6
View File
@@ -168,12 +168,12 @@ function fillRaycastResult (result: RaycastResult, cannonResult: CANNON.RaycastR
export class CannonRigidBody implements RigidBodyBase {
private _group: number = 0;
private _mask: number = 0;
get impl (): CANNON.Body {
return this._cannonBody;
}
private _group: number = 0;
private _mask: number = 0;
private _cannonBody: CANNON.Body;
private _velocityResult: Vec3 = new Vec3();
private _useGravity = true;
@@ -224,14 +224,17 @@ export class CannonRigidBody implements RigidBodyBase {
}
public getMask (): number {
return this._mask;
return this._cannonBody.collisionFilterMask;
}
public setMask (v: number): void {
this._mask = clamp(v, 0, 31);
v = clamp(Math.floor(v), 0, 31);
this._cannonBody.collisionFilterMask = 1 << v;
}
public addMask (v: number): void {
v = Math.floor(v);
this._cannonBody.collisionFilterMask += 1 << v;
}
public wakeUp (): void {
return this._cannonBody.wakeUp();
}
+13 -10
View File
@@ -10,21 +10,20 @@ import { BuiltInWorld } from './built-in-world';
* Built-in static collider, no physical forces involved
*/
export class BuiltInBody implements RigidBodyBase {
/** id generator */
private static idCounter: number = 0;
/** id unique */
public get id () { return this._id; }
public get collisionFilterGroup () { return this._collisionFilterGroup; }
public get collisionFilterMask () { return this._collisionFilterMask; }
/** id generator */
private static idCounter: number = 0;
private readonly _id: number;
private _type: ERigidBodyType = ERigidBodyType.DYNAMIC;
private _group: number = 0;
private _mask: number = 0;
public get collisionFilterGroup () { return this._collisionFilterGroup; }
private _collisionFilterGroup: number = 1 << 0;
public get collisionFilterMask () { return this._collisionFilterMask; }
private _collisionFilterMask: number = 1 << 0;
private _collisionCB: ICollisionCallback[] = [];
@@ -47,16 +46,20 @@ export class BuiltInBody implements RigidBodyBase {
return this._group;
}
public setGroup (v: number): void {
this._group = clamp(v, 0, 31);
this._group = clamp(Math.floor(v), 0, 31);
this._collisionFilterGroup = 1 << v;
}
public getMask (): number {
return this._mask;
return this._collisionFilterMask;
}
public setMask (v: number): void {
this._mask = clamp(v, 0, 31);
v = clamp(Math.floor(v), 0, 31);
this._collisionFilterMask = 1 << v;
}
public addMask (v: number): void {
v = clamp(Math.floor(v), 0, 31);
this._collisionFilterMask += 1 << v;
}
public intersects (body: BuiltInBody): boolean {
// tslint:disable-next-line: prefer-for-of
for (let i = 0; i < this._shapes.length; i++) {