/// <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(); }
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; }
public RigidBody(Shape shape, BodyMaterial material, bool isParticle) { this.readOnlyArbiters = new ReadOnlyHashset <Arbiter>(this.arbiters); this.readOnlyConstraints = new ReadOnlyHashset <Constraint>(this.constraints); RigidBody.instanceCount++; this.instance = RigidBody.instanceCount; this.hashCode = this.CalculateHash(this.instance); this.Shape = shape; this.orientation = TSMatrix.Identity; bool flag = !isParticle; if (flag) { this.updatedHandler = new ShapeUpdatedHandler(this.ShapeUpdated); this.Shape.ShapeUpdated += this.updatedHandler; this.SetMassProperties(); } else { this.inertia = TSMatrix.Zero; this.invInertia = (this.invInertiaWorld = TSMatrix.Zero); this.invOrientation = (this.orientation = TSMatrix.Identity); this.inverseMass = FP.One; } this.material = material; this.AllowDeactivation = true; this.EnableSpeculativeContacts = false; this.isParticle = isParticle; this.Update(); }
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(); }
/// <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(); }
/// <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(); }