Add physics interface api document (#4593)

This commit is contained in:
jiaxin.lai
2019-06-12 11:11:46 +08:00
committed by Weiliang Wang
parent babb37de50
commit 3359c9a30f
5 changed files with 138 additions and 31 deletions
@@ -47,14 +47,20 @@ export class BoxColliderComponent extends ColliderComponent {
/// PUBLIC PROPERTY GETTER\SETTER ///
/**
* The size of the box, in local space.
* @note Shall not specify size with component 0.
* @en
* Get the size of the box, in local space.
* @zh
* 获取盒的大小
*/
@property({ type: Vec3 })
public get size () {
return this._size;
}
/**
* @zh
* 设置盒的大小
*/
public set size (value) {
vec3.copy(this._size, value);
@@ -1,7 +1,5 @@
import {
ccclass,
property,
} from '../../../../core/data/class-decorator';
import { EventTarget } from '../../../../core';
import { ccclass, property } from '../../../../core/data/class-decorator';
import { CallbacksInvoker, ICallbackTable } from '../../../../core/event/callbacks-invoker';
import { applyMixins, IEventTarget } from '../../../../core/event/event-target-factory';
import { createMap } from '../../../../core/utils/js';
@@ -39,7 +37,11 @@ export class ColliderComponent extends PhysicsBasedComponent implements IEventTa
}
/**
* The center of the collider, in local space.
* @en
* get the center of the collider, in local space.
* @zh
* 获取碰撞器的中心点
*
*/
@property({
type: Vec3,
@@ -50,6 +52,10 @@ export class ColliderComponent extends PhysicsBasedComponent implements IEventTa
return this._center;
}
/**
* @zh
* 设置碰撞器的中心点
*/
public set center (value: Vec3) {
vec3.copy(this._center, value);
@@ -88,7 +94,7 @@ export class ColliderComponent extends PhysicsBasedComponent implements IEventTa
* @param target - 可选参数,执行回调函数的目标
* @param useCapture - 可选参数,当设置为 true,监听器将在捕获阶段触发,否则将在冒泡阶段触发。默认为 false。
*/
public on (type: CollisionEventType, callback: CollisionCallback, target?: Object, useCapture?: any): any{
public on (type: CollisionEventType, callback: CollisionCallback, target?: Object, useCapture?: any): any {
}
/**
@@ -125,6 +131,7 @@ export class ColliderComponent extends PhysicsBasedComponent implements IEventTa
public hasEventListener (key: CollisionEventType, callback?: CollisionCallback, target?: Object): boolean {
return false;
}
public removeAll (keyOrTarget?: CollisionEventType | Object): void {
}
@@ -43,13 +43,20 @@ export class SphereColliderComponent extends ColliderComponent {
/// PUBLIC PROPERTY GETTER\SETTER ///
/**
* The radius of the sphere.
* @en
* Get the radius of the sphere.
* @zh
* 获取球的半径
*/
@property
public get radius () {
return this._radius;
}
/**
* @zh
* 设置球的半径
*/
public set radius (value) {
this._radius = value;
@@ -11,14 +11,27 @@ export class PhysicsSystem {
this._world = createPhysicsWorld();
}
/**
* @zh
* 设置是否只运行一步
* @param b - 布尔值
*/
public setSingleStep (b: boolean) {
this._singleStep = b;
}
/**
* @zh
* 继续
*/
public resume () {
this._paused = false;
}
/**
* @zh
* 暂停
*/
public pause () {
this._paused = true;
}
@@ -42,6 +42,10 @@ export class RigidBodyComponent extends PhysicsBasedComponent {
// // }
// }
/**
* @zh
* 获取刚体的质量
*/
@property({
displayOrder: 0,
})
@@ -49,6 +53,10 @@ export class RigidBodyComponent extends PhysicsBasedComponent {
return this._mass;
}
/**
* @zh
* 设置刚体的质量
*/
public set mass (value) {
this._mass = value;
if (!CC_EDITOR && !CC_PHYSICS_BUILT_IN) {
@@ -56,6 +64,10 @@ export class RigidBodyComponent extends PhysicsBasedComponent {
}
}
/**
* @zh
* 获取线性阻尼
*/
@property({
displayOrder: 1,
})
@@ -63,6 +75,10 @@ export class RigidBodyComponent extends PhysicsBasedComponent {
return this._linearDamping;
}
/**
* @zh
* 设置线性阻尼
*/
public set linearDamping (value) {
this._linearDamping = value;
if (!CC_EDITOR && !CC_PHYSICS_BUILT_IN) {
@@ -70,6 +86,10 @@ export class RigidBodyComponent extends PhysicsBasedComponent {
}
}
/**
* @zh
* 获取角阻尼
*/
@property({
displayOrder: 2,
})
@@ -77,6 +97,10 @@ export class RigidBodyComponent extends PhysicsBasedComponent {
return this._angularDamping;
}
/**
* @zh
* 设置角阻尼
*/
public set angularDamping (value) {
this._angularDamping = value;
if (!CC_EDITOR && !CC_PHYSICS_BUILT_IN) {
@@ -84,6 +108,10 @@ export class RigidBodyComponent extends PhysicsBasedComponent {
}
}
/**
* @zh
* 获取刚体是否由物理系统控制运动
*/
@property({
displayOrder: 3,
})
@@ -91,6 +119,10 @@ export class RigidBodyComponent extends PhysicsBasedComponent {
return this._isKinematic;
}
/**
* @zh
* 设置刚体是否由自己控制运动
*/
public set isKinematic (value) {
this._isKinematic = value;
if (!CC_EDITOR && !CC_PHYSICS_BUILT_IN) {
@@ -98,6 +130,10 @@ export class RigidBodyComponent extends PhysicsBasedComponent {
}
}
/**
* @zh
* 获取刚体是否使用重力
*/
@property({
displayOrder: 4,
})
@@ -105,6 +141,10 @@ export class RigidBodyComponent extends PhysicsBasedComponent {
return this._useGravity;
}
/**
* @zh
* 设置刚体是否使用重力
*/
public set useGravity (value) {
this._useGravity = value;
if (!CC_EDITOR && !CC_PHYSICS_BUILT_IN) {
@@ -112,6 +152,10 @@ export class RigidBodyComponent extends PhysicsBasedComponent {
}
}
/**
* @zh
* 获取刚体是否固定旋转
*/
@property({
displayOrder: 5,
})
@@ -119,6 +163,10 @@ export class RigidBodyComponent extends PhysicsBasedComponent {
return this._fixedRotation;
}
/**
* @zh
* 设置刚体是否固定旋转
*/
public set fixedRotation (value) {
this._fixedRotation = value;
if (!CC_EDITOR && !CC_PHYSICS_BUILT_IN) {
@@ -128,27 +176,27 @@ export class RigidBodyComponent extends PhysicsBasedComponent {
/// PUBLIC GETTER\SETTER ///
public get isTrigger () {
return this._isTrigger;
}
// public get isTrigger () {
// return this._isTrigger;
// }
public set isTrigger (value) {
this._isTrigger = value;
if (!CC_EDITOR && !CC_PHYSICS_BUILT_IN) {
this._body.setIsTrigger(value);
}
}
// public set isTrigger (value) {
// this._isTrigger = value;
// if (!CC_EDITOR && !CC_PHYSICS_BUILT_IN) {
// this._body.setIsTrigger(value);
// }
// }
public get velocity () {
return this._velocity;
}
// public get velocity () {
// return this._velocity;
// }
public set velocity (value: Vec3) {
vec3.copy(this._velocity, value);
if (!CC_EDITOR && !CC_PHYSICS_BUILT_IN) {
this._body.setVelocity(this._velocity);
}
}
// public set velocity (value: Vec3) {
// vec3.copy(this._velocity, value);
// if (!CC_EDITOR && !CC_PHYSICS_BUILT_IN) {
// this._body.setVelocity(this._velocity);
// }
// }
/// PRIVATE PROPERTY ///
@@ -167,8 +215,8 @@ export class RigidBodyComponent extends PhysicsBasedComponent {
@property
private _fixedRotation: boolean = false;
@property
private _isTrigger: boolean = false;
// @property
// private _isTrigger: boolean = false;
@property
private _isKinematic: boolean = false;
@@ -176,7 +224,7 @@ export class RigidBodyComponent extends PhysicsBasedComponent {
@property
private _useGravity: boolean = true;
private _velocity: Vec3 = new Vec3();
// private _velocity: Vec3 = new Vec3();
constructor () {
super();
@@ -184,30 +232,56 @@ export class RigidBodyComponent extends PhysicsBasedComponent {
/// PUBLIC METHOD ///
/**
* @zh
* 在某点上对刚体施加一个作用力
* @param force - 作用力
* @param position - 作用点
*/
public applyForce (force: Vec3, position?: Vec3) {
if (!CC_PHYSICS_BUILT_IN && this._assertPreload) {
this._body!.applyForce(force, position);
}
}
/**
* @zh
* 在某点上对刚体施加一个冲量
* @param impulse - 冲量
* @param position - 作用点
*/
public applyImpulse (impulse: Vec3, position?: Vec3) {
if (!CC_PHYSICS_BUILT_IN && this._assertPreload) {
this._body!.applyImpulse(impulse, position);
}
}
/**
* @zh
* 唤醒刚体
*/
public wakeUp () {
if (!CC_PHYSICS_BUILT_IN && this._assertPreload) {
this._body!.wakeUp();
}
}
/**
* @zh
* 休眠刚体
*/
public sleep () {
if (!CC_PHYSICS_BUILT_IN && this._assertPreload) {
this._body!.sleep();
}
}
/**
* @zh
* 直接设置碰撞分组和掩码值
* @param group - 分组值
* @param mask - 掩码值
*/
public setCollisionFilter (group: number, mask: number) {
if (!CC_PHYSICS_BUILT_IN && this._assertPreload) {
this._body!.setCollisionFilter(group, mask);
@@ -229,7 +303,7 @@ export class RigidBodyComponent extends PhysicsBasedComponent {
this.angularDamping = this._angularDamping;
// this.material = this._material;
this.useGravity = this._useGravity;
this.velocity = this._velocity;
// this.velocity = this._velocity;
this.isKinematic = this._isKinematic;
this.fixedRotation = this._fixedRotation;
}