/// <summary> /// Create the physical entity. /// </summary> /// <param name="shape">Collision shape that define this body.</param> /// <param name="mass">Body mass (in kg), or 0 for static.</param> /// <param name="inertia">Body inertia, or 0 for static.</param> /// <param name="transformations">Starting transformations.</param> public RigidBody(CollisionShapes.ICollisionShape shape, float mass = 10f, float inertia = 1f, Matrix?transformations = null) { // store collision shape _shape = shape; // set default transformations transformations = transformations ?? Matrix.Identity; // create starting state _state = new DefaultMotionState(ToBullet.Matrix((Matrix)(transformations))); // create the rigid body construction info RigidBodyConstructionInfo info = new RigidBodyConstructionInfo( mass, _state, shape.BulletCollisionShape, shape.BulletCollisionShape.CalculateLocalInertia(mass) * inertia); // create the rigid body itself and attach self to UserObject BulletRigidBody = new BulletSharp.RigidBody(info); BulletRigidBody.UserObject = this; // set default group and mask CollisionGroup = CollisionGroups.DynamicObjects; CollisionMask = CollisionMasks.Targets; // set some defaults InvokeCollisionEvents = true; IsEthereal = false; }
/// <summary> /// Create the static collision object from shape. /// </summary> /// <param name="shape">Collision shape that define this body.</param> /// <param name="transformations">Starting transformations.</param> public KinematicBody(CollisionShapes.ICollisionShape shape, Matrix?transformations = null) { // create the collision object _shape = shape; BulletCollisionObject = new CollisionObject(); BulletCollisionObject.CollisionShape = shape.BulletCollisionShape; // turn off simulation base.EnableSimulation = false; // set default group and mask CollisionGroup = CollisionGroups.DynamicObjects; CollisionMask = CollisionMasks.Targets; // if provided, set transformations if (transformations != null) { BulletCollisionObject.WorldTransform = ToBullet.Matrix(transformations.Value); } }
/// <summary> /// Remove a child shape from this compound shape. /// </summary> /// <param name="shape">Collision shape to remove.</param> public void RemoveShape(ICollisionShape shape) { var comShape = _shape as BulletSharp.CompoundShape; comShape.RemoveChildShape(shape.BulletCollisionShape); }
/// <summary> /// Add a child shape to this compound shape. /// </summary> /// <param name="shape">Collision shape to add.</param> /// <param name="transform">Transformations for child shape.</param> public void AddShape(ICollisionShape shape, Matrix?transform = null) { var comShape = _shape as BulletSharp.CompoundShape; comShape.AddChildShape(ToBullet.Matrix(transform ?? Matrix.Identity), shape.BulletCollisionShape); }