Exemple #1
0
            protected void AddPolygonalChain(Vector3[] points, double radius, double drawShadowsFactor)
            {
                if (points.Length < 2)
                {
                    return;
                }

                double radius2 = radius;

                if (drawShadowsFactor != 0)
                {
                    radius2 *= 2.5 * drawShadowsFactor;                    //2.7f;
                }
                Vector3 center = Vector3.Zero;

                foreach (Vector3 point in points)
                {
                    center += point;
                }
                center /= points.Length;

                Vector3[] localPoints = new Vector3[points.Length];
                for (int n = 0; n < points.Length; n++)
                {
                    localPoints[n] = points[n] - center;
                }

                Vector3[] positions;
                int[]     indices;
                SimpleMeshGenerator.GeneratePolygonalChain(localPoints, radius2, out positions, out indices);

                Matrix4 transform = Matrix4.FromTranslate(center);

                DebugGeometry.AddTriangles(positions, indices, transform, false, true);

                //for( int n = 0; n < points.Length - 1; n++ )
                //{
                //   Vec3 p1 = points[ n ];
                //   Vec3 p2 = points[ n + 1 ];
                //   AddLine( p1, p2, thickness, drawShadows );
                //}
            }
Exemple #2
0
        public void GetGeometry(out Vector3[] vertices, out int[] indices)
        {
            switch (Shape.Value)
            {
            case ShapeEnum.Box:
            {
                SimpleMeshGenerator.GenerateBox(Vector3.One, out Vector3[] verticesLocal, out indices);

                var transform = Transform.Value.ToMatrix4();

                vertices = new Vector3[verticesLocal.Length];
                for (int n = 0; n < vertices.Length; n++)
                {
                    vertices[n] = transform * verticesLocal[n];
                }
            }
            break;

            case ShapeEnum.Cylinder:
            {
                var cylinder = GetCylinder();

                SimpleMeshGenerator.GenerateCylinder(2, cylinder.Radius, cylinder.GetLength(), 16, true, true, true, out Vector3[] verticesLocal, out indices);

                var transform = Transform.Value.UpdateScale(Vector3.One);

                vertices = new Vector3[verticesLocal.Length];
                for (int n = 0; n < vertices.Length; n++)
                {
                    vertices[n] = transform * verticesLocal[n];
                }
            }
            break;

            default:
                vertices = null;
                indices  = null;
                break;
            }
        }