• Quaternion:通过API对Quaternion(四元数)类中的方法属性初步学习总结(一)


    Quaternion(四元数)

    用于表示旋转Quaternion(x,y,z,w);属于结构体,拥有结构体的属性。

    来自官方的提醒,不要直接修改x,y,z,w的值,除非你很了解它;

    属性

    1.idetity表示无旋转参数,同方法中的void

    变量

    x,y,z,w:是四元数中的组件

    this[int index]利用struct中的下标来访问Quaternion中的组件

    eulerAngles 

    方法

    1.Quaternion.ToAngleAxis(out angle,out Axis)

    获取并输出该物体的旋转角,以及旋转轴;

    2.Quaternion.Angle(A.transform.position,B.transform.position);

    返回一个float类型,返回两个gameObject中间相差的角度

    3.Quaternion.AngleAxis(Angle,Vector3.Axis)

    以Vector3.Axis为轴以angle为旋转角进行旋转

    4.Quaternion.Euler(Vector3(0,30,0))&&Quaternion.Euler(0,30,0)

    返回一个四元数,一个绕Y轴旋转30度的四元数

     

    5.差值方法Lerp

    返回一个四元数,返回From与To的差值,并以Time.detaltime*speed变化着

    Quaternion.Lerp(From.rotation,To.Rotation,Time.detaltime*speed);

    例如 以下代码中C,D将以A.Rotation为起始点,以B.rotation为结束点以total为速度进行变化

    using UnityEngine;
    using System.Collections;
    pubilc class Eaxmble:MonoBehaviour
    {
    public Transform A,B,C,D;
    float speed=0.2f;
    float total=0.0f;
    void start()
    {
    }
    void Update()
    {
    total+=Time.deltaTime*speed;
    if(total>=1.0f)
    total=1.0f;
    
    C.rotation=Quaternion.Lerp(A.rotation,B.rotation,total);
    D.rotation=Quaternion.Lerp(A.rotation,B.rotation,total);    
    }
    }
    Lerp

    6.LookRotation方法

    a:Quaternion.LookRotation(Vector3.forword);

    b:Quaternion.LookRotation(Vector3.forword,Vector.up);

    个人看法:对这个方法不是很理解,不过知道它的一些用法,在Unity中这类方法比较特殊(比如Tramsform.MoveRotation),该方法的在使用的时候,大都取本身与对象之间的向量

    即下文的Vector.forWord

    Vector3.forword应该是transform.position-target.position这样就可以实现gameObject的Z轴始终指向target.posotion

    a方法是按照Vector3.up作为旋转轴

    b方法的旋转轴可以通过定义Vector.up来实现是围绕自身的transform.up旋转还是围绕Vector.up,或者是其他

  • 相关阅读:
    弱爆程序员的特征值
    快捷渐变效果
    做事务性的发布数据库日志会越来越大
    判断MS SQLSERVER临时表是否存在
    SQLite实现加密
    CentOS6.4下安装TeamViewer8
    安装CDT
    CentOS中安装Courier New字体
    VS2012的Windows程序不显示DOS窗口
    log4cpp安装使用
  • 原文地址:https://www.cnblogs.com/HeYIcengshuo/p/6407435.html
Copyright © 2020-2023  润新知