示例#1
0
    /// <summary>
    /// Initializes a new instance of the <see cref="Simulation"/> class.
    /// </summary>
    public Simulation()
    {
      Settings = new SimulationSettings();

      var collisionDetection = new CollisionDetection
      {
        CollisionFilter = new CollisionFilter(),
        FullContactSetPerFrame = true
      };
      CollisionDomain = new CollisionDomain(collisionDetection);

      ConstraintSolver = new SequentialImpulseBasedSolver(this);

      Constraints = new ConstraintCollection();
      Constraints.CollectionChanged += OnConstraintsChanged;

      ForceEffects = new ForceEffectCollection();
      ForceEffects.CollectionChanged += OnForceEffectsChanged;

      RigidBodies = new RigidBodyCollection();
      RigidBodies.CollectionChanged += OnRigidBodiesChanged;

      ContactConstraintsInternal = new List<ContactConstraint>();

      IslandManager = new SimulationIslandManager(this);

      // Define the "World" as a rigid body.
      //   - World is an imaginary body that is used to define the space of the simulation.
      //   - The user can use World in constraints e.g. to anchor objects in the world.
      //   - No contacts are computed for World.
      World = new RigidBody(new BoxShape(20000, 20000, 20000))
      {
        CollisionResponseEnabled = false,
        CollisionObject = { Type = CollisionObjectType.Trigger },
        MotionType = MotionType.Static,
        Name = "World",
        Simulation = this,
      };

      // Remove "World" from the collision domain. 
      CollisionDomain.CollisionObjects.Remove(World.CollisionObject);


      Diagnostics = new SimulationDiagnostics();


      // Store delegate methods to avoid garbage when multithreading.
      _updateVelocityMethod = i =>
      {
        var body = RigidBodies[i];
        body.UpdateVelocity(_fixedTimeStep);
      };
      _solveIslandMethod = SolveIsland;
      _updatePoseMethod = i =>
      {
        var body = RigidBodies[i];
        body.UpdatePose(_fixedTimeStep);
      };
      _computeTimeOfImpactMethod = ComputeTimeOfImpact_Multithreaded;
      _moveToTimeOfImpactMethod = MoveToTimeOfImpact;
    }
示例#2
0
        //--------------------------------------------------------------
        /// <summary>
        /// Initializes a new instance of the <see cref="Simulation"/> class.
        /// </summary>
        public Simulation()
        {
            Settings = new SimulationSettings();

              var collisionDetection = new CollisionDetection
              {
            CollisionFilter = new CollisionFilter(),
            FullContactSetPerFrame = true
              };
              CollisionDomain = new CollisionDomain(collisionDetection);

              ConstraintSolver = new SequentialImpulseBasedSolver(this);

              Constraints = new ConstraintCollection();
              Constraints.CollectionChanged += OnConstraintsChanged;

              ForceEffects = new ForceEffectCollection();
              ForceEffects.CollectionChanged += OnForceEffectsChanged;

              RigidBodies = new RigidBodyCollection();
              RigidBodies.CollectionChanged += OnRigidBodiesChanged;

              ContactConstraintsInternal = new List<ContactConstraint>();

              IslandManager = new SimulationIslandManager(this);

              // Define the "World" as a rigid body.
              //   - World is an imaginary body that is used to define the space of the simulation.
              //   - The user can use World in constraints e.g. to anchor objects in the world.
              //   - No contacts are computed for World.
              World = new RigidBody(new BoxShape(20000, 20000, 20000))
              {
            CollisionResponseEnabled = false,
            CollisionObject = { Type = CollisionObjectType.Trigger },
            MotionType = MotionType.Static,
            Name = "World",
            Simulation = this,
              };

              // Remove "World" from the collision domain.
              CollisionDomain.CollisionObjects.Remove(World.CollisionObject);

            #if STOPWATCH
              Diagnostics = new SimulationDiagnostics();
            #endif

              // Store delegate methods to avoid garbage when multithreading.
              _updateVelocityMethod = i =>
              {
            var body = RigidBodies[i];
            body.UpdateVelocity(_fixedTimeStep);
              };
              _solveIslandMethod = SolveIsland;
              _updatePoseMethod = i =>
              {
            var body = RigidBodies[i];
            body.UpdatePose(_fixedTimeStep);
              };
              _computeTimeOfImpactMethod = ComputeTimeOfImpact_Multithreaded;
              _moveToTimeOfImpactMethod = MoveToTimeOfImpact;
        }