Exemplo n.º 1
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 collision)
        {
            if (collision == null)
            {
                throw new ArgumentNullException("The CollisionSystem can't be null.", "collision");
            }

            arbiterCallback   = new Action <object>(ArbiterCallback);
            integrateCallback = new Action <object>(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 = collision;

            collisionDetectionHandler = new CollisionDetectedHandler(CollisionDetected);

            this.CollisionSystem.CollisionDetected += collisionDetectionHandler;

            this.arbiterMap = new ArbiterMap();

            AllowDeactivation = true;
        }
Exemplo n.º 2
0
        public virtual void DoSelfCollision(CollisionDetectedHandler collision)
        {
            bool flag = !this.selfCollision;

            if (!flag)
            {
                for (int i = 0; i < this.points.Count; i++)
                {
                    this.queryList.Clear();
                    this.dynamicTree.Query(this.queryList, ref this.points[i].boundingBox);
                    for (int j = 0; j < this.queryList.Count; j++)
                    {
                        SoftBody.Triangle userData = this.dynamicTree.GetUserData(this.queryList[j]);
                        bool flag2 = userData.VertexBody1 != this.points[i] && userData.VertexBody2 != this.points[i] && userData.VertexBody3 != this.points[i];
                        if (flag2)
                        {
                            TSVector tSVector;
                            TSVector normal;
                            FP       penetration;
                            bool     flag3 = XenoCollide.Detect(this.points[i].Shape, userData, ref this.points[i].orientation, ref TSMatrix.InternalIdentity, ref this.points[i].position, ref TSVector.InternalZero, out tSVector, out normal, out penetration);
                            if (flag3)
                            {
                                int index = CollisionSystem.FindNearestTrianglePoint(this, this.queryList[j], ref tSVector);
                                collision(this.points[i], this.points[index], tSVector, tSVector, normal, penetration);
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 3
0
        public virtual void DoSelfCollision(CollisionDetectedHandler collision)
        {
            if (!selfCollision)
            {
                return;
            }

            JVector point, normal;
            float   penetration;

            for (int i = 0; i < points.Count; i++)
            {
                queryList.Clear();
                this.dynamicTree.Query(queryList, ref points[i].boundingBox);

                for (int e = 0; e < queryList.Count; e++)
                {
                    Triangle t = this.dynamicTree.GetUserData(queryList[e]);

                    if (!(t.VertexBody1 == points[i] || t.VertexBody2 == points[i] || t.VertexBody3 == points[i]))
                    {
                        if (XenoCollide.Detect(points[i].Shape, t, ref points[i].orientation,
                                               ref JMatrix.InternalIdentity, ref points[i].position, ref JVector.InternalZero,
                                               out point, out normal, out penetration))
                        {
                            int nearest = CollisionSystem.FindNearestTrianglePoint(this, queryList[e], ref point);

                            collision(points[i], points[nearest], point, point, normal, penetration);
                        }
                    }
                }
            }
        }
Exemplo 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;
        }
Exemplo 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;
        }
Exemplo 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;
        }
Exemplo n.º 7
0
        public World(CollisionSystem collision)
        {
            bool flag = collision == null;

            if (flag)
            {
                throw new ArgumentNullException("The CollisionSystem can't be null.", "collision");
            }
            RigidBody.instanceCount                 = 0;
            Constraint.instanceCount                = 0;
            this.arbiterCallback                    = new Action <object>(this.ArbiterCallback);
            this.integrateCallback                  = new Action <object>(this.IntegrateCallback);
            this.RigidBodies                        = new ReadOnlyHashset <RigidBody>(this.rigidBodies);
            this.Constraints                        = new ReadOnlyHashset <Constraint>(this.constraints);
            this.SoftBodies                         = new ReadOnlyHashset <SoftBody>(this.softbodies);
            this.CollisionSystem                    = collision;
            this.collisionDetectionHandler          = new CollisionDetectedHandler(this.CollisionDetected);
            this.CollisionSystem.CollisionDetected += this.collisionDetectionHandler;
            this.arbiterMap                         = new ArbiterMap();
            this.arbiterTriggerMap                  = new ArbiterMap();
            this.AllowDeactivation                  = false;
        }
Exemplo 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;
        }
Exemplo n.º 9
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 collision)
        {
            if (collision == null)
                throw new ArgumentNullException("The CollisionSystem can't be null.", "collision");

            arbiterCallback = new Action<object>(ArbiterCallback);
            integrateCallback = new Action<object>(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 = collision;

            collisionDetectionHandler = new CollisionDetectedHandler(CollisionDetected);

            this.CollisionSystem.CollisionDetected += collisionDetectionHandler;

            this.arbiterMap = new ArbiterMap();

            AllowDeactivation = true;
        }
Exemplo n.º 10
0
        public virtual void DoSelfCollision(CollisionDetectedHandler collision)
        {
            if (!selfCollision) return;

            JVector point, normal;
            float penetration;

            for (int i = 0; i < points.Count; i++)
            {
                queryList.Clear();
                this.dynamicTree.Query(queryList, ref points[i].boundingBox);

                for (int e = 0; e < queryList.Count; e++)
                {
                    Triangle t = this.dynamicTree.GetUserData(queryList[e]);

                    if (!(t.VertexBody1 == points[i] || t.VertexBody2 == points[i] || t.VertexBody3 == points[i]))
                    {
                        if (XenoCollide.Detect(points[i].Shape, t, ref points[i].orientation,
                            ref JMatrix.InternalIdentity, ref points[i].position, ref JVector.InternalZero,
                            out point, out normal, out penetration))
                        {
                            int nearest = CollisionSystem.FindNearestTrianglePoint(this, queryList[e], ref point);

                            collision(points[i], points[nearest], point, point, normal, penetration);
                     
                        }
                    }
                }
            }
        }