kingBook

导航

LayaAir2.x Quaternion

Laya.createFromYawPitchRoll(yaw: number, pitch: number, roll: number, out: Quaternion): void
Laya.getYawPitchRoll(out: Vector3): void

pitch: x轴的旋转角度
yaw: y轴的旋转角度
roll: z轴的旋转角度

QuaternionUtil.ts

export default class QuaternionUtil{
	
	public static getEulerAngles(quat:Laya.Quaternion,out:Laya.Vector3):void{
		quat.getYawPitchRoll(out);
		let x=out.x*180/Math.PI;
		let y=out.y*180/Math.PI;
		let z=out.z*180/Math.PI;
		out.x=y;
		out.y=x;
		out.z=z;
	}
}
Laya.rotationLookAt(forward: Vector3, up: Vector3, out: Quaternion): void
let rotation=new Laya.Quaternion();
Laya.Quaternion.rotationLookAt(new Laya.Vector3(0,0,-1),new Laya.Vector3(0,1,0),rotation);
let eulerAngles=Vector3Util.newZero;
QuaternionUtil.getEulerAngles(rotation,eulerAngles);
console.log(eulerAngles);//(0,0,0)

let rotation=new Laya.Quaternion();
Laya.Quaternion.rotationLookAt(new Laya.Vector3(1,0,-1),new Laya.Vector3(0,1,0),rotation);
let eulerAngles=Vector3Util.newZero;
QuaternionUtil.getEulerAngles(rotation,eulerAngles);
console.log(eulerAngles);//(0,45,0)

posted on 2021-01-11 22:06  kingBook  阅读(276)  评论(0编辑  收藏  举报