99偷拍视频精品区一区二,口述久久久久久久久久久久,国产精品夫妇激情啪发布,成人永久免费网站在线观看,国产精品高清免费在线,青青草在线观看视频观看,久久久久久国产一区,天天婷婷久久18禁,日韩动漫av在线播放直播

Unity向量如何按照某一點進行旋轉-創新互聯

這期內容當中小編將會給大家帶來有關Unity向量如何按照某一點進行旋轉,文章內容豐富且以專業的角度為大家分析和敘述,閱讀完這篇文章希望大家可以有所收獲。

成都創新互聯公司是一家集網站建設,彭陽企業網站建設,彭陽品牌網站建設,網站定制,彭陽網站建設報價,網絡營銷,網絡優化,彭陽網站推廣為一體的創新建站企業,幫助傳統企業提升企業形象加強企業競爭力。可充分滿足這一群體相比中小企業更為豐富、高端、多元的互聯網需求。同時我們時刻保持專業、時尚、前沿,時刻以成就客戶成長自我,堅持不斷學習、思考、沉淀、凈化自己,讓我們為更多的企業打造出實用型網站。

一、unity的旋轉

首先要知道一點就是在Unity的旋轉中使用過四元數進行旋轉的,如果對一個物體的rotation直接賦值你會發現結果不是你最終想要的結果,這個時候我們需要去借助Quaternion來進行旋轉。

二、向量按照原點進行旋轉

用到的Unity內置方法Quaternion.AngleAxis(float angle,Vector3 axis)第一個參數就是我們需要旋轉的角度 angle大于0時是按照順時針的方向進行旋轉,angle小于0是按照逆時針的方向旋轉,這里的旋轉時按照坐標原點進行的旋轉。第二個參數是旋轉軸,圍繞哪一個坐標軸進行旋轉。

注意:使用這個方法時獲得的也是四元數,我們將其轉換成向量Vector3是需要乘以自身的坐標(四元數 * 自身向量,如果反過來 自身向量 * 四元數 在Unity會發生編譯錯誤,這里需要注意一下)

案例:將Vector3(1,0,1)按照原點旋轉45°,90°,180°,270°測試分別用黑、黃、藍、綠顏色表示

代碼如下:

using UnityEngine;[ExecuteInEditMode]public class VectorDirTest : MonoBehaviour { // Update is called once per frame void Update () {  Debug.DrawLine(Vector3.left * 5f,Vector3.right * 5f,Color.red);  Debug.DrawLine(Vector3.up * 5f,Vector3.down * 5f,Color.green);  Debug.DrawLine(Vector3.forward * 5f,Vector3.back * 5f,Color.blue);    Vector3 dir = new Vector3(1,0,1);  Debug.DrawLine(Vector3.zero,dir,Color.white);  Debug.DrawLine(Vector3.zero,Quaternion.AngleAxis(45,Vector3.up) * dir,Color.black);  Debug.DrawLine(Vector3.zero,Quaternion.AngleAxis(90,Vector3.up) * dir,Color.yellow);  Debug.DrawLine(Vector3.zero,Quaternion.AngleAxis(180,Vector3.up) * dir,Color.blue);  Debug.DrawLine(Vector3.zero,Quaternion.AngleAxis(270,Vector3.up) * dir,Color.green); }}

三、向量按照指定位置進行旋轉

/// <summary>/// 圍繞某點旋轉指定角度/// </summary>/// <param name="position">自身坐標</param>/// <param name="center">旋轉中心</param>/// <param name="axis">圍繞旋轉軸</param>/// <param name="angle">旋轉角度</param>/// <returns></returns>public Vector3 RotateRound(Vector3 position, Vector3 center, Vector3 axis, float angle) {  return Quaternion.AngleAxis(angle, axis) * (position - center) + center; }

案例:將Vector3(1,0,1)按照Vector(2,0,2)旋轉45°,90°,180°,270°測試分別用紅、黃、藍、綠顏色表示

代碼如下:

using UnityEngine;[ExecuteInEditMode]public class VectorDirTest : MonoBehaviour {  // Update is called once per frame void Update () {  Debug.DrawLine(Vector3.left * 5f,Vector3.right * 5f,Color.red);  Debug.DrawLine(Vector3.up * 5f,Vector3.down * 5f,Color.green);  Debug.DrawLine(Vector3.forward * 5f,Vector3.back * 5f,Color.blue);  Vector3 dir = new Vector3(1,0,1);  Vector3 point = new Vector3(2,0,2);  Debug.DrawLine(Vector3.zero, RotateRound(dir, point, Vector3.up, 45), Color.red);  Debug.DrawLine(Vector3.zero, RotateRound(dir, point, Vector3.up, 90), Color.yellow);  Debug.DrawLine(Vector3.zero, RotateRound(dir, point, Vector3.up, 180), Color.blue);  Debug.DrawLine(Vector3.zero, RotateRound(dir, point, Vector3.up, 270), Color.green);  Debug.DrawLine(Vector3.zero, dir, Color.black);   }  /// <summary> /// 圍繞某點旋轉指定角度 /// </summary> /// <param name="position">自身坐標</param> /// <param name="center">旋轉中心</param> /// <param name="axis">圍繞旋轉軸</param> /// <param name="angle">旋轉角度</param> /// <returns></returns> public Vector3 RotateRound(Vector3 position, Vector3 center, Vector3 axis, float angle) {  return Quaternion.AngleAxis(angle, axis) * (position - center) + center; }}

上述就是小編為大家分享的Unity向量如何按照某一點進行旋轉了,如果剛好有類似的疑惑,不妨參照上述分析進行理解。如果想知道更多相關知識,歡迎關注創新互聯行業資訊頻道。

分享名稱:Unity向量如何按照某一點進行旋轉-創新互聯
網頁鏈接:http://www.yijiale78.com/article32/cegssc.html

成都網站建設公司_創新互聯,為您提供企業建站移動網站建設GoogleApp開發小程序開發用戶體驗

廣告

聲明:本網站發布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創新互聯

外貿網站制作