GetPosition() публичный Метод

Get the position of the vertex in the line.

public GetPosition ( int index ) : Vector3
index int The index of the position to retrieve.
Результат Vector3
 static public int GetPosition(IntPtr l)
 {
     try {
                     #if DEBUG
         var    method     = System.Reflection.MethodBase.GetCurrentMethod();
         string methodName = GetMethodName(method);
                     #if UNITY_5_5_OR_NEWER
         UnityEngine.Profiling.Profiler.BeginSample(methodName);
                     #else
         Profiler.BeginSample(methodName);
                     #endif
                     #endif
         UnityEngine.LineRenderer self = (UnityEngine.LineRenderer)checkSelf(l);
         System.Int32             a1;
         checkType(l, 2, out a1);
         var ret = self.GetPosition(a1);
         pushValue(l, true);
         pushValue(l, ret);
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
             #if DEBUG
     finally {
                     #if UNITY_5_5_OR_NEWER
         UnityEngine.Profiling.Profiler.EndSample();
                     #else
         Profiler.EndSample();
                     #endif
     }
             #endif
 }
Пример #2
0
 static public int GetPosition(IntPtr l)
 {
     try {
         UnityEngine.LineRenderer self = (UnityEngine.LineRenderer)checkSelf(l);
         System.Int32             a1;
         checkType(l, 2, out a1);
         var ret = self.GetPosition(a1);
         pushValue(l, ret);
         return(1);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
 static int GetPosition(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 2);
         UnityEngine.LineRenderer obj = (UnityEngine.LineRenderer)ToLua.CheckObject(L, 1, typeof(UnityEngine.LineRenderer));
         int arg0 = (int)LuaDLL.luaL_checknumber(L, 2);
         UnityEngine.Vector3 o = obj.GetPosition(arg0);
         ToLua.Push(L, o);
         return(1);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
Пример #4
0
        public void crossSectTetrahedron(Unity.Mathematics.float3 point, Unity.Mathematics.float3 normalDirection,
                                         Unity.Mathematics.float3x4 vertices, UnityEngine.Mesh tetrahedronMesh)
        {
            //take vertices and organize them into clockwise triangles to be passed to triangle intersection function
            Unity.Mathematics.float3 a = vertices.c0;
            Unity.Mathematics.float3 b = vertices.c1;
            Unity.Mathematics.float3 c = vertices.c2;
            Unity.Mathematics.float3 d = vertices.c3;

            Unity.Mathematics.float3[] triangle1 = { a, b, c };
            Unity.Mathematics.float3[] triangle2 = { a, c, d };
            Unity.Mathematics.float3[] triangle3 = { a, d, b };
            Unity.Mathematics.float3[] triangle4 = { b, c, d };

            Unity.Mathematics.float3 triangle1point = a;
            Unity.Mathematics.float3 triangle2point = a;
            Unity.Mathematics.float3 triangle3point = a;
            Unity.Mathematics.float3 triangle4point = b;

            Unity.Mathematics.float3 triangle1Normal =
                Unity.Mathematics.math.cross(UnityEngine.Vector3.Normalize(c - a),
                                             UnityEngine.Vector3.Normalize(b - a));
            Unity.Mathematics.float3 triangle2Normal =
                Unity.Mathematics.math.cross(UnityEngine.Vector3.Normalize(c - a),
                                             UnityEngine.Vector3.Normalize(d - a));
            Unity.Mathematics.float3 triangle3Normal =
                Unity.Mathematics.math.cross(UnityEngine.Vector3.Normalize(d - a),
                                             UnityEngine.Vector3.Normalize(b - a));
            Unity.Mathematics.float3 triangle4Normal =
                Unity.Mathematics.math.cross(UnityEngine.Vector3.Normalize(c - b),
                                             UnityEngine.Vector3.Normalize(d - b));

            //TODO make this pretty
            UnityEngine.LineRenderer crossSectionRenderer1 = triXC[0].GetComponent <UnityEngine.LineRenderer>();
            UnityEngine.LineRenderer crossSectionRenderer2 = triXC[1].GetComponent <UnityEngine.LineRenderer>();
            UnityEngine.LineRenderer crossSectionRenderer3 = triXC[2].GetComponent <UnityEngine.LineRenderer>();
            UnityEngine.LineRenderer crossSectionRenderer4 = triXC[3].GetComponent <UnityEngine.LineRenderer>();

            int vertCount = 0;

            bool line1 = false, line2 = false, line3 = false, line4 = false;

            if (crossSectionRenderer1.enabled)
            {
                vertCount++;
                line1 = true;
            }

            if (crossSectionRenderer2.enabled)
            {
                vertCount++;
                line2 = true;
            }

            if (crossSectionRenderer3.enabled)
            {
                vertCount++;
                line3 = true;
            }

            if (crossSectionRenderer4.enabled)
            {
                vertCount++;
                line4 = true;
            }

            //Intersection is Triangle
            if (vertCount == 3)
            {
                //verts
                UnityEngine.Vector3[] verts = new UnityEngine.Vector3[3];

                if (line1 && line2 && line3)
                {
                    //a way to avoid checking orientation of line segments
                    verts[0] = crossSectionRenderer1.GetPosition(0);
                    verts[1] = crossSectionRenderer1.GetPosition(1);
                    verts[2] =
                        crossSectionRenderer2.GetPosition(1) == verts[0] ||
                        crossSectionRenderer2.GetPosition(1) == verts[1]
                            ? crossSectionRenderer2.GetPosition(0)
                            : crossSectionRenderer2.GetPosition(1);
                }

                else if (line1 && line2 && line4)
                {
                    verts[0] = crossSectionRenderer1.GetPosition(0);
                    verts[1] = crossSectionRenderer1.GetPosition(1);
                    verts[2] =
                        crossSectionRenderer2.GetPosition(1) == verts[0] ||
                        crossSectionRenderer2.GetPosition(1) == verts[1]
                            ? crossSectionRenderer2.GetPosition(0)
                            : crossSectionRenderer2.GetPosition(1);
                }

                else if (line1 && line3 && line4)
                {
                    verts[0] = crossSectionRenderer1.GetPosition(0);
                    verts[1] = crossSectionRenderer1.GetPosition(1);
                    verts[2] =
                        crossSectionRenderer3.GetPosition(1) == verts[0] ||
                        crossSectionRenderer3.GetPosition(1) == verts[1]
                            ? crossSectionRenderer3.GetPosition(0)
                            : crossSectionRenderer3.GetPosition(1);
                }

                else if (line2 && line3 && line4)
                {
                    verts[0] = crossSectionRenderer2.GetPosition(0);
                    verts[1] = crossSectionRenderer2.GetPosition(1);
                    verts[2] =
                        crossSectionRenderer3.GetPosition(1) == verts[0] ||
                        crossSectionRenderer3.GetPosition(1) == verts[1]
                            ? crossSectionRenderer3.GetPosition(0)
                            : crossSectionRenderer3.GetPosition(1);
                }
                tetrahedronMesh.vertices = verts;

                //tris
                int[] tris = { 0, 1, 2 };
                tetrahedronMesh.triangles = tris;
            }
            //Intersection is quadrilateral
            else if (vertCount == 4)
            {
                //verts
                UnityEngine.Vector3[] verts = new UnityEngine.Vector3[4];

                verts[0] = crossSectionRenderer2.GetPosition(0);
                verts[1] = crossSectionRenderer2.GetPosition(1);
                verts[2] =
                    (crossSectionRenderer3.GetPosition(1) == verts[0] ||
                     crossSectionRenderer3.GetPosition(1) == verts[1])
                        ? crossSectionRenderer3.GetPosition(0)
                        : crossSectionRenderer3.GetPosition(1);
                verts[3] =
                    (crossSectionRenderer4.GetPosition(1) == verts[0] ||
                     crossSectionRenderer4.GetPosition(1) == verts[1] ||
                     crossSectionRenderer4.GetPosition(1) == verts[2])
                        ? crossSectionRenderer4.GetPosition(0)
                        : crossSectionRenderer4.GetPosition(1);

                tetrahedronMesh.vertices = verts;

                //tris
                //find the opposite corner to #0
                //assume 0,1,2,3
                float3 cross0 = IMRE.Math.Operations.AngleCrossProduct(verts, 3, 0, 1);
                //float3 cross1 = Unity.Mathematics.math.cross(verts[3] - verts[0], verts[1] - verts[0]);
                //float3 cross1 = Unity.Mathematics.math.cross(verts[a] - verts[b], verts[c] - verts[b]);
                float3 cross1 = IMRE.Math.Operations.AngleCrossProduct(verts, 0, 1, 2);
                float3 cross2 = IMRE.Math.Operations.AngleCrossProduct(verts, 1, 2, 3);
                float3 cross3 = IMRE.Math.Operations.AngleCrossProduct(verts, 2, 3, 0);

                int[] tris = { 0, 1, 2, 0, 2, 3 };
                if (!(cross0.Equals(cross1) && cross1.Equals(cross2) && cross2.Equals(cross3)))
                {
                    //assume 0,1,3,2
                    cross0 = IMRE.Math.Operations.AngleCrossProduct(verts, 2, 0, 1);
                    cross1 = IMRE.Math.Operations.AngleCrossProduct(verts, 0, 1, 3);
                    cross2 = IMRE.Math.Operations.AngleCrossProduct(verts, 1, 3, 2);
                    cross3 = IMRE.Math.Operations.AngleCrossProduct(verts, 3, 2, 0);

                    tris = new int[] { 0, 1, 3, 0, 3, 2 };

                    if (!(cross0.Equals(cross1) && cross1.Equals(cross2) && cross2.Equals(cross3)))
                    {
                        //assume 0,2,1,3 (switch 1 and 2)
                        cross0 = IMRE.Math.Operations.AngleCrossProduct(verts, 3, 0, 2);
                        cross1 = IMRE.Math.Operations.AngleCrossProduct(verts, 0, 2, 1);
                        cross2 = IMRE.Math.Operations.AngleCrossProduct(verts, 2, 1, 3);
                        cross3 = IMRE.Math.Operations.AngleCrossProduct(verts, 1, 3, 0);
                        if (!(cross0.Equals(cross1) && cross1.Equals(cross2) && cross2.Equals(cross3)))
                        {
                            UnityEngine.Debug.LogWarning("failed check on vertex ordering");
                        }
                        tris = new int[] { 0, 2, 1, 0, 1, 3 };
                    }
                }
                tetrahedronMesh.triangles = tris;
            }
        }