예제 #1
0
        public static List <VertexPositionColor> GetTriangleStrip(Vector3[] points, float thickness, Color color, ref int triangleCount, Matrix worldMatrix)
        {
            Vector3 lastPoint = Vector3.Zero;
            List <VertexPositionColor> list = new List <VertexPositionColor>();


            for (int i = 0; i < points.Length; i++)
            {
                if (i == 0)
                {
                    lastPoint = points[i];
                    continue;
                }
                Vector3 t1        = Vector3.Transform(lastPoint, worldMatrix);
                Vector3 t2        = Vector3.Transform(points[i], worldMatrix);
                Vector3 direction = t1 - t2;
                Vector3 normal    = Vector3.Cross(direction,
                                                  MathFunctions.GetClosestPointOnLineSegment(t1, t2, Camera.Position) - Camera.Position);
                direction.Normalize();
                normal.Normalize();


                Vector3 p1 = t1 + normal * thickness;
                Vector3 p2 = t1 - normal * thickness;
                Vector3 p3 = t2 + normal * thickness;
                Vector3 p4 = t2 - normal * thickness;

                list.Add(new VertexPositionColor(p1, color));
                list.Add(new VertexPositionColor(p2, color));
                list.Add(new VertexPositionColor(p3, color));
                list.Add(new VertexPositionColor(p4, color));

                triangleCount += 2;

                lastPoint = points[i];
            }

            return(list);
        }