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

add calculation delta of node angle #6102

Merged
merged 1 commit into from
Jan 15, 2020

Conversation

knoxHuang
Copy link
Contributor

@knoxHuang knoxHuang commented Jan 14, 2020

Re:
cocos-creator/2d-tasks#2399
/issues/6654

Changes:

  • 修复 ScrollView 设置角度后,计算滚动方向错误的问题

@PPpro
Copy link
Contributor

PPpro commented Jan 15, 2020

_onTouchMoved 里也有相关 delta 的逻辑,需要同步修改一下吗

// calculation delta of node angle
_getLocalAxisAlignDelta (delta) {
let worldRot = cc.quat();
this.node.getWorldRotation(worldRot);
Copy link
Contributor

Choose a reason for hiding this comment

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

这里如果耗性能的话,是不是可以先判断下,如果 angle 为 0,就不做这个处理了
一般也很少人回去旋转 scrollview

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@2youyou2 这里是否能通过 this.node._worldMatDirty 来判断是否有旋转?如果 _worldMatDirty 为 true 时,在 TOUCH_MOVE 触发的时候获取的 _worldMatDirty 是否还是 true,还是说已经被重置为 false 了

_getLocalAxisAlignDelta (delta) {
   
        if (this.node._worldMatDirty) {
            this.node.getWorldRotation(_worldRot);
        }
        let oriDelta = cc.v3(delta.x, delta.y, 0);
        let deltaMove = cc.v2();
        if (this.horizontal) {
            Vec3.transformQuat(_tempVec3, Vec3.RIGHT, _worldRot);
            deltaMove.x = oriDelta.dot(_tempVec3);
        }
        if (this.vertical) {
            Vec3.transformQuat(_tempVec3, Vec3.UP, _worldRot);
            deltaMove.y = oriDelta.dot(_tempVec3);
        }
        return deltaMove;
    },
``

Copy link
Contributor

Choose a reason for hiding this comment

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

不行啊,_worldMatDirty 什么时候都有可能被重置掉

Copy link
Contributor Author

Choose a reason for hiding this comment

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

你有没有比较好的办法呢?

Copy link
Contributor

Choose a reason for hiding this comment

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

把 delta 转到 local 坐标系下就好了嘛

@knoxHuang
Copy link
Contributor Author

_onTouchMoved 中的 let deltaMove = touch.getLocation().sub(touch.getStartLocation()); 会在 _handleReleaseLogic 函数进行处理,不需要进行同步

_getLocalAxisAlignDelta (delta) {
let worldRot = cc.quat();
this.node.getWorldRotation(worldRot);
let oriDelta = cc.v3(delta.x, delta.y, 0);
Copy link
Contributor

Choose a reason for hiding this comment

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

不要一直 new 对象

@knoxHuang knoxHuang removed the request for review from jareguo January 15, 2020 05:53
@@ -1011,8 +1011,15 @@ let ScrollView = cc.Class({
this._gatherTouchMove(deltaMove);
},

// Contains node angle calculations
_getLocalAxisAlignDelta (touch) {
let point = this.node.convertToNodeSpaceAR(touch.getLocation());
Copy link
Contributor

Choose a reason for hiding this comment

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

可以定义几个临时变量传到 convertToNodeSpaceAR 里面作为返回值

Comment on lines 1019 to 1021
let _point = this.node.convertToNodeSpaceAR(touch.getLocation(), _tempPoint);
let _prevPoint = this.node.convertToNodeSpaceAR(touch.getPreviousLocation(), _tempPrevPoint);
return _point.sub(_prevPoint);
Copy link
Contributor

Choose a reason for hiding this comment

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

应该不用创建 _point _prevPoint 变量了
_tempPoint _tempPrevPoint 就是输出变量

@SantyWang SantyWang merged commit f917e24 into cocos:v2.3.0-release Jan 15, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants