Ejemplo n.º 1
0
        protected override void OnAttach()
        {
            InternalRigidBody = new BulletSharp.RigidBody(0.0f, MotionState, ColliderShape.InternalShape, Vector3.Zero)
            {
                UserObject = this
            };

            NativeCollisionObject = InternalRigidBody;

            NativeCollisionObject.ContactProcessingThreshold = !Simulation.CanCcd ? 1e18f : 1e30f;

            if (ColliderShape.NeedsCustomCollisionCallback)
            {
                NativeCollisionObject.CollisionFlags |= BulletSharp.CollisionFlags.CustomMaterialCallback;
            }

            if (ColliderShape.Is2D) //set different defaults for 2D shapes
            {
                InternalRigidBody.LinearFactor  = new Vector3(1.0f, 1.0f, 0.0f);
                InternalRigidBody.AngularFactor = new Vector3(0.0f, 0.0f, 1.0f);
            }

            var inertia = ColliderShape.InternalShape.CalculateLocalInertia(mass);

            InternalRigidBody.SetMassProps(mass, inertia);
            InternalRigidBody.UpdateInertiaTensor(); //this was the major headache when I had to debug Slider and Hinge constraint

            base.OnAttach();

            Mass            = mass;
            LinearDamping   = linearDamping;
            AngularDamping  = angularDamping;
            OverrideGravity = overrideGravity;
            Gravity         = gravity;
            RigidBodyType   = IsKinematic ? RigidBodyTypes.Kinematic : RigidBodyTypes.Dynamic;

            GetWorldTransformCallback = (out Matrix transform) => RigidBodyGetWorldTransform(out transform);
            SetWorldTransformCallback = transform => RigidBodySetWorldTransform(ref transform);

            UpdatePhysicsTransformation(); //this will set position and rotation of the collider

            if (IsDefaultGroup)
            {
                Simulation.AddRigidBody(this, CollisionFilterGroupFlags.DefaultFilter, CollisionFilterGroupFlags.AllFilter);
            }
            else
            {
                Simulation.AddRigidBody(this, (CollisionFilterGroupFlags)CollisionGroup, CanCollideWith);
            }
        }
Ejemplo n.º 2
0
        // Methods
        public override void Load(Stream fileStream)
        {
            var reader = new BINAReader(fileStream);

            Header      = reader.ReadHeader();
            IsBigEndian = reader.IsBigEndian;

            System.Console.WriteLine(reader.BaseStream.Position);
            RangeIn       = reader.ReadSingle(); // Unused
            RangeDistance = reader.ReadSingle(); // Unused

            ModelName = reader.GetString();
            reader.JumpAhead(12);

            SkeletonName = reader.GetString();
            reader.JumpAhead(12);

            BoundingShape = (BoundingShapes)reader.ReadUInt32();

            BoundingSize = reader.ReadVector3();

            MeshName = reader.GetString();
            reader.JumpAhead(20);

            ShapeOffset = reader.ReadVector3();
            reader.JumpAhead(4);
            ShapeSizeOffset = reader.ReadSingle();

            RigidBodyType     = (RigidBodyTypes)reader.ReadByte();
            RigidBodyMaterial = (RigidBodyMaterials)reader.ReadByte();
            reader.JumpAhead(2);

            _PhysicsParam = new PhysicsParam(reader);

            ContactDamageType = (ContactDamageTypes)reader.ReadByte();
            RideOnDamage      = reader.ReadBoolean();
            AerialBounce      = reader.ReadBoolean();

            reader.JumpAhead(9);

            // ReactionData
            for (uint i = 0; i < ReactionDataCount; i++)
            {
                _ReactionData[i] = new ReactionData(reader);
            }
        }
Ejemplo n.º 3
0
        protected override void OnAttach()
        {
            if (NativeCollisionObject == null)
            {
                MotionState = new XenkoMotionState(this);

                SetupBoneLink();

                var rbci = new BulletSharp.RigidBodyConstructionInfo(0.0f, MotionState, ColliderShape.InternalShape, Vector3.Zero);
                InternalRigidBody = new BulletSharp.RigidBody(rbci)
                {
                    UserObject = this,
                };

                NativeCollisionObject = InternalRigidBody;

                NativeCollisionObject.ContactProcessingThreshold = !Simulation.CanCcd ? 1e18f : 1e30f;
            }

            if (ColliderShape.NeedsCustomCollisionCallback)
            {
                NativeCollisionObject.CollisionFlags |= BulletSharp.CollisionFlags.CustomMaterialCallback;
            }

            if (ColliderShape.Is2D) //set different defaults for 2D shapes
            {
                InternalRigidBody.LinearFactor  = new Vector3(1.0f, 1.0f, 0.0f);
                InternalRigidBody.AngularFactor = new Vector3(0.0f, 0.0f, 1.0f);
            }

            var inertia = ColliderShape.InternalShape.CalculateLocalInertia(mass);

            InternalRigidBody.SetMassProps(mass, inertia);
            InternalRigidBody.UpdateInertiaTensor(); //this was the major headache when I had to debug Slider and Hinge constraint

            base.OnAttach();

            Mass            = mass;
            LinearDamping   = linearDamping;
            AngularDamping  = angularDamping;
            OverrideGravity = overrideGravity;
            Gravity         = gravity;
            RigidBodyType   = type;

            Simulation.AddRigidBody(this, (CollisionFilterGroupFlags)CollisionGroup, CanCollideWith);
        }
Ejemplo n.º 4
0
        public static CollidableMobility ToBepuCollidableType(this RigidBodyTypes rigidBodyType)
        {
            switch (rigidBodyType)
            {
            case RigidBodyTypes.Static:
                return(CollidableMobility.Static);

            case RigidBodyTypes.Dynamic:
                return(CollidableMobility.Dynamic);

            case RigidBodyTypes.Kinematic:
                return(CollidableMobility.Kinematic);

            default:
                Debug.Fail($"Unknown rigidBodyType: {rigidBodyType}");
                return(CollidableMobility.Static);
            }
        }
Ejemplo n.º 5
0
        public RigidBody(Shape shape, RigidBodyTypes bodyType, Material material, RigidBodyFlags flags = 0)
        {
            Debug.Assert(shape != null, "Shape can't be null.");
            Debug.Assert(material != null, "Material can't be null.");

            this.bodyType = bodyType;
            this.material = material;

            // Pseudo-static bodies, by design, are always manually controlled.
            if (bodyType == RigidBodyTypes.PseudoStatic)
            {
                flags |= RigidBodyFlags.IsManuallyControlled;
            }

            // TODO: Should pseudo-static bodies have deactivation allowed?
            // By default, all bodies start active (and with deactivation allowed).
            this.flags = flags | RigidBodyFlags.IsActive | RigidBodyFlags.IsDeactivationAllowed;

            readOnlyArbiters    = new ReadOnlyHashset <Arbiter>(arbiters);
            readOnlyConstraints = new ReadOnlyHashset <Constraint>(constraints);

            instance = Interlocked.Increment(ref instanceCount);
            hashCode = CalculateHash(instance);

            Shape       = shape;
            Damping     = DampingType.Angular | DampingType.Linear;
            orientation = JMatrix.Identity;

            if (!IsParticle)
            {
                updatedHandler      = ShapeUpdated;
                Shape.ShapeUpdated += updatedHandler;
                SetMassProperties();
            }
            else
            {
                inertia        = JMatrix.Zero;
                invInertia     = invInertiaWorld = JMatrix.Zero;
                invOrientation = orientation = JMatrix.Identity;
                inverseMass    = 1.0f;
            }

            Update();
        }
        protected override void OnAttach()
        {
            MotionState = new XenkoMotionState(this);

            SetupBoneLink();

            GetWorldTransformCallback = (out Matrix transform) => RigidBodyGetWorldTransform(out transform);
            SetWorldTransformCallback = transform => RigidBodySetWorldTransform(ref transform);

            InternalRigidBody = new BulletSharp.RigidBody(0.0f, MotionState, ColliderShape.InternalShape, Vector3.Zero)
            {
                UserObject = this
            };

            NativeCollisionObject = InternalRigidBody;

            NativeCollisionObject.ContactProcessingThreshold = !Simulation.CanCcd ? 1e18f : 1e30f;

            if (ColliderShape.NeedsCustomCollisionCallback)
            {
                NativeCollisionObject.CollisionFlags |= BulletSharp.CollisionFlags.CustomMaterialCallback;
            }

            if (ColliderShape.Is2D) //set different defaults for 2D shapes
            {
                InternalRigidBody.LinearFactor = new Vector3(1.0f, 1.0f, 0.0f);
                InternalRigidBody.AngularFactor = new Vector3(0.0f, 0.0f, 1.0f);
            }

            var inertia = ColliderShape.InternalShape.CalculateLocalInertia(mass);
            InternalRigidBody.SetMassProps(mass, inertia);
            InternalRigidBody.UpdateInertiaTensor(); //this was the major headache when I had to debug Slider and Hinge constraint

            base.OnAttach();

            Mass = mass;
            LinearDamping = linearDamping;
            AngularDamping = angularDamping;
            OverrideGravity = overrideGravity;
            Gravity = gravity;
            RigidBodyType = IsKinematic ? RigidBodyTypes.Kinematic : RigidBodyTypes.Dynamic;

            Simulation.AddRigidBody(this, (CollisionFilterGroupFlags)CollisionGroup, CanCollideWith);
        }
Ejemplo n.º 7
0
 public DummyCube(RigidBodyTypes bodyType, bool isAffectedByGravity, vec3 scale) : base(EntityGroups.Object)
 {
     this.bodyType            = bodyType;
     this.isAffectedByGravity = isAffectedByGravity;
     this.scale = scale;
 }
Ejemplo n.º 8
0
 public DummyCapsule(RigidBodyTypes bodyType) : base(EntityGroups.Object)
 {
     this.bodyType = bodyType;
 }
Ejemplo n.º 9
0
 public RigidBody(Shape shape, RigidBodyTypes bodyType, RigidBodyFlags flags = 0) :
     this(shape, bodyType, new Material(), flags)
 {
 }