public MeshColliderShape(Simulation simulation, Vector3[] vertices,
                                 int[] indices, Vector3 scaling)
        {
            Vertices = vertices;
            Indices  = indices;

            simulation.BufferPool.Take <Triangle>(indices.Length / 3, out var triangles);
            for (int i = 0; i < triangles.Length; ++i)
            {
                var i1 = indices[(i * 3) + 0];
                var i2 = indices[(i * 3) + 1];
                var i3 = indices[(i * 3) + 2];

                var vert1 = vertices[i1];
                var vert2 = vertices[i2];
                var vert3 = vertices[i3];

                triangles[i] = new Triangle(
                    new System.Numerics.Vector3(vert1.X, vert1.Y, vert1.Z),
                    new System.Numerics.Vector3(vert2.X, vert2.Y, vert2.Z),
                    new System.Numerics.Vector3(vert3.X, vert3.Y, vert3.Z));
            }

            var mesh = new Mesh(triangles,
                                new System.Numerics.Vector3(scaling.X, scaling.Y, scaling.Z), simulation.BufferPool);

            InternalShape      = mesh;
            InternalShapeIndex = simulation.AddShape(mesh);

            DebugPrimitiveMatrix = Matrix.Scaling(Vector3.One * DebugScaling);
        }
        public BoxColliderShape(Simulation simulation, Vector3 size)
        {
            var box = new Box(size.X, size.Y, size.Z);

            InternalShape      = box;
            InternalShapeIndex = simulation.AddShape(box);

            DebugPrimitiveMatrix = Matrix.Scaling(size * DebugScaling);
        }
        public SphereColliderShape(Simulation simulation, float radius)
        {
            Radius = radius;

            var sphere = new Sphere(radius);

            InternalShape      = sphere;
            InternalShapeIndex = simulation.AddShape(sphere);

            DebugPrimitiveMatrix = Matrix.Scaling(new Vector3(DebugScaling));
        }
        public CylinderColliderShape(Simulation simulation, float radius, float length)
        {
            Radius = radius;
            Length = length;

            var cylinder = new Cylinder(radius, length);

            InternalShape      = cylinder;
            InternalShapeIndex = simulation.AddShape(cylinder);

            DebugPrimitiveMatrix = Matrix.Scaling(new Vector3(Radius * 2, Length, Radius * 2) * DebugScaling);
        }
Exemple #5
0
        public CapsuleColliderShape(Simulation simulation, float radius, float length)
        {
            Radius = radius;
            Length = length;

            var capsule = new Capsule(radius, length);

            InternalShape      = capsule;
            InternalShapeIndex = simulation.AddShape(capsule);

            DebugPrimitiveMatrix = Matrix.Scaling(new Vector3(DebugScaling));
        }