Unity3d quaternion properties and function test __unity3d

Source: Internet
Author: User
Quaternion Properties and methods

One, properties:

X, Y, z don't say, just look at a eulerangles, the code is as follows:
[CSharp]View plain copy public quaternion rotation = quaternion.identity;   void Start () {rotation.eulerangles = new Vector3 (0, 30, 0);   Transform.rotation = rotation;   Print (ROTATION.EULERANGLES.Y); Effect: Turn the object clockwise around the y axis, with the same effect as transform.eulerangles. Object rotation = (0,30,0). However, you cannot assign values directly to Transform.rotation.eulerAngle.


Second, the method

1,function Toangleaxis (out of Angle:float, out Axis:vector3): void
[CSharp]View plain copy public float angle = 0.0F;      Public Vector3 axis = Vector3.zero;   void Start () {transform.eulerangles = new Vector3 (0, 90, 0);   Transform.rotation.ToAngleAxis (out angle, out axis);   Print (angle + "" + axis); Effects: Returns the rotation of an object to the angles and axis (the angle between the object's Z-axis and the world's Z axis).
Input: transform.localeulerangles= (0,0,0);
Output: Angle=0, axis= (1,0,0);
Input: transform.localeulerangles= (0,90,0);
Output: angle=90,axis= (0,1,0);
Input: transform.localeulerangles= (270,0,0);
Output: angle=90,axis= ( -1,0,0)

2,function setfromtorotation (Fromdirection:vector3, Todirection:vector3): void
[CSharp]View plain copy private Vector3 _from = Vector3.one;   Private Vector3 _to = new Vector3 (100f, 200f, 100f);   Private quaternion q;      Private Vector3 Headupdir;   void Start () {q.setfromtorotation (_from, _to);   transform.rotation=q; Headupdir=transform.   Transformdirection (Vector3.forward); Effect: Rotate the fromdirection of the object to the Todirection
Input: A=vector3 (0,0,1); B=vector3 (0,1,0)//Z axis toward Y axis
Output: q= ( -0.7,0,0,0.7); Headupdir= (0,1,0)
Input: A=vector3 (0,0,1); B=vector3 (1,0,0)//Turn the z-axis toward the x-axis
Output: q= (0,0.7,0,0.7); Headupdir= (1,0,0)
Input: A=vector3 (0,1,0); B=vector3 (1,0,0)//Turn y axis toward X axis
Output: q= (0,0,-0.7,0.7); Headupdir= (0,0,1)

3,function setlookrotation (View:vector3, Up:vector3 = vector3.up): void
[CSharp]View plain copy public Transform obj1;   Public Transform Obj2;      quaternion q;   void Update () {q.setlookrotation (obj1.position, obj2.position);   transform.rotation = q; Effect: Similar to the LookAt () method so that object 1 always stares at object 2

4, static operator * (Lhs:quaternion, rhs:quaternion): quaternion
[CSharp]  View Plain Copy public transform extrarotation;  

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.