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) {
}
}