Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

provides world position that are converted to up,right,forward direction #6287

Merged
merged 8 commits into from Mar 20, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
94 changes: 59 additions & 35 deletions cocos2d/core/CCNode.js
Expand Up @@ -49,7 +49,6 @@ var emptyFunc = function () {};

// getWorldPosition temp var
var _gwpVec3 = new Vec3();

var _gwpQuat = new Quat();

// _invTransformPoint temp var
Expand Down Expand Up @@ -80,7 +79,7 @@ var _laQuat = new Quat();
//up、right、forward temp var
var _uVec3 = new Vec3();
var _rVec3 = new Vec3();
var _fVec3 = new vec3();
var _fVec3 = new Vec3();
jareguo marked this conversation as resolved.
Show resolved Hide resolved

// _hitTest temp var
var _htVec3a = new Vec3();
Expand Down Expand Up @@ -878,6 +877,10 @@ let NodeDefines = {

_is3DNode: false,

_up: undefined,
_right: undefined,
_front: undefined,
jareguo marked this conversation as resolved.
Show resolved Hide resolved

// internal properties
/**
* !#en
Expand Down Expand Up @@ -1575,6 +1578,60 @@ let NodeDefines = {
this._update3DFunction();
}
},

/**
* !#en Returns a normalized vector representing the up direction (Y axis) of the node in world space.
* !#zh 获取节点正上方(y 轴)所在方向,返回值为世界坐标系下的归一化向量
*
* @method up
* @return {Vec2|Vec3}
*/
jareguo marked this conversation as resolved.
Show resolved Hide resolved
up: {
get () {
this._up = Vec3.transformQuat(_uVec3, Vec3.UP, this.getWorldRotation(new Quat()));
return this._up;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里输出结果为 Vec3 类型,与 2D 节点的 position 类型保持一致。

},
set () {
//TODO: This function can receive a value to set node‘s direction.
return null;
jareguo marked this conversation as resolved.
Show resolved Hide resolved
}
},

/**
* !#en Returns a normalized vector representing the right direction (-X axis) of the node in world space.
* !#zh 获取节点正右方(-x 轴)所在方向,返回值为世界坐标系下的归一化向量
*
* @method right
* @return {Vec2|Vec3}
*/
right: {
get () {
this._right = Vec3.transformQuat(_rVec3, Vec3.RIGHT, this.getWorldRotation(new Quat()));
return this._right;
},
set () {
//TODO: This function can receive a value to set node‘s direction.
return null;
}
},

/**
* !#en Returns a normalized vector representing the forward direction (Z axis) of the node in world space.
* !#zh 获取节点正前方(z 轴)所在方向,返回值为世界坐标系下的归一化向量
jareguo marked this conversation as resolved.
Show resolved Hide resolved
*
* @method front
* @return {Vec2|Vec3}
*/
front: {
jareguo marked this conversation as resolved.
Show resolved Hide resolved
get () {
this._front = Vec3.transformQuat(_fVec3, Vec3.FRONT, this.getWorldRotation(new Quat()));
return this._front;
},
set () {
//TODO: This function can receive a value to set node‘s direction.
return null;
}
},
},

/**
Expand Down Expand Up @@ -2999,39 +3056,6 @@ let NodeDefines = {
return out;
},

/**
* !#en Get the node vector of the nodes that are converted to the up direction.
* !#zh 获取转换到正上方的节点向量
*
* @method up
* @return {Vec3}
*/
up () {
return Vec3.transformQuat(_uVec3, Vec3.UP, this.getWorldRotation(new Quat()));
},

/**
* !#en Get the node vector of the nodes that are converted to the right direction.
* !#zh 获取转换到正右方的节点向量
*
* @method right
* @return {Vec3}
*/
right () {
return Vec3.transformQuat(_rVec3, Vec3.RIGHT, this.getWorldRotation(new Quat()));
},

/**
* !#en Get the node vector of the nodes that are converted to the forward direction.
* !#zh 获取转换到正前方的节点向量
*
* @method forward
* @return {Vec3}
*/
forward () {
return Vec3.transformQuat(_fVec3, Vec3.FRONT, this.getWorldRotation(new Quat()));
},

/*
* Set world position.
* This is not a public API yet, its usage could be updated
Expand Down