From 759303d916f8ec0534c5405ac72b7db8262b717d Mon Sep 17 00:00:00 2001 From: jho1995 <337031709@qq.com> Date: Thu, 5 Mar 2020 09:51:00 +0800 Subject: [PATCH 1/8] provides world position that are converted to up,right,forward direction --- cocos2d/core/CCNode.js | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/cocos2d/core/CCNode.js b/cocos2d/core/CCNode.js index c440507bc4a..ca5fcafe9c3 100644 --- a/cocos2d/core/CCNode.js +++ b/cocos2d/core/CCNode.js @@ -49,6 +49,10 @@ var emptyFunc = function () {}; // getWorldPosition temp var var _gwpVec3 = new Vec3(); +var _guwpVec3 = new Vec3(); +var _grwpVec3 = new Vec3(); +var _gfwpVec3 = new Vec3(); + var _gwpQuat = new Quat(); // _invTransformPoint temp var @@ -2993,6 +2997,39 @@ let NodeDefines = { return out; }, + /** + * !#en Get the world coordinates of the nodes that are converted to the up direction. + * !#zh 获取转换到正上方向的节点世界坐标 + * + * @method getUpWorldPosition + * @return {Vec3} + */ + getUpWorldPosition () { + return Vec3.transformQuat(_guwpVec3, Vec3.UP, this.getWorldPosition(new Quat())); + }, + + /** + * !#en Get the world coordinates of the nodes that are converted to the right direction. + * !#zh 获取转换到正右方向的节点世界坐标 + * + * @method getRightWorldPosition + * @return {Vec3} + */ + getRightWorldPosition () { + return Vec3.transformQuat(_guwpVec3, Vec3.RIGHT, this.getWorldPosition(new Quat())); + }, + + /** + * !#en Get the world coordinates of the nodes that are converted to the forward direction. + * !#zh 获取转换到正前方向的节点世界坐标 + * + * @method getForwardWorldPosition + * @return {Vec3} + */ + getForwardWorldPosition () { + return Vec3.transformQuat(_guwpVec3, Vec3.FRONT, this.getWorldPosition(new Quat())); + }, + /* * Set world position. * This is not a public API yet, its usage could be updated From b5691ed655304dc59fed7d93780ecb1e6164d2ee Mon Sep 17 00:00:00 2001 From: jho1995 <337031709@qq.com> Date: Fri, 6 Mar 2020 17:32:50 +0800 Subject: [PATCH 2/8] correction code --- cocos2d/core/CCNode.js | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/cocos2d/core/CCNode.js b/cocos2d/core/CCNode.js index ca5fcafe9c3..bfa2346f626 100644 --- a/cocos2d/core/CCNode.js +++ b/cocos2d/core/CCNode.js @@ -49,9 +49,6 @@ var emptyFunc = function () {}; // getWorldPosition temp var var _gwpVec3 = new Vec3(); -var _guwpVec3 = new Vec3(); -var _grwpVec3 = new Vec3(); -var _gfwpVec3 = new Vec3(); var _gwpQuat = new Quat(); @@ -80,6 +77,11 @@ var _gwrtQuatb = new Quat(); var _laVec3 = new Vec3(); var _laQuat = new Quat(); +//up、right、forward temp var +var _uVec3 = new Vec3(); +var _rVec3 = new Vec3(); +var _fVec3 = new vec3(); + // _hitTest temp var var _htVec3a = new Vec3(); var _htVec3b = new Vec3(); @@ -2998,36 +3000,36 @@ let NodeDefines = { }, /** - * !#en Get the world coordinates of the nodes that are converted to the up direction. - * !#zh 获取转换到正上方向的节点世界坐标 + * !#en Get the node vector of the nodes that are converted to the up direction. + * !#zh 获取转换到正上方的节点向量 * - * @method getUpWorldPosition + * @method up * @return {Vec3} */ - getUpWorldPosition () { - return Vec3.transformQuat(_guwpVec3, Vec3.UP, this.getWorldPosition(new Quat())); + up () { + return Vec3.transformQuat(_uVec3, Vec3.UP, this.getWorldRotation(new Quat())); }, /** - * !#en Get the world coordinates of the nodes that are converted to the right direction. - * !#zh 获取转换到正右方向的节点世界坐标 + * !#en Get the node vector of the nodes that are converted to the right direction. + * !#zh 获取转换到正右方的节点向量 * - * @method getRightWorldPosition + * @method right * @return {Vec3} */ - getRightWorldPosition () { - return Vec3.transformQuat(_guwpVec3, Vec3.RIGHT, this.getWorldPosition(new Quat())); + right () { + return Vec3.transformQuat(_rVec3, Vec3.RIGHT, this.getWorldRotation(new Quat())); }, /** - * !#en Get the world coordinates of the nodes that are converted to the forward direction. - * !#zh 获取转换到正前方向的节点世界坐标 + * !#en Get the node vector of the nodes that are converted to the forward direction. + * !#zh 获取转换到正前方的节点向量 * - * @method getForwardWorldPosition + * @method forward * @return {Vec3} */ - getForwardWorldPosition () { - return Vec3.transformQuat(_guwpVec3, Vec3.FRONT, this.getWorldPosition(new Quat())); + forward () { + return Vec3.transformQuat(_fVec3, Vec3.FRONT, this.getWorldRotation(new Quat())); }, /* From 7c3861d3a574e1ed5f8e9746f757261c01b43d2b Mon Sep 17 00:00:00 2001 From: jho1995 <337031709@qq.com> Date: Tue, 17 Mar 2020 18:53:31 +0800 Subject: [PATCH 3/8] correction code --- cocos2d/core/CCNode.js | 94 ++++++++++++++++++++++++++---------------- 1 file changed, 59 insertions(+), 35 deletions(-) diff --git a/cocos2d/core/CCNode.js b/cocos2d/core/CCNode.js index bfa2346f626..afcfadef47a 100644 --- a/cocos2d/core/CCNode.js +++ b/cocos2d/core/CCNode.js @@ -49,7 +49,6 @@ var emptyFunc = function () {}; // getWorldPosition temp var var _gwpVec3 = new Vec3(); - var _gwpQuat = new Quat(); // _invTransformPoint temp var @@ -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(); // _hitTest temp var var _htVec3a = new Vec3(); @@ -878,6 +877,10 @@ let NodeDefines = { _is3DNode: false, + _up: undefined, + _right: undefined, + _front: undefined, + // internal properties /** * !#en @@ -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} + */ + up: { + get () { + this._up = Vec3.transformQuat(_uVec3, Vec3.UP, this.getWorldRotation(new Quat())); + return this._up; + }, + set () { + //TODO: This function can receive a value to set node‘s direction. + return null; + } + }, + + /** + * !#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 轴)所在方向,返回值为世界坐标系下的归一化向量 + * + * @method front + * @return {Vec2|Vec3} + */ + front: { + 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; + } + }, }, /** @@ -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 From 7973e2b176eab7dfc901c0c2796f86e7d1d9423f Mon Sep 17 00:00:00 2001 From: jho1995 <337031709@qq.com> Date: Thu, 19 Mar 2020 10:22:27 +0800 Subject: [PATCH 4/8] correction code --- cocos2d/core/CCNode.js | 36 +++++++++----------------------- cocos2d/core/value-types/vec3.ts | 6 +++--- 2 files changed, 13 insertions(+), 29 deletions(-) diff --git a/cocos2d/core/CCNode.js b/cocos2d/core/CCNode.js index afcfadef47a..04a62d7ee29 100644 --- a/cocos2d/core/CCNode.js +++ b/cocos2d/core/CCNode.js @@ -877,10 +877,6 @@ let NodeDefines = { _is3DNode: false, - _up: undefined, - _right: undefined, - _front: undefined, - // internal properties /** * !#en @@ -1581,55 +1577,43 @@ let NodeDefines = { /** * !#en Returns a normalized vector representing the up direction (Y axis) of the node in world space. - * !#zh 获取节点正上方(y 轴)所在方向,返回值为世界坐标系下的归一化向量 + * !#zh 获取节点正上方(y 轴)面对的方向,返回值为世界坐标系下的归一化向量 * * @method up * @return {Vec2|Vec3} */ up: { get () { - this._up = Vec3.transformQuat(_uVec3, Vec3.UP, this.getWorldRotation(new Quat())); - return this._up; - }, - set () { - //TODO: This function can receive a value to set node‘s direction. - return null; + var _up = Vec3.transformQuat(_uVec3, Vec3.UP, this.getWorldRotation(new Quat())); + return _up; } }, /** * !#en Returns a normalized vector representing the right direction (-X axis) of the node in world space. - * !#zh 获取节点正右方(-x 轴)所在方向,返回值为世界坐标系下的归一化向量 + * !#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; + var _right = Vec3.transformQuat(_rVec3, Vec3.RIGHT, this.getWorldRotation(new Quat())); + return _right; } }, /** * !#en Returns a normalized vector representing the forward direction (Z axis) of the node in world space. - * !#zh 获取节点正前方(z 轴)所在方向,返回值为世界坐标系下的归一化向量 + * !#zh 获取节点正前方(z 轴)面对的方向,返回值为世界坐标系下的归一化向量 * * @method front * @return {Vec2|Vec3} */ - front: { + forward: { 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; + var _forward = Vec3.transformQuat(_fVec3, Vec3.FORWARD, this.getWorldRotation(new Quat())); + return _forward; } }, }, diff --git a/cocos2d/core/value-types/vec3.ts b/cocos2d/core/value-types/vec3.ts index bf40a4e2995..6e8736c985b 100644 --- a/cocos2d/core/value-types/vec3.ts +++ b/cocos2d/core/value-types/vec3.ts @@ -211,12 +211,12 @@ export default class Vec3 extends ValueType { /** * !#en return a Vec3 object with x = 0, y = 0, z = 1. * !#zh 返回 x = 0,y = 0,z = 1 的 Vec3 对象。 - * @property FRONT + * @property FORWARD * @type Vec3 * @static */ - static get FRONT () { return new Vec3(0, 0, 1); } - static readonly FRONT_R = Vec3.FRONT; + static get FORWARD () { return new Vec3(0, 0, 1); } + static readonly FRONT_R = Vec3.FORWARD; /** From 654b443986dd9f513aefe81cac3c6ac2932e477e Mon Sep 17 00:00:00 2001 From: jho1995 <337031709@qq.com> Date: Thu, 19 Mar 2020 10:23:01 +0800 Subject: [PATCH 5/8] correction code --- cocos2d/core/CCNode.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cocos2d/core/CCNode.js b/cocos2d/core/CCNode.js index 04a62d7ee29..c0ca1c2a297 100644 --- a/cocos2d/core/CCNode.js +++ b/cocos2d/core/CCNode.js @@ -1607,7 +1607,7 @@ let NodeDefines = { * !#en Returns a normalized vector representing the forward direction (Z axis) of the node in world space. * !#zh 获取节点正前方(z 轴)面对的方向,返回值为世界坐标系下的归一化向量 * - * @method front + * @method forward * @return {Vec2|Vec3} */ forward: { From 650810582d2cb890b5a98026243f9f35df53db38 Mon Sep 17 00:00:00 2001 From: jho1995 <337031709@qq.com> Date: Thu, 19 Mar 2020 16:15:52 +0800 Subject: [PATCH 6/8] correction code --- cocos2d/core/CCNode.js | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/cocos2d/core/CCNode.js b/cocos2d/core/CCNode.js index c0ca1c2a297..ffda90931b3 100644 --- a/cocos2d/core/CCNode.js +++ b/cocos2d/core/CCNode.js @@ -77,9 +77,8 @@ var _laVec3 = new Vec3(); var _laQuat = new Quat(); //up、right、forward temp var -var _uVec3 = new Vec3(); -var _rVec3 = new Vec3(); -var _fVec3 = new Vec3(); +var _urfVec3 = new Vec3(); +var _urfQuat = new Quat(); // _hitTest temp var var _htVec3a = new Vec3(); @@ -1584,8 +1583,8 @@ let NodeDefines = { */ up: { get () { - var _up = Vec3.transformQuat(_uVec3, Vec3.UP, this.getWorldRotation(new Quat())); - return _up; + var _up = Vec3.transformQuat(_urfVec3, Vec3.UP, this.getWorldRotation(_urfQuat)); + return _up.clone(); } }, @@ -1598,8 +1597,8 @@ let NodeDefines = { */ right: { get () { - var _right = Vec3.transformQuat(_rVec3, Vec3.RIGHT, this.getWorldRotation(new Quat())); - return _right; + var _right = Vec3.transformQuat(_urfVec3, Vec3.RIGHT, this.getWorldRotation(_urfQuat)); + return _right.clone(); } }, @@ -1612,8 +1611,8 @@ let NodeDefines = { */ forward: { get () { - var _forward = Vec3.transformQuat(_fVec3, Vec3.FORWARD, this.getWorldRotation(new Quat())); - return _forward; + var _forward = Vec3.transformQuat(_urfVec3, Vec3.FORWARD, this.getWorldRotation(_urfQuat)); + return _forward.clone(); } }, }, From c87767e36fce7659ba721abcd4d50be4f2855cf5 Mon Sep 17 00:00:00 2001 From: jho1995 <337031709@qq.com> Date: Fri, 20 Mar 2020 11:08:47 +0800 Subject: [PATCH 7/8] correction code --- cocos2d/core/CCNode.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cocos2d/core/CCNode.js b/cocos2d/core/CCNode.js index ffda90931b3..b3ba409b12b 100644 --- a/cocos2d/core/CCNode.js +++ b/cocos2d/core/CCNode.js @@ -1589,8 +1589,8 @@ let NodeDefines = { }, /** - * !#en Returns a normalized vector representing the right direction (-X axis) of the node in world space. - * !#zh 获取节点正右方(-x 轴)面对的方向,返回值为世界坐标系下的归一化向量 + * !#en Returns a normalized vector representing the right direction (X axis) of the node in world space. + * !#zh 获取节点正右方(x 轴)面对的方向,返回值为世界坐标系下的归一化向量 * * @method right * @return {Vec2|Vec3} From a1ba7405b07c6aae0a7c415087263f18ea33beb2 Mon Sep 17 00:00:00 2001 From: jho1995 <337031709@qq.com> Date: Fri, 20 Mar 2020 15:42:24 +0800 Subject: [PATCH 8/8] correction code --- cocos2d/core/CCNode.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/cocos2d/core/CCNode.js b/cocos2d/core/CCNode.js index b3ba409b12b..5f107b7209f 100644 --- a/cocos2d/core/CCNode.js +++ b/cocos2d/core/CCNode.js @@ -1578,8 +1578,8 @@ let NodeDefines = { * !#en Returns a normalized vector representing the up direction (Y axis) of the node in world space. * !#zh 获取节点正上方(y 轴)面对的方向,返回值为世界坐标系下的归一化向量 * - * @method up - * @return {Vec2|Vec3} + * @property up + * @type {Vec3} */ up: { get () { @@ -1592,8 +1592,8 @@ let NodeDefines = { * !#en Returns a normalized vector representing the right direction (X axis) of the node in world space. * !#zh 获取节点正右方(x 轴)面对的方向,返回值为世界坐标系下的归一化向量 * - * @method right - * @return {Vec2|Vec3} + * @property right + * @type {Vec3} */ right: { get () { @@ -1606,8 +1606,8 @@ let NodeDefines = { * !#en Returns a normalized vector representing the forward direction (Z axis) of the node in world space. * !#zh 获取节点正前方(z 轴)面对的方向,返回值为世界坐标系下的归一化向量 * - * @method forward - * @return {Vec2|Vec3} + * @property forward + * @type {Vec3} */ forward: { get () {