Unity 6.3
0 онлайн 44 гостей 3 в системе
Вход

Quaternion.operator *

Declaration

public static Quaternion operator *(Quaternion lhs, Quaternion rhs);

Параметры

Параметр Описание
лс Кватернион левой стороны.
РХС Правый кватернион.

Описание

Объединяет вращения lhs и rhs.

Вращение по произведению lhs * rhs то же самое, что и применение двух вращений в последовательности: lhs сначала, а затем rhsотносительно системы отсчета, полученной в результате вращения lhs. Обратите внимание, что это означает, что вращения не являются коммутативными, так что lhs * rhs не даёт такое же вращение, как rhs * lhs.

using UnityEngine;

public class QuaternionProduct : MonoBehaviour { void Start() { // Two simple rotations Quaternion rotX = Quaternion.AngleAxis(90, Vector3.right); Quaternion rotY = Quaternion.AngleAxis(90, Vector3.up); // Order matters: lhs * rhs does not equal rhs * lhs Quaternion result1 = rotX * rotY; // applies Y rotation first, then X Quaternion result2 = rotY * rotX; // applies X rotation first, then Y Debug.Log($"X * Y = {result1.eulerAngles}"); Debug.Log($"Y * X = {result2.eulerAngles}"); // Apply one result to see the difference transform.rotation = result1; } }

Declaration

public static Vector3 operator *(Quaternion rotation, Vector3 point);

Параметры

Параметр Описание
ротация Кватернион, представляющий вращение для применения.
пункт Vector3 для вращения.

Описание

Transform Vector3 point с использованием кватерниона rotation.

using UnityEngine;
using System.Collections;

public class Example2 : MonoBehaviour { private void Start() { //Creates an array of three points forming a triangle Vector3[] points = new Vector3[] { new Vector3(-1, -1, 0), new Vector3(1, -1, 0), new Vector3(0, 1, 0) };

//Creates a Quaternion rotation of 5 degrees around the Z axis Quaternion rotation = Quaternion.AngleAxis(5, Vector3.forward);

//Loop through the array of Vector3s and apply the rotation for (int n = 0; n < points.Length; n++) { Vector3 rotatedPoint = rotation * points[n]; //Output the new rotation values Debug.Log("Point " + n + " rotated: " + rotatedPoint); } } }