private void GetCursorIntersectionPoint( ref Vec3 clippedMouseNear, ref Vec3 clippedMouseFar, out float closestDistanceSquared, out Vec3 intersectionPoint, ref PathFaceRecord currentFace, BodyFlags excludedBodyFlags = BodyFlags.CommonFocusRayCastExcludeFlags) { double num = (double)(clippedMouseFar - clippedMouseNear).Normalize(); this.MissionScreen.SceneLayer.SceneView.GetScene().GetBoundingBox(out Vec3 _, out Vec3 _); Vec3 direction = clippedMouseFar - clippedMouseNear; float maxDistance = direction.Normalize(); this._mouseRay.Reset(clippedMouseNear, direction, maxDistance); intersectionPoint = Vec3.Zero; closestDistanceSquared = 1E+12f; float collisionDistance; if (this.MissionScreen.SceneLayer.SceneView.GetScene().RayCastForClosestEntityOrTerrain(clippedMouseNear, clippedMouseFar, out collisionDistance, 0.01f, excludedBodyFlags)) { closestDistanceSquared = collisionDistance * collisionDistance; intersectionPoint = clippedMouseNear + direction * collisionDistance; } currentFace = Campaign.Current.MapSceneWrapper.GetFaceIndex(intersectionPoint.AsVec2); }
public Controlable( LifeSpan lifeTime, MassInertia massInfo, PhysicsState physicsState, BodyFlags flags, ICollidableBodyPart[] collidableParts, ShipMovementInfo movementInfo, ShipState shipState, ControlableSounds controlableSounds, IWeaponsLogic weaponInfo) : this( lifeTime, massInfo, physicsState, flags, collidableParts, movementInfo, shipState, controlableSounds) { this.CollisionState.GenerateCollisionEvents = true; this.CollisionState.GenerateContactEvents = true; this.weaponInfo = weaponInfo; this.controlableType = ControlableType.Weapon; }
internal bool SynchronizeShapes() { XForm xf1 = new XForm(); xf1.R.Set(_sweep.A0); xf1.Position = _sweep.C0 - Common.Math.Mul(xf1.R, _sweep.LocalCenter); bool inRange = true; for (Shape s = _shapeList; s != null; s = s._next) { inRange = s.Synchronize(_world._broadPhase, xf1, _xf); if (inRange == false) { break; } } if (inRange == false) { _flags |= BodyFlags.Frozen; _linearVelocity.SetZero(); _angularVelocity = 0.0f; for (Shape s = _shapeList; s != null; s = s._next) { s.DestroyProxy(_world._broadPhase); } // Failure return(false); } // Success return(true); }
internal bool SynchronizeFixtures() { Transform xf1 = default(Transform); xf1.rotation = Box2DX.Common.Math.AngleToRotation(_sweep.A0); //xf1.R = new Mat22(_sweep.A0); xf1.position = _sweep.C0 - xf1.TransformDirection(_sweep.LocalCenter); bool inRange = true; for (Fixture f = _fixtureList; f != null; f = f.Next) { inRange = f.Synchronize(_world._broadPhase, xf1, _xf); if (inRange == false) { break; } } if (inRange == false) { _flags |= BodyFlags.Frozen; _linearVelocity = Vector2.zero; _angularVelocity = 0.0f; // Failure return(false); } // Success return(true); }
public Ship( LifeSpan lifeTime, PhysicsState physicsState, BodyFlags flags, RigidBodyTemplate template, ShipMovementInfo movementInfo, ShipState shipState, ControlableSounds controlableSounds, ShipSounds shipSounds, ActionList actions, IShip[] subShips) : base( lifeTime, physicsState, flags, template, movementInfo, shipState, controlableSounds) { this.UQMFlags |= ContFlags.CanDoGravityWhip; this.shipSounds = shipSounds; this.subShips = subShips; this.actions = actions; this.controlableType = ControlableType.Ship; }
internal Transform _xf; // the body origin transform public Body(World world, Vector2 position = new Vector2(), float rotation = 0, BodyType bodyType = BodyType.Static, object userdata = null) { Debug.Assert(!float.IsNaN(position.X)); Debug.Assert(!float.IsNaN(position.Y)); Debug.Assert(!float.IsNaN(rotation)); FixtureList = new List <Fixture>(1); BodyId = _bodyIdCounter++; _world = world; _flags = BodyFlags.Enabled | BodyFlags.AwakeFlag | BodyFlags.AutoSleepFlag; UserData = userdata; GravityScale = 1.0f; _type = bodyType; _xf.q.Set(rotation); _xf.p = position; _sweep.C0 = _xf.p; _sweep.C = _xf.p; _sweep.A0 = rotation; _sweep.A = rotation; world.AddBody(this); //Velcro note: bodies can't live without a World }
/// <summary> /// Describes whether this instance synchronize fixtures /// </summary> /// <returns>The bool</returns> internal bool SynchronizeFixtures() { XForm xf1 = new XForm(); xf1.R.Set(Sweep.A0); xf1.Position = Sweep.C0 - Math.Mul(xf1.R, Sweep.LocalCenter); bool inRange = true; for (Fixture f = FixtureList; f != null; f = f.Next) { inRange = f.Synchronize(world.BroadPhase, xf1, Xf); if (inRange == false) { break; } } if (inRange == false) { Flags |= BodyFlags.Frozen; LinearVelocity.SetZero(); AngularVelocity = 0.0f; // Failure return(false); } // Success return(true); }
public Ship( LifeSpan lifeTime, MassInertia massInfo, PhysicsState physicsState, BodyFlags flags, ICollidableBodyPart[] collidableParts, ShipMovementInfo movementInfo, ShipState shipState, ControlableSounds controlableSounds, ShipSounds shipSounds, ActionList actions, IShip[] subShips) : base( lifeTime, massInfo, physicsState, flags, collidableParts, movementInfo, shipState, controlableSounds) { this.UQMFlags |= ContFlags.CanDoGravityWhip; this.shipSounds = shipSounds; this.subShips = subShips; this.actions = actions; this.controlableType = ControlableType.Ship; }
public int GenerateContactsWithCapsule( ref CapsuleData capsule, BodyFlags exclude_flags, Intersection[] intersectionsOutput) { return(EngineApplicationInterface.IScene.GenerateContactsWithCapsule(this.Pointer, ref capsule, exclude_flags, intersectionsOutput)); }
internal bool SynchronizeFixtures() { XForm xf1 = new XForm(); xf1.R.Set(_sweep.A0); xf1.Position = _sweep.C0 - Common.Math.Mul(xf1.R, _sweep.LocalCenter); bool inRange = true; for (Fixture f = _fixtureList; f != null; f = f.Next) { inRange = f.Synchronize(_world._broadPhase, xf1, _xf); if (inRange == false) { break; } } if (inRange == false) { _flags |= BodyFlags.Frozen; _linearVelocity.SetZero(); _angularVelocity = 0.0f; // Failure return(false); } // Success return(true); }
private Transform _xf; // the body origin transform #endregion Fields #region Constructors internal Body(BodyDef bd, World world) { _flags = 0; if (bd.IsBullet) { _flags |= BodyFlags.Bullet; } if (bd.FixedRotation) { _flags |= BodyFlags.FixedRotation; } if (bd.AllowSleep) { _flags |= BodyFlags.AllowSleep; } if (bd.IsSleeping) { _flags |= BodyFlags.Sleep; } _world = world; _xf.Position = bd.Position; _xf.R.Set(bd.Angle); _sweep.LocalCenter.SetZero(); _sweep.T0 = 1.0f; _sweep.A0 = _sweep.A = bd.Angle; _sweep.C0 = _sweep.C = Math.Mul(_xf, _sweep.LocalCenter); _jointList = null; _contactList = null; _prev = null; _next = null; _linearVelocity = bd.LinearVelocity; _angularVelocity = bd.AngularVelocity; _linearDamping = bd.LinearDamping; _angularDamping = bd.AngularDamping; _force.Set(0.0f, 0.0f); _torque = 0.0f; _sleepTime = 0.0f; _mass = 0; _invMass = 0.0f; _I = 0.0f; _invI = 0.0f; _type = BodyType.Static; _userData = bd.UserData; _fixtureList = null; _fixtureCount = 0; }
internal Body(BodyDef bd, World world) { _flags = 0; if (bd.IsBullet) { _flags |= BodyFlags.Bullet; } if (bd.FixedRotation) { _flags |= BodyFlags.FixedRotation; } if (bd.AllowSleep) { _flags |= BodyFlags.AllowSleep; } if (bd.IsSleeping) { _flags |= BodyFlags.Sleep; } _world = world; _xf.Position = bd.Position; _xf.R.Set(bd.Angle); _sweep.LocalCenter.SetZero(); _sweep.T0 = 1.0f; _sweep.A0 = _sweep.A = bd.Angle; _sweep.C0 = _sweep.C = Math.Mul(_xf, _sweep.LocalCenter); _jointList = null; _contactList = null; _prev = null; _next = null; _linearVelocity = bd.LinearVelocity; _angularVelocity = bd.AngularVelocity; _linearDamping = bd.LinearDamping; _angularDamping = bd.AngularDamping; _force.Set(0.0f, 0.0f); _torque = 0.0f; _sleepTime = 0.0f; _mass = 0; _invMass = 0.0f; _I = 0.0f; _invI = 0.0f; _type = BodyType.Static; _userData = bd.UserData; _fixtureList = null; _fixtureCount = 0; }
public RemoveMissionObjectBodyFlags( MissionObject missionObject, BodyFlags bodyFlags, bool applyToChildren) { this.MissionObject = missionObject; this.BodyFlags = bodyFlags; this.ApplyToChildren = applyToChildren; }
public SelectiveImpulseRay( LifeSpan lifeTime, RaySegment2D raySegment, float impulse, BodyFlags ignoreFlags) : base(lifeTime, raySegment, impulse) { this.ignoreFlags = ignoreFlags; }
/// <summary> /// Put this body to sleep so it will stop simulating. /// This also sets the velocity to zero. /// </summary> public void PutToSleep() { _flags |= BodyFlags.Sleep; _sleepTime = 0.0f; _linearVelocity.SetZero(); _angularVelocity = 0.0f; _force.SetZero(); _torque = 0.0f; }
/// <summary> /// Put this body to sleep so it will stop simulating. /// This also sets the velocity to zero. /// </summary> public void PutToSleep() { Flags |= BodyFlags.Sleep; SleepTime = 0.0f; LinearVelocity.SetZero(); AngularVelocity = 0.0f; Force.SetZero(); Torque = 0.0f; }
/// <summary> /// Put this body to sleep so it will stop simulating. /// This also sets the velocity to zero. /// </summary> public void PutToSleep() { _flags |= BodyFlags.Sleep; _sleepTime = 0.0f; _linearVelocity = Vector2.zero; _angularVelocity = 0.0f; _force = Vector2.zero; _torque = 0.0f; }
public Transform _xf; // the body origin transform internal Body(World world, BodyTemplate template) { FixtureList = new List <Fixture>(1); if (template.AllowCCD) { _flags |= BodyFlags.BulletFlag; } if (template.AllowRotation) { _flags |= BodyFlags.FixedRotationFlag; } if (template.AllowSleep) { _flags |= BodyFlags.AutoSleepFlag; } if (template.Awake) { _flags |= BodyFlags.AwakeFlag; } if (template.Active) { _flags |= BodyFlags.Enabled; } _world = world; _xf.p = template.Position; _xf.q.Set(template.Angle); _sweep.C0 = _xf.p; _sweep.C = _xf.p; _sweep.A0 = template.Angle; _sweep.A = template.Angle; _linearVelocity = template.LinearVelocity; _angularVelocity = template.AngularVelocity; LinearDamping = template.LinearDamping; AngularDamping = template.AngularDamping; GravityScale = 1.0f; _type = template.Type; if (_type == BodyType.Dynamic) { _mass = 1.0f; _invMass = 1.0f; } else { _mass = 0.0f; _invMass = 0.0f; } UserData = template.UserData; }
/// <summary> /// Should this body be treated like a bullet for continuous collision detection? /// </summary> /// <param name="flag"></param> public void SetBullet(bool flag) { if (flag) { _flags |= BodyFlags.Bullet; } else { _flags &= ~BodyFlags.Bullet; } }
/// <summary> /// You can disable sleeping on this body. /// </summary> /// <param name="flag"></param> public void AllowSleeping(bool flag) { if (flag) { _flags |= BodyFlags.AllowSleep; } else { _flags &= ~BodyFlags.AllowSleep; WakeUp(); } }
public bool SetTransform(Vector2 position, Quaternion rotation) #endif { Box2DXDebug.Assert(_world._lock == false); if (_world._lock == true) { return(true); } if (IsFrozen()) { return(false); } _xf.rotation = rotation; //_xf.R = rotation; _xf.position = position; _sweep.C0 = _sweep.C = _xf.TransformPoint(_sweep.LocalCenter); #if USE_MATRIX_FOR_ROTATION _sweep.A0 = _sweep.A = rotation.GetAngle(); #else _sweep.A0 = _sweep.A = rotation.eulerAngles.z * Mathf.Deg2Rad; #endif bool freeze = false; for (Fixture f = _fixtureList; f != null; f = f.Next) { bool inRange = f.Synchronize(_world._broadPhase, _xf, _xf); if (inRange == false) { freeze = true; break; } } if (freeze == true) { _flags |= BodyFlags.Frozen; _linearVelocity = Vector2.zero; _angularVelocity = 0.0f; // Failure return(false); } // Success _world._broadPhase.Commit(); return(true); }
/// <summary> /// Set the position of the body's origin and rotation (radians). /// This breaks any contacts and wakes the other bodies. /// </summary> /// <param name="position">The new world position of the body's origin (not necessarily /// the center of mass).</param> /// <param name="angle">The new world rotation angle of the body in radians.</param> /// <returns>Return false if the movement put a shape outside the world. In this case the /// body is automatically frozen.</returns> public bool SetXForm(Vec2 position, float angle) { Box2DXDebug.Assert(_world._lock == false); if (_world._lock == true) { return(true); } if (IsFrozen()) { return(false); } _xf.R.Set(angle); _xf.Position = position; _sweep.C0 = _sweep.C = Common.Math.Mul(_xf, _sweep.LocalCenter); _sweep.A0 = _sweep.A = angle; bool freeze = false; for (Shape s = _shapeList; s != null; s = s._next) { bool inRange = s.Synchronize(_world._broadPhase, _xf, _xf); if (inRange == false) { freeze = true; break; } } if (freeze == true) { _flags |= BodyFlags.Frozen; _linearVelocity.SetZero(); _angularVelocity = 0.0f; for (Shape s = _shapeList; s != null; s = s._next) { s.DestroyProxy(_world._broadPhase); } // Failure return(false); } // Success _world._broadPhase.Commit(); return(true); }
public void RemoveBodyFlagsSynched(BodyFlags flags, bool applyToChildren = true) { if ((this.GameEntity.BodyFlag & flags) == BodyFlags.None) { return; } if (GameNetwork.IsServerOrRecorder) { GameNetwork.BeginBroadcastModuleEvent(); GameNetwork.WriteMessage((GameNetworkMessage) new RemoveMissionObjectBodyFlags((MissionObject)this, flags, applyToChildren)); GameNetwork.EndBroadcastModuleEvent(GameNetwork.EventBroadcastFlags.AddToMissionRecord); } this.GameEntity.RemoveBodyFlags(flags, applyToChildren); this._initialSynchFlags |= SynchedMissionObject.SynchFlags.SynchBodyFlags; }
internal Body(BodyDef def) { _fixtureList = new List <Fixture>(1); if (def.IsBullet) { _flags |= BodyFlags.BulletFlag; } if (def.FixedRotation) { _flags |= BodyFlags.FixedRotationFlag; } if (def.AllowSleep) { _flags |= BodyFlags.AutoSleepFlag; } if (def.Awake) { _flags |= BodyFlags.AwakeFlag; } if (def.Enabled) { _flags |= BodyFlags.Enabled; } _xf.p = def.Position; _xf.q.Set(def.Angle); _sweep.C0 = _xf.p; _sweep.C = _xf.p; _sweep.A0 = def.Angle; _sweep.A = def.Angle; _linearVelocity = def.LinearVelocity; _angularVelocity = def.AngularVelocity; _linearDamping = def.LinearDamping; _angularDamping = def.AngularDamping; _gravityScale = def.GravityScale; _type = def.Type; _mass = 0.0f; _invMass = 0.0f; _userData = def.UserData; }
/// <summary> /// Set the position of the body's origin and rotation (radians). /// This breaks any contacts and wakes the other bodies. /// </summary> /// <param name="position"> /// The new world position of the body's origin (not necessarily /// the center of mass). /// </param> /// <param name="angle">The new world rotation angle of the body in radians.</param> /// <returns> /// Return false if the movement put a shape outside the world. In this case the /// body is automatically frozen. /// </returns> public bool SetXForm(Vec2 position, float angle) { Box2DxDebug.Assert(world.Lock == false); if (world.Lock) { return(true); } if (IsFrozen()) { return(false); } Xf.R.Set(angle); Xf.Position = position; Sweep.C0 = Sweep.C = Math.Mul(Xf, Sweep.LocalCenter); Sweep.A0 = Sweep.A = angle; bool freeze = false; for (Fixture f = FixtureList; f != null; f = f.Next) { bool inRange = f.Synchronize(world.BroadPhase, Xf, Xf); if (inRange == false) { freeze = true; break; } } if (freeze) { Flags |= BodyFlags.Frozen; LinearVelocity.SetZero(); AngularVelocity = 0.0f; // Failure return(false); } // Success world.BroadPhase.Commit(); return(true); }
/// <summary> /// Sets the fixed rotation using the specified fixedr /// </summary> /// <param name="fixedr">The fixedr</param> public void SetFixedRotation(bool fixedr) { if (fixedr) { AngularVelocity = 0.0f; InvI = 0.0f; Flags |= BodyFlags.FixedRotation; } else { if (I > 0.0f) { // Recover _invI from _I. InvI = 1.0f / I; Flags &= BodyFlags.FixedRotation; } // TODO: Else what? } }
public void SetFixedRotation(bool fixedr) { if (fixedr) { _angularVelocity = 0.0f; _invI = 0.0f; _flags |= BodyFlags.FixedRotation; } else { if (_I > 0.0f) { // Recover _invI from _I. _invI = 1.0f / _I; _flags &= BodyFlags.FixedRotation; } // TODO: Else what? } }
public Controlable( LifeSpan lifeTime, PhysicsState physicsState, BodyFlags flags, RigidBodyTemplate template, ShipMovementInfo movementInfo, ShipState shipState, ControlableSounds controlableSounds) : base( lifeTime, physicsState, flags, template) { this.shipState = shipState; this.movementInfo = movementInfo; this.controlableSounds = controlableSounds; this.attachedEffectCollection = new EffectCollection(); this.CollisionState.GenerateRayEvents = true; }
// Constructor public PhysBody( Vector2 pos, Vector2 vel, float mass ) { Position = pos; Velocity = vel; Mass = mass; MomentOfInertia = 1f; Force = Vector2.Zero; Angle = 0.0f; AngularVelocity = 0.0f; Torque = 0f; Flags = BodyFlags.None; Elasticity = .5f; Friction = .5f; TouchNormal = Vector2.Zero; Touching = null; Parent = null; CollisionList = new List<PhysBody>( 4 ); }
public Controlable( LifeSpan lifeTime, MassInertia massInfo, PhysicsState physicsState, BodyFlags flags, ICollidableBodyPart[] collidableParts, ShipMovementInfo movementInfo, ShipState shipState, ControlableSounds controlableSounds) : base(lifeTime, massInfo, physicsState, flags, collidableParts) { this.shipState = shipState; this.movementInfo = movementInfo; this.controlableSounds = controlableSounds; this.attachedEffectCollection = new EffectCollection(); this.CollisionState.GenerateRayEvents = true; }
public Controlable( LifeSpan lifeTime, PhysicsState physicsState, BodyFlags flags, RigidBodyTemplate template, ShipMovementInfo movementInfo, ShipState shipState, ControlableSounds controlableSounds, IWeaponsLogic weaponInfo) : this( lifeTime, physicsState, flags, template, movementInfo, shipState, controlableSounds) { this.weaponInfo = weaponInfo; this.CollisionState.GenerateCollisionEvents = true; this.CollisionState.GenerateContactEvents = true; this.controlableType = ControlableType.Weapon; }
public SpawningSolidWeapon( LifeSpan lifeTime, PhysicsState physicsState, BodyFlags flags, RigidBodyTemplate template, ShipMovementInfo movementInfo, ShipState shipState, ControlableSounds controlableSounds, IWeaponsLogic weaponInfo, ISolidWeapon spawn, bool diesOnSpawn) : base( lifeTime, physicsState, flags, template, movementInfo, shipState, controlableSounds, weaponInfo) { this.spawn = spawn; this.diesOnSpawn = diesOnSpawn; }
private bool HasFlag(BodyFlags flag) { return (Flags & flag) == flag; }
public bool SetTransform(Vector2 position, Quaternion rotation) #endif { Box2DXDebug.Assert(_world._lock == false); if (_world._lock == true) { return true; } if (IsFrozen()) { return false; } _xf.rotation = rotation; //_xf.R = rotation; _xf.position = position; _sweep.C0 = _sweep.C = _xf.TransformPoint(_sweep.LocalCenter); #if USE_MATRIX_FOR_ROTATION _sweep.A0 = _sweep.A = rotation.GetAngle(); #else _sweep.A0 = _sweep.A = rotation.eulerAngles.z * Mathf.Deg2Rad; #endif bool freeze = false; for (Fixture f = _fixtureList; f != null; f = f.Next) { bool inRange = f.Synchronize(_world._broadPhase, _xf, _xf); if (inRange == false) { freeze = true; break; } } if (freeze == true) { _flags |= BodyFlags.Frozen; _linearVelocity = Vector2.zero; _angularVelocity = 0.0f; // Failure return false; } // Success _world._broadPhase.Commit(); return true; }
/// <summary> /// Set the position of the body's origin and rotation (radians). /// This breaks any contacts and wakes the other bodies. /// </summary> /// <param name="position">The new world position of the body's origin (not necessarily /// the center of mass).</param> /// <param name="angle">The new world rotation angle of the body in radians.</param> /// <returns>Return false if the movement put a shape outside the world. In this case the /// body is automatically frozen.</returns> public bool SetXForm(Vec2 position, float angle) { Box2DXDebug.Assert(_world._lock == false); if (_world._lock == true) { return true; } if (IsFrozen()) { return false; } _xf.R.Set(angle); _xf.Position = position; _sweep.C0 = _sweep.C = Common.Math.Mul(_xf, _sweep.LocalCenter); _sweep.A0 = _sweep.A = angle; bool freeze = false; for (Fixture f = _fixtureList; f != null; f = f.Next) { bool inRange = f.Synchronize(_world._broadPhase, _xf, _xf); if (inRange == false) { freeze = true; break; } } if (freeze == true) { _flags |= BodyFlags.Frozen; _linearVelocity.SetZero(); _angularVelocity = 0.0f; // Failure return false; } // Success _world._broadPhase.Commit(); return true; }
/// <summary> /// Wake up this body so it will begin simulating. /// </summary> public void WakeUp() { _flags &= ~BodyFlags.Sleep; _sleepTime = 0.0f; }
internal XForm _xf; // the body origin transform #endregion Fields #region Constructors internal Body(BodyDef bd, World world) { _flags = 0; if (bd.isBullet) { _flags |= BodyFlags.Bullet; } if (bd.fixedRotation) { _flags |= BodyFlags.FixedRotation; } if (bd.allowSleep) { _flags |= BodyFlags.AllowSleep; } if (bd.isSleeping) { _flags |= BodyFlags.Sleep; } _world = world; _xf.Position = bd.position; _xf.R.Set(bd.angle); _sweep.localCenter = bd.massData.center; _sweep.t0 = 1.0f; _sweep.a0 = _sweep.a = bd.angle; _sweep.c0 = _sweep.c = MathUtils.Multiply(ref _xf, _sweep.localCenter); _jointList = null; _contactList = null; _prev = null; _next = null; _linearVelocity = bd.linearVelocity; _angularVelocity = bd.angularVelocity; _linearDamping = bd.linearDamping; _angularDamping = bd.angularDamping; _force = new Vector2(0.0f, 0.0f); _torque = 0.0f; _linearVelocity = Vector2.Zero; _angularVelocity = 0.0f; _sleepTime = 0.0f; _invMass = 0.0f; _I = 0.0f; _invI = 0.0f; _mass = bd.massData.mass; if (_mass > 0.0f) { _invMass = 1.0f / _mass; } _I = bd.massData.i; if (_I > 0.0f && (_flags & BodyFlags.FixedRotation) == 0) { _invI = 1.0f / _I; } if (_invMass == 0.0f && _invI == 0.0f) { _type = BodyType.Static; } else { _type = BodyType.Dynamic; } _userData = bd.userData; _fixtureList = null; _fixtureCount = 0; }
/// <summary> /// Set the active state of the body. An inactive body is not /// simulated and cannot be collided with or woken up. /// If you pass a flag of true, all fixtures will be added to the /// broad-phase. /// If you pass a flag of false, all fixtures will be removed from /// the broad-phase and all contacts will be destroyed. /// Fixtures and joints are otherwise unaffected. You may continue /// to create/destroy fixtures and joints on inactive bodies. /// Fixtures on an inactive body are implicitly inactive and will /// not participate in collisions, ray-casts, or queries. /// Joints connected to an inactive body are implicitly inactive. /// An inactive body is still owned by a b2World object and remains /// in the body list. /// </summary> /// <param name="flag"></param> public void SetActive(bool flag) { if (flag == IsActive()) { return; } if (flag) { _flags |= BodyFlags.Active; // Create all proxies. BroadPhase broadPhase = _world._contactManager._broadPhase; for (Fixture f = _fixtureList; f != null; f = f._next) { f.CreateProxy(broadPhase, ref _xf); } // Contacts are created the next time step. } else { _flags &= ~BodyFlags.Active; // Destroy all proxies. BroadPhase broadPhase = _world._contactManager._broadPhase; for (Fixture f = _fixtureList; f != null; f = f._next) { f.DestroyProxy(broadPhase); } // Destroy the attached contacts. ContactEdge ce = _contactList; while (ce != null) { ContactEdge ce0 = ce; ce = ce.Next; _world._contactManager.Destroy(ce0.Contact); } _contactList = null; } }
/// <summary> /// You can disable sleeping on this body. /// </summary> /// <param name="flag"></param> public void AllowSleeping(bool flag) { if (flag) { _flags |= BodyFlags.AutoSleep; } else { _flags &= ~BodyFlags.AutoSleep; SetAwake(true); } }
/// <summary> /// You can disable sleeping on this body. If you disable sleeping, the /// body will be woken. /// </summary> /// <param name="flag"></param> void SetSleepingAllowed(bool flag) { if (flag) { _flags |= BodyFlags.AutoSleep; } else { _flags &= ~BodyFlags.AutoSleep; SetAwake(true); } }
internal Body(BodyDef bd, World world) { Debug.Assert(bd.position.IsValid()); Debug.Assert(bd.linearVelocity.IsValid()); Debug.Assert(MathUtils.IsValid(bd.angle)); Debug.Assert(MathUtils.IsValid(bd.angularVelocity)); Debug.Assert(MathUtils.IsValid(bd.inertiaScale) && bd.inertiaScale >= 0.0f); Debug.Assert(MathUtils.IsValid(bd.angularDamping) && bd.angularDamping >= 0.0f); Debug.Assert(MathUtils.IsValid(bd.linearDamping) && bd.linearDamping >= 0.0f); if (bd.bullet) { _flags |= BodyFlags.Bullet; } if (bd.fixedRotation) { _flags |= BodyFlags.FixedRotation; } if (bd.allowSleep) { _flags |= BodyFlags.AutoSleep; } if (bd.awake) { _flags |= BodyFlags.Awake; } if (bd.active) { _flags |= BodyFlags.Active; } _world = world; _xf.Position = bd.position; _xf.R.Set(bd.angle); _sweep.a0 = _sweep.a = bd.angle; _sweep.c0 = _sweep.c = MathUtils.Multiply(ref _xf, _sweep.localCenter); _linearVelocity = bd.linearVelocity; _angularVelocity = bd.angularVelocity; _linearDamping = bd.linearDamping; _angularDamping = bd.angularDamping; _type = bd.type; if (_type == BodyType.Dynamic) { _mass = 1.0f; _invMass = 1.0f; } _userData = bd.userData; }
private void RemoveFlags(BodyFlags flag) { Flags &= ~flag; }
/** * Set the sleep state of the body. A sleeping body has very low CPU cost. * * @param flag set to true to put body to sleep, false to wake it. * @param flag */ public void setAwake(bool flag) { if (flag) { if ((m_flags & BodyFlags.Awake) == 0) { m_flags |= BodyFlags.Awake; m_sleepTime = 0.0f; } } else { m_flags &= ~BodyFlags.Awake; m_sleepTime = 0.0f; m_linearVelocity.setZero(); m_angularVelocity = 0.0f; m_force.setZero(); m_torque = 0.0f; } }
/// <summary> /// Set this body to have fixed rotation. This causes the mass /// to be reset. /// </summary> /// <param name="flag"></param> public void SetFixedRotation(bool flag) { if (flag) { _flags |= BodyFlags.FixedRotation; } else { _flags &= ~BodyFlags.FixedRotation; } ResetMassData(); }
internal bool SynchronizeFixtures() { XForm xf1 = new XForm(); xf1.R.Set(_sweep.A0); xf1.Position = _sweep.C0 - Common.Math.Mul(xf1.R, _sweep.LocalCenter); bool inRange = true; for (Fixture f = _fixtureList; f != null; f = f.Next) { inRange = f.Synchronize(_world._broadPhase, xf1, _xf); if (inRange == false) { break; } } if (inRange == false) { _flags |= BodyFlags.Frozen; _linearVelocity.SetZero(); _angularVelocity = 0.0f; // Failure return false; } // Success return true; }
/// Put this body to sleep so it will stop simulating. /// This also sets the velocity to zero. public void PutToSleep() { _flags |= BodyFlags.Sleep; _sleepTime = 0.0f; _linearVelocity = Vector2.Zero; _angularVelocity = 0.0f; _force = Vector2.Zero; _torque = 0.0f; }
internal bool SynchronizeFixtures() { Transform xf1; xf1.rotation = Box2DX.Common.Math.AngleToRotation(_sweep.A0); //xf1.R = new Mat22(_sweep.A0); xf1.position = _sweep.C0 - xf1.TransformDirection(_sweep.LocalCenter); bool inRange = true; for (Fixture f = _fixtureList; f != null; f = f.Next) { inRange = f.Synchronize(_world._broadPhase, xf1, _xf); if (inRange == false) { break; } } if (inRange == false) { _flags |= BodyFlags.Frozen; _linearVelocity = Vector2.zero; _angularVelocity = 0.0f; // Failure return false; } // Success return true; }
public static bool HasFlags( this BodyFlags flags, BodyFlags value ) { return ( ( flags & value ) == value ); }
/** * Set the active state of the body. An inactive body is not simulated and cannot be collided with * or woken up. If you pass a flag of true, all fixtures will be added to the broad-phase. If you * pass a flag of false, all fixtures will be removed from the broad-phase and all contacts will * be destroyed. Fixtures and joints are otherwise unaffected. You may continue to create/destroy * fixtures and joints on inactive bodies. Fixtures on an inactive body are implicitly inactive * and will not participate in collisions, ray-casts, or queries. Joints connected to an inactive * body are implicitly inactive. An inactive body is still owned by a World object and remains in * the body list. * * @param flag */ public void setActive(bool flag) { Debug.Assert(m_world.isLocked() == false); if (flag == isActive()) { return; } if (flag) { m_flags |= BodyFlags.Active; // Create all proxies. BroadPhase broadPhase = m_world.m_contactManager.m_broadPhase; for (Fixture f = m_fixtureList; f != null; f = f.m_next) { f.createProxies(broadPhase, m_xf); } // Contacts are created the next time step. } else { m_flags &= ~BodyFlags.Active; // Destroy all proxies. BroadPhase broadPhase = m_world.m_contactManager.m_broadPhase; for (Fixture f = m_fixtureList; f != null; f = f.m_next) { f.destroyProxies(broadPhase); } // Destroy the attached contacts. ContactEdge ce = m_contactList; while (ce != null) { ContactEdge ce0 = ce; ce = ce.next; m_world.m_contactManager.destroy(ce0.contact); } m_contactList = null; } }
internal Body(BodyDef bd, World world) { Box2DXDebug.Assert(world._lock == false); _flags = 0; if (bd.IsBullet) { _flags |= BodyFlags.Bullet; } if (bd.FixedRotation) { _flags |= BodyFlags.FixedRotation; } if (bd.AllowSleep) { _flags |= BodyFlags.AllowSleep; } if (bd.IsSleeping) { _flags |= BodyFlags.Sleep; } _world = world; _xf.Position = bd.Position; _xf.R.Set(bd.Angle); _sweep.LocalCenter = bd.MassData.Center; _sweep.T0 = 1.0f; _sweep.A0 = _sweep.A = bd.Angle; _sweep.C0 = _sweep.C = Common.Math.Mul(_xf, _sweep.LocalCenter); //_jointList = null; //_contactList = null; //_controllerList = null; //_prev = null; //_next = null; _linearVelocity = bd.LinearVelocity; _angularVelocity = bd.AngularVelocity; _linearDamping = bd.LinearDamping; _angularDamping = bd.AngularDamping; //_force.Set(0.0f, 0.0f); //_torque = 0.0f; //_linearVelocity.SetZero(); //_angularVelocity = 0.0f; //_sleepTime = 0.0f; //_invMass = 0.0f; //_I = 0.0f; //_invI = 0.0f; _mass = bd.MassData.Mass; if (_mass > 0.0f) { _invMass = 1.0f / _mass; } _I = bd.MassData.I; if (_I > 0.0f && (_flags & BodyFlags.FixedRotation) == 0) { _invI = 1.0f / _I; } if (_invMass == 0.0f && _invI == 0.0f) { _type = BodyType.Static; } else { _type = BodyType.Dynamic; } _userData = bd.UserData; //_fixtureList = null; //_fixtureCount = 0; }
public Body(BodyDef bd, World world) { Debug.Assert(bd.position.isValid()); Debug.Assert(bd.linearVelocity.isValid()); Debug.Assert(bd.gravityScale >= 0.0f); Debug.Assert(bd.angularDamping >= 0.0f); Debug.Assert(bd.linearDamping >= 0.0f); m_flags = 0; if (bd.bullet) { m_flags |= BodyFlags.Bullet; } if (bd.fixedRotation) { m_flags |= BodyFlags.FixedRotation; } if (bd.allowSleep) { m_flags |= BodyFlags.AutoSleep; } if (bd.awake) { m_flags |= BodyFlags.Awake; } if (bd.active) { m_flags |= BodyFlags.Active; } m_world = world; m_xf.p.set(bd.position); m_xf.q.set(bd.angle); m_sweep.localCenter.setZero(); m_sweep.c0.set(m_xf.p); m_sweep.c.set(m_xf.p); m_sweep.a0 = bd.angle; m_sweep.a = bd.angle; m_sweep.alpha0 = 0.0f; m_jointList = null; m_contactList = null; m_prev = null; m_next = null; m_linearVelocity.set(bd.linearVelocity); m_angularVelocity = bd.angularVelocity; m_linearDamping = bd.linearDamping; m_angularDamping = bd.angularDamping; m_gravityScale = bd.gravityScale; m_force.setZero(); m_torque = 0.0f; m_sleepTime = 0.0f; m_type = bd.type; if (m_type == BodyType.DYNAMIC) { m_mass = 1f; m_invMass = 1f; } else { m_mass = 0f; m_invMass = 0f; } m_I = 0.0f; m_invI = 0.0f; m_userData = bd.userData; m_fixtureList = null; m_fixtureCount = 0; }
/** * You can disable sleeping on this body. If you disable sleeping, the body will be woken. * * @param flag */ public void setSleepingAllowed(bool flag) { if (flag) { m_flags |= BodyFlags.AutoSleep; } else { m_flags &= ~BodyFlags.AutoSleep; setAwake(true); } }
internal bool SynchronizeShapes() { XForm xf1 = new XForm(); xf1.R.Set(_sweep.A0); xf1.Position = _sweep.C0 - Common.Math.Mul(xf1.R, _sweep.LocalCenter); bool inRange = true; for (Shape s = _shapeList; s != null; s = s._next) { inRange = s.Synchronize(_world._broadPhase, xf1, _xf); if (inRange == false) { break; } } if (inRange == false) { _flags |= BodyFlags.Frozen; _linearVelocity.SetZero(); _angularVelocity = 0.0f; for (Shape s = _shapeList; s != null; s = s._next) { s.DestroyProxy(_world._broadPhase); } // Failure return false; } // Success return true; }
/// <summary> /// Set the sleep state of the body. A sleeping body has very /// low CPU cost. /// </summary> /// <param name="flag">set to true to put body to sleep, false to wake it.</param> public void SetAwake(bool flag) { if (flag) { if ((_flags & BodyFlags.Awake) == 0) { _flags |= BodyFlags.Awake; _sleepTime = 0.0f; } } else { _flags &= ~BodyFlags.Awake; _sleepTime = 0.0f; _linearVelocity = Vector2.Zero; _angularVelocity = 0.0f; _force = Vector2.Zero; _torque = 0.0f; } }
private void AppendFlags(BodyFlags flag) { Flags |= flag; }