Example #1
0
        /// <summary>
        /// Creates a sphere body.
        /// </summary>
        /// <param name="simulation">The simulation to use.</param>
        /// <param name="position">The position of the body.</param>
        /// <param name="radius">The radius of the sphere.</param>
        /// <returns>The sphere body that was created.</returns>
        public static SphereBody Create(PhysicsSimulation simulation, Vector3 position, float radius)
        {
            var obj = new SphereBody(simulation);

            obj.Position = position;
            obj.Radius   = radius;
            simulation.Register(obj);
            return(obj);
        }
Example #2
0
        /// <summary>
        /// Creates a box body.
        /// </summary>
        /// <param name="simulation">The simulation to use.</param>
        /// <param name="position">The position of the body.</param>
        /// <param name="rotation">The rotation of the body.</param>
        /// <param name="size">The size of the body (length in x, y and z direction).</param>
        /// <returns>The box body that was created.</returns>
        public static BoxBody Create(PhysicsSimulation simulation, Vector3 position, Quaternion rotation, Vector3 size)
        {
            var obj = new BoxBody(simulation);

            obj.Size     = size;
            obj.Position = position;
            obj.Rotation = rotation;
            obj.Vertices = FindVertices(obj);
            simulation.Register(obj);
            return(obj);
        }
Example #3
0
        /// <summary>
        /// Creates a capsule body.
        /// </summary>
        /// <param name="simulation">The simulation to use.</param>
        /// <param name="position">The position of the body.</param>
        /// <param name="rotation">The rotation of the body.</param>
        /// <param name="radius">The radius of the capsule.</param>
        /// <param name="height">The height of the cylinder part of the capsule.</param>
        /// <returns>The capsule body that was created.</returns>
        public static CapsuleBody Create(PhysicsSimulation simulation, Vector3 position, Quaternion rotation,
                                         float radius, float height)
        {
            var obj = new CapsuleBody(simulation);

            obj.Position = position;
            obj.Rotation = rotation;
            obj.Radius   = radius;
            obj.Height   = height;
            simulation.Register(obj);
            return(obj);
        }
Example #4
0
        public static TriggerBox Create(PhysicsSimulation simulation, Vector3 position, Quaternion rotation, Vector3 size)
        {
            var shape = new Box(size.X, size.Y, size.Z);

            var index = simulation.Simulation.Shapes.Add(shape);

            var collidable = new CollidableDescription(index, 0.01f);

            var descriptor = new StaticDescription(position, rotation, collidable);

            var handle = simulation.Simulation.Statics.Add(descriptor);

            var obj = new TriggerBox(simulation, handle);

            simulation.Register(obj);

            return(obj);
        }
Example #5
0
        public static CylinderBody Create(PhysicsSimulation simulation, Vector3 position, Quaternion rotation, Vector2 size)
        {
            var shape = new Cylinder(size.X, size.Y);

            shape.ComputeInertia(1, out var inertia);

            var index = simulation.Simulation.Shapes.Add(shape);

            var collidable = new CollidableDescription(index, 0.1f);

            var activity = new BodyActivityDescription(0);

            var pose = new RigidPose(position, rotation);

            var descriptor = BodyDescription.CreateDynamic(pose, inertia, collidable, activity);

            var handle = simulation.Simulation.Bodies.Add(descriptor);

            var obj = new CylinderBody(simulation, handle);

            simulation.Register(obj);

            return(obj);
        }