cocos旋转归零测试

import { _decorator, Component, EventMouse, Input, input, Node, Vec3 } from 'cc';

const { ccclass, property } = _decorator;

@ccclass('n3')

export class n3 extends Component {

    start() {

        input.on(Input.EventType.MOUSE_MOVE, this.onMouseMove, this)

        input.on(Input.EventType.MOUSE_UP, this.onMouseUp, this)

    }

    onMouseMove(event: EventMouse){

        if (event.getButton() == 2) {

            //获取本地坐标系下的旋转,用欧拉角表示

            let fe1 = this.node.eulerAngles.x

            let fe2 = this.node.eulerAngles.y

            //鼠标在UI坐标系下的移动距离

            let x1 = event.movementX * 0.5

            let y1 = event.movementY * 0.5

            //用欧拉角设置世界坐标系下的旋转

            fe1 += -y1

            fe2 += -x1

            this.node.setRotationFromEuler(fe1, fe2, 0)

        }

    }

    onMouseUp(event: EventMouse){

        let h1 = new Vec3(0,0,0)

        let h2 = new Vec3(0,0,0)

        let h3 = new Vec3(0,0,0)

        let h4 = new Vec3(0,0,0)

        this.node.worldRotation.getEulerAngles(h1)

        this.node.rotation.getEulerAngles(h2)

        this.node.parent.worldRotation.getEulerAngles(h3)

        this.node.parent.rotation.getEulerAngles(h4)

        let b1 = this.node.worldPosition

        let b2 = this.node.position

        let b3 = this.node.parent.worldPosition

        let b4 = this.node.parent.position

        console.log(h1 + 'sss')

        console.log(h2 + 'ddd')

        console.log(h3 + 'sss')

        console.log(h4 + 'ddd')

        this.node.parent.setRotationFromEuler(h1)

        this.node.setRotationFromEuler(0,0,0)

        let h5 = new Vec3(0,0,0)

        let h6 = new Vec3(0,0,0)

        let h7 = new Vec3(0,0,0)

        let h8 = new Vec3(0,0,0)

        this.node.worldRotation.getEulerAngles(h5)

        this.node.rotation.getEulerAngles(h6)

        this.node.parent.worldRotation.getEulerAngles(h7)

        this.node.parent.rotation.getEulerAngles(h8)

     

        console.log(h5 + 'www')

        console.log(h6 + 'eee')

        console.log(h7 + 'www')

        console.log(h8 + 'eee')

    }

    update(deltaTime: number) {

       

    }

}



 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值