Esempio n. 1
0
        /// <summary>
        /// Initializes a new instance of the RigidBody class.
        /// </summary>
        /// <param name="shape">The shape of the body.</param>
        /// <param name="isParticle">If set to true the body doesn't rotate.
        /// Also contacts are only solved for the linear motion part.</param>
        public RigidBody(Shape shape, Material material, bool isParticle)
        {
            readOnlyArbiters    = new ReadOnlyHashset <Arbiter>(arbiters);
            readOnlyConstraints = new ReadOnlyHashset <Constraint>(constraints);

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

            this.Shape  = shape;
            orientation = JMatrix.Identity;

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

            this.material = material;

            AllowDeactivation         = true;
            EnableSpeculativeContacts = false;

            this.isParticle = isParticle;

            Update();
        }
Esempio n. 2
0
        public void Dispose()
        {
            material          = null;
            inactiveTime      = 0f;
            isActive          = false;
            isStatic          = false;
            affectedByGravity = false;

            island      = null;
            inverseMass = 0f;

            internalIndex  = 0;
            updatedHandler = null;
            connections.Clear();
            connections = null;

            arbiters.Clear();
            arbiters = null;

            constraints.Clear();
            constraints = null;

            readOnlyArbiters    = null;
            readOnlyConstraints = null;
        }
Esempio n. 3
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();
        }
Esempio n. 4
0
        public World(CollisionSystem collision)
        {
            CollisionSystem = collision ?? throw new ArgumentNullException("The CollisionSystem can't be null.", nameof(collision));

            arbiterCallback   = new Action <object>(ArbiterCallback);
            integrateCallback = new Action <object>(IntegrateCallback);

            RigidBodies = new ReadOnlyHashset <RigidBody>(rigidBodies);
            Constraints = new ReadOnlyHashset <Constraint>(constraints);
            SoftBodies  = new ReadOnlyHashset <SoftBody>(softbodies);

            collisionDetectionHandler = new CollisionDetectedHandler(CollisionDetected);

            CollisionSystem.CollisionDetected += collisionDetectionHandler;

            ArbiterMap = new ArbiterMap();

            AllowDeactivation = true;
        }
Esempio n. 5
0
        public World(CollisionSystem collision)
        {
            if (collision == null) throw new ArgumentNullException("collision", "The CollisionSystem can't be null.");

            arbiterCallback = ArbiterCallback;
            integrateCallback = IntegrateCallback;

            RigidBodies = new ReadOnlyHashset<RigidBody>(rigidBodies);
            Constraints = new ReadOnlyHashset<Constraint>(constraints);
            SoftBodies = new ReadOnlyHashset<SoftBody>(softbodies);

            CollisionSystem = collision;

            collisionDetectionHandler = CollisionDetected;

            CollisionSystem.CollisionDetected += collisionDetectionHandler;

            arbiterMap = new ArbiterMap();

            AllowDeactivation = true;
        }
Esempio n. 6
0
        public World(CollisionSystem collision)
        {
            if (collision == null) throw new ArgumentNullException("collision", "The CollisionSystem can't be null.");

            arbiterCallback = ArbiterCallback;
            integrateCallback = IntegrateCallback;

            RigidBodies = new ReadOnlyHashset<RigidBody>(rigidBodies);
            Constraints = new ReadOnlyHashset<Constraint>(constraints);
            SoftBodies = new ReadOnlyHashset<SoftBody>(softbodies);

            CollisionSystem = collision;

            collisionDetectionHandler = CollisionDetected;

            CollisionSystem.CollisionDetected += collisionDetectionHandler;

            arbiterMap = new ArbiterMap();

            AllowDeactivation = true;
        }
Esempio n. 7
0
        /// <summary>
        /// Initializes a new instance of the RigidBody class.
        /// </summary>
        /// <param name="shape">The shape of the body.</param>
        public RigidBody(Shape shape, Material material)
        {
            readOnlyArbiters    = new ReadOnlyHashset <Arbiter>(arbiters);
            readOnlyConstraints = new ReadOnlyHashset <Constraint>(constraints);

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

            this.Shape  = shape;
            orientation = JMatrix.Identity;

            updatedHandler = new ShapeUpdatedHandler(ShapeUpdated);

            this.Shape.ShapeUpdated += updatedHandler;

            SetMassProperties();

            this.material = material;

            AllowDeactivation = true;

            Update();
        }
Esempio n. 8
0
        /// <summary>
        /// Create a new instance of the <see cref="World"/> class.
        /// </summary>
        /// <param name="collision">The collisionSystem which is used to detect
        /// collisions. See for example: <see cref="CollisionSystemSAP"/>
        /// or <see cref="CollisionSystemBrute"/>.
        /// </param>
        public World(CollisionSystem system)
        {
            Debug.Assert(system != null, "Collision system can't be null.");

            Arbiter.World = this;

            arbiterCallback   = ArbiterCallback;
            integrateCallback = IntegrateCallback;

            // Create the readonly wrappers
            this.RigidBodies = new ReadOnlyHashset <RigidBody>(rigidBodies);
            this.Constraints = new ReadOnlyHashset <Constraint>(constraints);
            this.SoftBodies  = new ReadOnlyHashset <SoftBody>(softbodies);

            this.CollisionSystem = system;

            collisionDetectionHandler = new CollisionDetectedHandler(CollisionDetected);

            this.CollisionSystem.CollisionDetected += collisionDetectionHandler;

            this.arbiterMap = new ArbiterMap();

            AllowDeactivation = true;
        }
Esempio n. 9
0
        /// <summary>
        /// Initializes a new instance of the RigidBody class.
        /// </summary>
        /// <param name="shape">The shape of the body.</param>
        /// <param name="isParticle">If set to true the body doesn't rotate.
        /// Also contacts are only solved for the linear motion part.</param>
        public RigidBody(CommonData commonData, Shape shape, Material material, bool isParticle)
        {
            this.commonData      = commonData;
            this.DisableRotation = false;

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

            instance = Interlocked.Increment(ref commonData.RigidBody_instanceCount);
            hashCode = CalculateHash(instance);

            this.Shape  = shape;
            orientation = 0.0f;

            if (!isParticle)
            {
                updatedHandler           = new ShapeUpdatedHandler(ShapeUpdated);
                this.Shape.ShapeUpdated += updatedHandler;
                SetMassProperties();
            }
            else
            {
                this.inertia        = 0.0f;
                this.invInertia     = 0.0f;
                this.invOrientation = this.orientation = 0.0f;
                inverseMass         = 1.0f;
            }

            this.material = material;

            AllowDeactivation = true;

            this.isParticle = isParticle;

            Update();
        }
Esempio n. 10
0
 /// Constructor of CollisionIsland class.
 /// </summary>
 public CollisionIsland()
 {
     readOnlyBodies      = new ReadOnlyHashset <RigidBody>(bodies);
     readOnlyArbiter     = new ReadOnlyHashset <Arbiter>(arbiter);
     readOnlyConstraints = new ReadOnlyHashset <Constraint>(constraints);
 }
Esempio n. 11
0
 /// Constructor of CollisionIsland class.
 /// </summary>
 public CollisionIsland()
 {
     readOnlyBodies = new ReadOnlyHashset<RigidBody>(bodies);
     readOnlyArbiter = new ReadOnlyHashset<Arbiter>(arbiter);
     readOnlyConstraints = new ReadOnlyHashset<Constraint>(constraints);
 }