关于pitch、roll、 yaw的示意图和Laya.Quaternion.createFromYawPitchRoll用法

本文介绍了如何使用Laya3D中的Laya.Quaternion.createFromYawPitchRoll方法从欧拉角生成四元数,并解释了yaw、pitch、roll的概念及其对应轴的旋转方式。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

关于pitch、roll、 yaw的图解和Laya.Quaternion.createFromYawPitchRoll用法


首先说明一下:transform.rotation获取的是四元数,是从欧拉角转换过的,所以要想直接设置transform.rotation用欧拉角是不行的,得转换一下


createFromYawPitchRoll用法

最近学laya 3D,看到一个API Laya.Quaternion.createFromYawPitchRoll,看下代码,可以依靠轴角到四元数的公式进行推导,用法就很清楚了:

/**
 *  从欧拉角生成四元数(顺序为Yaw、Pitch、Roll)
 * @param	yaw yaw值
 * @param	pitch pitch值
 * @param	roll roll值
 * @param	out 输出四元数
 */
static createFromYawPitchRoll(yaw: number, pitch: number, roll: number, out: Quaternion): void {
	var halfRoll: number = roll * 0.5;
	var halfPitch: number = pitch * 0.5;
	var halfYaw: number = yaw * 0.5;

	var sinRoll: number = Math.sin(halfRoll);
	var cosRoll: number = Math.cos(halfRoll);
	var sinPitch: number = Math.sin(halfPitch);
	var cosPitch: number = Math.cos(halfPitch);
	var sinYaw: number = Math.sin(halfYaw);
	var cosYaw: number = Math.cos(halfYaw);


	out.x = (cosYaw * sinPitch * cosRoll) + (sinYaw * cosPitch * sinRoll);
	out.y = (sinYaw * cosPitch * cosRoll) - (cosYaw * sinPitch * sinRoll);
	out.z = (cosYaw * cosPitch * sinRoll) - (sinYaw * sinPitch * cosRoll);
	out.w = (cosYaw * cosPitch * cosRoll) + (sinYaw * sinPitch * sinRoll);
	}

用法:

let tempLocalRotation: Laya.Quaternion = new Laya.Quaternion();
Laya.Quaternion.createFromYawPitchRoll(this.yawPitchRoll.x, this.yawPitchRoll.y, this.yawPitchRoll.z, tempLocalRotation);
this.camera.transform.localRotation = tempLocalRotation;

关于pitch、 roll、 yaw的示意图

ψ、θ、φ分别为绕Z轴、Y轴、X轴的旋转角度,如果用Tait-Bryan angle表示,分别为Yaw、Pitch、Roll

img

后面我找了张图,描述不太一样,但你知道就好了:

  • yaw是围绕Y轴旋转
  • pitch是围绕X轴旋转
  • roll是围绕Z轴旋转

下面这张,黄色的是y轴:

在这里插入图片描述


维尼聚合工具

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值