當前位置: 首頁>>代碼示例>>C#>>正文


C# Quaternion.SetEulerRotation方法代碼示例

本文整理匯總了C#中UnityEngine.Quaternion.SetEulerRotation方法的典型用法代碼示例。如果您正苦於以下問題:C# Quaternion.SetEulerRotation方法的具體用法?C# Quaternion.SetEulerRotation怎麽用?C# Quaternion.SetEulerRotation使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在UnityEngine.Quaternion的用法示例。


在下文中一共展示了Quaternion.SetEulerRotation方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: Start

    //    void OnDrawGizmos () {
    //        Debug.Log ("_________________________");
    //        Debug.Log (counter);
    //        Debug.Log ("_________________________");
    //        if (vertices == null || counter == 5)
    //            return;
    //        Gizmos.color = Color.black;
    //        for (int i = 0; i <vertices.Length; i++) {
    //            //Debug.Log (i);
    //            if (vertices [i] != null) {
    //                Gizmos.DrawSphere (vertices [i], .05f);
    //                Debug.Log (vertices[i]);
    //                Debug.Log("Point: "+vertices[i/2]);
    //            } else {
    //                Debug.Log ("NULL");
    //            }
    //        }
    //    }
    // Use this for initialization
    void Start()
    {
        lastRightFence = new Vector3 ();
        lastLeftFence = new Vector3 ();
        lastLeftDxDy = new Vector3 ();
        lastRightDxDy = new Vector3 ();
        Mesh mesh = new Mesh ();
        MeshFilter m = GetComponent<MeshFilter>();
        m.mesh.Clear ();
        //
        string text = System.IO.File.ReadAllText(Application.dataPath + "/Scripts/WriteToFile.txt");
        string[] lines = text.Split ('\n');
        string sep = "\t";
        Vector3 oldV = new Vector3();
        List<Vector3> array = new List<Vector3> ();
        for (int i=0; i<lines.Length-1; i++) {
            string s = lines [i];
            string[] split = s.Split (sep.ToCharArray());
            float x = float.Parse (split [0]);
            float y = float.Parse (split [1]);
            float z = float.Parse (split [2]);
            Vector3 tempp = new Vector3 (x, y, z);
            if (Vector3.Magnitude (tempp - oldV) < MIN_DISTANCE)
                continue;
            array.Add(tempp);
            oldV = tempp;
        }

        Vector3[] sampleinput = array.ToArray ();
        vertices = new Vector3[sampleinput.Length * 2];
        float dz = sampleinput[1].z - sampleinput[0].z;
        float dx = sampleinput[1].x - sampleinput[0].x;

        temp.Set (-1 * dz, dx);
        temp.Normalize();
        temp *= width;

        float moveZ = temp.y;
        float moveX = temp.x;

        vertices [0] = new Vector3 (sampleinput [0].x + moveX, 0, sampleinput [0].z + moveZ);
        vertices [1] = new Vector3 (sampleinput [0].x - moveX, 0, sampleinput [0].z - moveZ);

        //-------------------------------------------------------
        Transform fence = GameObject.FindGameObjectWithTag("FenceHolder").transform;
        ArrayList fences = new ArrayList ();
        for (int i = 1; i < sampleinput.Length-1; i++) {
            //			if (i % 10 == 0) {
            //				GameObject o = Instantiate (Resources.Load ("BetterFence"), sampleinput [i], Quaternion.identity) as GameObject;
            //				o.transform.SetParent (fence);
            //				fences.Add (o);
            //			}
            dz = sampleinput[i+1].z - sampleinput[i-1].z;
            dx = sampleinput[i+1].x - sampleinput[i-1].x;
            temp.Set (-1 * dz, dx);
            temp.Normalize();
            temp *= width;

            moveZ = temp.y;
            moveX = temp.x;

            vertices [i*2] = new Vector3 (sampleinput [i].x + moveX, 0, sampleinput [i].z + moveZ);
            vertices [i*2 + 1] = new Vector3 (sampleinput [i].x - moveX, 0, sampleinput [i].z - moveZ);
            if (lastLeftFence == null || Vector3.Distance(lastLeftFence,vertices[i*2]) > FENCE_LENGTH) {
                Vector3 tempp;
                if (lastLeftDxDy == null) {
                    tempp = vertices [i * 2];
                    lastLeftDxDy.Set (moveX, 0, moveZ);
                    lastLeftDxDy.Normalize ();
                } else {
                    tempp = lastLeftFence + (lastLeftDxDy * FENCE_LENGTH / 2);
                    lastLeftDxDy.Set (moveX, 0, moveZ);
                    lastLeftDxDy.Normalize ();
                    tempp += (lastLeftDxDy * FENCE_LENGTH / 2);
                }
                lastLeftFence = vertices [i * 2];

                float angle = Mathf.Atan (lastLeftDxDy.x / lastLeftDxDy.z);
                Quaternion q = new Quaternion ();
                q.SetEulerRotation (0, angle, 0);
                GameObject o1 = Instantiate (Resources.Load ("BetterFence"), tempp,q) as GameObject;
//.........這裏部分代碼省略.........
開發者ID:intel-cornellcup,項目名稱:mini-modbot-simulation,代碼行數:101,代碼來源:CreateRoad.cs


注:本文中的UnityEngine.Quaternion.SetEulerRotation方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。