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
provides world position that are converted to up,right,forward direction #6287
Conversation
@Jno1995, v2.3.1-release branch will be deleted, so we edited the base branch to v2.3.2, or this PR will be killed by GitHub.
Please review the commits history to ensure that the PR does not polluted by unneeded commits from your origin branch.
If you need to merge to other branch, you can first click the Edit button on the right side of the PR title, then switch the base branch.
If necessary, welcome to resubmit a new PR. Thanks!
cocos2d/core/CCNode.js
Outdated
* @method getUpWorldPosition | ||
* @return {Vec3} | ||
*/ | ||
getUpWorldPosition () { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
为啥叫worldPosition, 应该是获取局部空间中的 UP 轴在世界坐标系中的向量,直接用 up, left, forward 就行
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
你是说只提供一个接口,然后让用户自己选择传递 up、left 或者 forward ?
cocos2d/core/CCNode.js
Outdated
|
||
/** | ||
* !#en Get the node vector of the nodes that are converted to the forward direction. | ||
* !#zh 获取转换到正前方的节点向量 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
获取节点正前方(z 轴)面对的方向,返回值为世界坐标系下的归一化向量
收到
…------------------ 原始邮件 ------------------
发件人: "Jare Guo"<notifications@github.com>;
发送时间: 2020年3月6日(星期五) 晚上9:13
收件人: "cocos-creator/engine"<engine@noreply.github.com>;
抄送: "张哲锋"<337031709@qq.com>; "Mention"<mention@noreply.github.com>;
主题: Re: [cocos-creator/engine] provides world position that are converted to up,right,forward direction (#6287)
@jareguo commented on this pull request.
In cocos2d/core/CCNode.js:
> @@ -49,6 +49,7 @@ var emptyFunc = function () {}; // getWorldPosition temp var var _gwpVec3 = new Vec3(); +
这里的空行去掉吧
In cocos2d/core/CCNode.js:
> @@ -2993,6 +2999,39 @@ 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()));
这里得区分一下 2D/3D 吧,2D 的话 return 一个 Vec2。另外返回的 vec 得 clone 一份,不能返回全局唯一一个。反而是 getWorldRotation 用的 quat 可以缓存一下
In cocos2d/core/CCNode.js:
> + 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.
Returns a normalized vector representing the forward direction (Z axis) of the node in world space.
In cocos2d/core/CCNode.js:
> + }, + + /** + * !#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 获取转换到正前方的节点向量
获取节点正前方(z 轴)面对的方向,返回值为世界坐标系下的归一化向量
In cocos2d/core/CCNode.js:
> @@ -2993,6 +2999,39 @@ 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 获取转换到正右方的节点向量
获取节点正右方(-x 轴)所在方向,返回值为世界坐标系下的归一化向量
In cocos2d/core/CCNode.js:
> + * + * @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 () {
感觉不太统一,Vec3 用的是 front
In cocos2d/core/CCNode.js:
> @@ -2993,6 +2999,39 @@ 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 () {
直接用 getter 比较好,将来还能添加一个 setter 用于赋值,给 up 赋值相当于 lookAt(dir, upAxis);
In cocos2d/core/CCNode.js:
> @@ -2993,6 +2999,39 @@ let NodeDefines = { return out; }, + /** + * !#en Get the node vector of the nodes that are converted to the up direction. + * !#zh 获取转换到正上方的节点向量
获取节点正上方(y 轴)所在方向,返回值为世界坐标系下的归一化向量
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or unsubscribe.
|
@Jno1995, v2.3.2 branch will be deleted, so we edited the base branch to v2.3.3-release, or this PR will be killed by GitHub.
Please review the commits history to ensure that the PR does not polluted by unneeded commits from your origin branch.
If you need to merge to other branch, you can first click the Edit button on the right side of the PR title, then switch the base branch.
If necessary, welcome to resubmit a new PR. Thanks!
cocos2d/core/CCNode.js
Outdated
//up、right、forward temp var | ||
var _uVec3 = new Vec3(); | ||
var _rVec3 = new Vec3(); | ||
var _fVec3 = new vec3(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Vec3 大小写写错了
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
嗯嗯
看到了
发自我的iPhone
…------------------ Original ------------------
From: Jare Guo <notifications@github.com>
Date: Sat,Mar 14,2020 3:33 PM
To: cocos-creator/engine <engine@noreply.github.com>
Cc: zhefeng.zhang <337031709@qq.com>, Mention <mention@noreply.github.com>
Subject: Re: [cocos-creator/engine] provides world position that are converted to up,right,forward direction (#6287)
@jareguo commented on this pull request.
In cocos2d/core/CCNode.js:
> @@ -2993,6 +2999,39 @@ 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()));
2D 估计用 vec2.rotateSelf(worldRotation) 就行
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or unsubscribe.
|
cocos2d/core/CCNode.js
Outdated
up: { | ||
get () { | ||
this._up = Vec3.transformQuat(_uVec3, Vec3.UP, this.getWorldRotation(new Quat())); | ||
return this._up; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里输出结果为 Vec3 类型,与 2D 节点的 position 类型保持一致。
Re: cocos/2d-tasks#2181
Changes:
*
新增三个接口
getUpWorldPosition
、getRightWorldPosition
、getForwardWorldPosition
。Add three new interfaces
getUpWorld Position
,getRightWorldPosition
,getForwardWorld Position
.