Exemplo n.º 1
0
        private ICollide CheckCollision()
        {
            ICollide retVal = null;

            // If I'm not colliding with myself or an object of my same type, return that object
            if (collidables.Count > 1)
            {
                foreach (var item in collidables)
                {
                    if (this.colliderRectangle.IntersectsWith(item.Value) && item.Key.GetType() != this.parentObject.GetType())
                    {
                        return(item.Key);
                    }
                }
                //try
                //{
                //  //  retVal = collidables.Where(p => p.Value.IntersectsWith(this.colliderRectangle) && p.Key.GetType() != this.parentObject.GetType()).First().Key;
                //}
                //catch (InvalidOperationException)
                //{
                //    retVal = null;
                //}
            }
            return(retVal);
        }
Exemplo n.º 2
0
        protected override void Collided(ICollide otherObject)
        {
            if (otherObject is Ship ship)
            {
                var fleet = ship.Fleet;

                if (CarriedBy == null && fleet != null && !(fleet.Owner is Robot))
                {
                    if (fleet.Owner.Color == Team.ColorName)
                    {
                        ReturnToBase();
                    }
                    else
                    {
                        CarriedBy = fleet;

                        if (CarriedBy != null)
                        {
                            CarriedBy.Burden = World.Hook.CTFCarryBurden;
                        }
                    }
                }
            }

            base.Collided(otherObject);
        }
Exemplo n.º 3
0
    public void Move(Vector3 movement, float moveDelta = 1f)
    {
        movement *= moveDelta;

        Transform current     = GetTransform();
        Transform destination = current;

        destination.Translated(movement);

        Vector3            delta     = destination.origin - current.origin;
        KinematicCollision collision = MoveAndCollide(delta);

        if (collision != null && collision.Collider != null)
        {
            ICollide collider = collision.Collider as ICollide;

            if (collider != null)
            {
                Node colliderNode = collider as Node;
                collider.OnCollide(this as object);
            }
        }

        if (!grounded && collision != null && collision.Position.y < GetTranslation().y)
        {
            if (gravityVelocity < 0)
            {
                grounded        = true;
                gravityVelocity = 0f;
            }
        }
    }
Exemplo n.º 4
0
 public static void CollideTV(DbvtNode root, ref DbvtAabbMm volume, ICollide collideable)
 {
     CollideTVCount++;
     Debug.Assert(CollideTVCount < 2);
     CollideTVStack.Clear();
     if (root != null)
     {
         CollideTVStack.Push(root);
         do
         {
             DbvtNode n = CollideTVStack.Pop();
             if (DbvtAabbMm.Intersect(ref n.volume, ref volume))
             {
                 if (n.IsInternal())
                 {
                     CollideTVStack.Push(n._children[0]);
                     CollideTVStack.Push(n._children[1]);
                 }
                 else
                 {
                     collideable.Process(n);
                 }
             }
         } while (CollideTVStack.Count > 0);
     }
     CollideTVCount--;
 }
Exemplo n.º 5
0
 public void Collide(float s, PhysicsGroupType groupType, ICollide other)
 {
     if (groupType == PhysicsGroupType.Physical)
     {
         for (int i = bullets.Count - 1; i >= 0; i--)
         {
             Circle          bullet          = bullets[i];
             CollisionResult bulletCollision = other.Collide(s, groupType, bullet, bulletIdentity);
             if (bulletCollision)
             {
                 bullets.RemoveAt(i);
                 //bullet.Position = bulletCollision.PositionB;
                 //bullet.Velocity = bulletCollision.VelocityB;
             }
         }
         CollisionResult result = other.Collide(s, groupType, collision, null);
         if (result)
         {
             if (collisionResult)
             {
                 collisionResult.PositionA = collision.Position;
                 collisionResult.VelocityA = Vector2.Zero;
             }
             else
             {
                 collisionResult = result;
             }
             takeDamage(result.Identity);
         }
     }
 }
Exemplo n.º 6
0
 /// <summary>
 /// Controleert of we de rechterkant van de static sprite aanraken
 /// </summary>
 /// <param name="staticObject">static collision object</param>
 /// <param name="movingCollision">bewegend collision object</param>
 /// <returns>returned true als het bewegend object de rechterkant van het static object aanraakt</returns>
 private bool IsTouchingRight(ICollide staticObject, IMovingCollide movingCollision)
 {
     return(movingCollision.CollisionRectangle.Left + movingCollision.Velocity.X < staticObject.CollisionRectangle.Right &&
            movingCollision.CollisionRectangle.Right > staticObject.CollisionRectangle.Right &&
            movingCollision.CollisionRectangle.Bottom > staticObject.CollisionRectangle.Top &&
            movingCollision.CollisionRectangle.Top < staticObject.CollisionRectangle.Bottom);
 }
Exemplo n.º 7
0
 /// <summary>
 /// Controleert of we de onderkant raken van de static sprite
 /// </summary>
 /// <param name="staticObject">static collision object</param>
 /// <param name="movingCollision">bewegend collision object</param>
 /// <returns>returned true als het bewegend object de onderkant van het static object aanraakt</returns>
 private bool IsTouchingBottom(ICollide staticObject, IMovingCollide movingCollision)
 {
     return(movingCollision.CollisionRectangle.Top + movingCollision.Velocity.Y < staticObject.CollisionRectangle.Bottom &&
            movingCollision.CollisionRectangle.Bottom > staticObject.CollisionRectangle.Bottom &&
            movingCollision.CollisionRectangle.Right > staticObject.CollisionRectangle.Left &&
            movingCollision.CollisionRectangle.Left < staticObject.CollisionRectangle.Right);
 }
Exemplo n.º 8
0
 public bool CheckEnemyPlayerCollision(ICollide PlayerCollisionRectangle, ICollide EnemyCollisionRectangle)
 {
     if (PlayerCollisionRectangle.GetCollisionRectangle().Intersects(EnemyCollisionRectangle.GetCollisionRectangle()))
     {
         return(true);
     }
     return(false);
 }
Exemplo n.º 9
0
        //Pixel Collision

        public void checkPixelCollision(ICollide object1, ICollide object2)
        {
            if (getColorData(object1.getTexture(), object1.getSourceRect(), object2.getTexture(), object2.getSourceRect(), object1.getCollisionRect(), object2.getCollisionRect()))
            {
                object1.setOldPos();
                object2.setOldPos();
            }
        }
Exemplo n.º 10
0
 public bool CheckCollider(ICollide source, ICollide target)
 {
     if (source.CollisionRectangle.Intersects(target.CollisionRectangle))
     {
         return(true);
     }
     return(false);
 }
Exemplo n.º 11
0
 // I need only the location now, but i'll leave it for simplicity
 public Collider(ICollide obj, Rectangle colliderRectangle)
 {
     // Set the start location of the collider
     if (obj == null)
         throw new NullReferenceException("Parent object is null");
     this.parentObject = obj;
     this.colliderRectangle = colliderRectangle;
     collidables.Add(obj, colliderRectangle);
 }
Exemplo n.º 12
0
 public static void EnumNodes(DbvtNode root, ICollide collideable)
 {
     collideable.Process(root);
     if (root.IsInternal())
     {
         EnumNodes(root._children[0], collideable);
         EnumNodes(root._children[1], collideable);
     }
 }
Exemplo n.º 13
0
 public static void collideTT(Node root0, Node root1, Dispatcher dispatcher, ICollide policy)
 {
     if (root0 != null && root1 != null)
     {
         List <sStkNN> stack = new List <sStkNN>(DOUBLE_STACKSIZE);
         stack.Add(new sStkNN(root0, root1));
         do
         {
             sStkNN p = stack[stack.Count - 1];
             stack.RemoveAt(stack.Count - 1);
             if (p.a == p.b)
             {
                 if (p.a.isinternal())
                 {
                     stack.Add(new sStkNN(p.a.childs[0], p.a.childs[0]));
                     stack.Add(new sStkNN(p.a.childs[1], p.a.childs[1]));
                     stack.Add(new sStkNN(p.a.childs[0], p.a.childs[1]));
                 }
             }
             else if (DbvtAabbMm.Intersect(p.a.volume, p.b.volume))
             {
                 if (p.a.isinternal())
                 {
                     if (p.b.isinternal())
                     {
                         stack.Add(new sStkNN(p.a.childs[0], p.b.childs[0]));
                         stack.Add(new sStkNN(p.a.childs[1], p.b.childs[0]));
                         stack.Add(new sStkNN(p.a.childs[0], p.b.childs[1]));
                         stack.Add(new sStkNN(p.a.childs[1], p.b.childs[1]));
                     }
                     else
                     {
                         stack.Add(new sStkNN(p.a.childs[0], p.b));
                         stack.Add(new sStkNN(p.a.childs[1], p.b));
                     }
                 }
                 else
                 {
                     if (p.b.isinternal())
                     {
                         stack.Add(new sStkNN(p.a, p.b.childs[0]));
                         stack.Add(new sStkNN(p.a, p.b.childs[1]));
                     }
                     else
                     {
                         if (!dispatcher.needsCollision(p.a.data.collisionFilterGroup, p.a.data.collisionFilterMask, p.b.data.collisionFilterGroup, p.b.data.collisionFilterMask))
                         {
                             continue;
                         }
                         policy.Process(p.a, p.b);
                     }
                 }
             }
         }while (stack.Count > 0);
     }
 }
Exemplo n.º 14
0
 // I need only the location now, but i'll leave it for simplicity
 public Collider(ICollide obj, Rectangle colliderRectangle)
 {
     // Set the start location of the collider
     if (obj == null)
     {
         throw new NullReferenceException("Parent object is null");
     }
     this.parentObject      = obj;
     this.colliderRectangle = colliderRectangle;
     collidables.Add(obj, colliderRectangle);
 }
Exemplo n.º 15
0
 public int CheckEnemyPlayerProjectileHit(ICollide EnemyCollisionRectangle)
 {
     for (int i = 0; i < projectileCollisionObjecten.Count; i++)
     {
         if (EnemyCollisionRectangle.GetCollisionRectangle().Intersects(projectileCollisionObjecten[i].GetCollisionRectangle()))
         {
             return(i);
         }
     }
     return(-1);
 }
Exemplo n.º 16
0
 private void CollideBulletsSimple(float s, ICollide other, PhysicsGroupType groupType, List <Circle> list, CollisionIdentity identity, List <Circle> removalList)
 {
     for (int i = list.Count - 1; i >= 0; i--)
     {
         Circle          c = list[i];
         CollisionResult collisionResult = other.Collide(s, groupType, c, identity);
         if (collisionResult)
         {
             removalList.Add(c);
         }
     }
 }
Exemplo n.º 17
0
        protected override void Collided(ICollide otherObject)
        {
            var ship  = otherObject as Ship;
            var fleet = ship?.Fleet;

            if (fleet != null && fleet != ExcludedFleet)
            {
                EquipFleet(fleet);

                Randomize();
            }

            base.Collided(otherObject);
        }
Exemplo n.º 18
0
        /// <summary>
        /// Constructs a real functioning collider
        /// </summary>
        /// <param name="obj">Object holding the collider</param>
        /// <param name="colliderRectangle">Dimensions of the collider</param>
        public Collider(ICollide obj, Rectangle colliderRectangle)
        {
            // Set the start location of the collider
            if (obj == null)
            {
                throw new NullReferenceException("Parent object is null");
            }

            this.parentObject      = obj;
            this.colliderRectangle = colliderRectangle;

            // Set the collider to active and check collision
            this.Active = true;
        }
Exemplo n.º 19
0
        public void RayTestInternal(DbvtNode root,
                                    ref IndexedVector3 rayFrom,
                                    ref IndexedVector3 rayTo,
                                    ref IndexedVector3 rayDirectionInverse,
                                    bool[] signs,
                                    float lambda_max,
                                    ref IndexedVector3 aabbMin,
                                    ref IndexedVector3 aabbMax,
                                    ICollide policy)
        {
            using (DbvtStackDataBlock stackDataBlock = BulletGlobals.DbvtStackDataBlockPool.Get())
            {
                //    (void) rayTo;
                //DBVT_CHECKTYPE
                if (root != null)
                {
                    IndexedVector3 resultNormal = new IndexedVector3(0, 1, 0);

                    int depth    = 1;
                    int treshold = DOUBLE_STACKSIZE - 2;
                    stackDataBlock.stack[0] = root;
                    do
                    {
                        DbvtNode node = stackDataBlock.stack[--depth];
                        stackDataBlock.bounds[0] = node.volume.Mins() - aabbMax;
                        stackDataBlock.bounds[1] = node.volume.Maxs() - aabbMin;
                        float tmin = 1.0f, lambda_min = 0.0f;
                        bool  result1 = AabbUtil2.RayAabb2(ref rayFrom, ref rayDirectionInverse, signs, stackDataBlock.bounds, out tmin, lambda_min, lambda_max);
                        if (result1)
                        {
                            if (node.IsInternal())
                            {
                                if (depth > treshold)
                                {
                                    stackDataBlock.stack.Resize(stackDataBlock.stack.Count * 2);
                                    treshold = stackDataBlock.stack.Count - 2;
                                }
                                stackDataBlock.stack[depth++] = node._children[0];
                                stackDataBlock.stack[depth++] = node._children[1];
                            }
                            else
                            {
                                policy.Process(node);
                            }
                        }
                    } while (depth != 0);
                }
            }
        }
Exemplo n.º 20
0
        //Map Collision Prüfen

        public void checkMapCollision(ICollide collObject)
        {
            for (int i = 0; i < map._layerCount; i++)
            {
                foreach (Tile tile in map.layerList[i])
                {
                    if (tile._passable == false)
                    {
                        if (tile.destiRect.Intersects(collObject.getCollisionRect()))
                        {
                            collObject.setOldPos();
                        }
                    }
                }
            }
        }
Exemplo n.º 21
0
 /// <summary>
 /// Maken van een lijst van beweegbare objecten uit de collisionlijst
 /// </summary>
 private void MakeLists()
 {
     charactersList.Add(hero);
     foreach (ICollide temp in CollisionItemList.ToList())
     {
         if (temp is Enemy)
         {
             charactersList.Add((IMoveableObject)temp);
         }
         else if (temp is INextLevelTile)
         {
             nextlevelObject = temp;
             CollisionItemList.Remove(temp);
         }
     }
 }
Exemplo n.º 22
0
        public void CheckCollisions(ICollide myCollisionRectangle)
        {
            BottomCollisions = new List <ICollide>();
            RightCollisions  = new List <ICollide>();
            LeftCollisions   = new List <ICollide>();
            TopCollisions    = new List <ICollide>();

            for (int i = 0; i < mogelijkeCollisionObjecten.Count; i++)
            {
                //Check bottom
                if (myCollisionRectangle.GetCollisionRectangle().Bottom >= mogelijkeCollisionObjecten[i].GetCollisionRectangle().Top - 5 &&
                    myCollisionRectangle.GetCollisionRectangle().Bottom <= mogelijkeCollisionObjecten[i].GetCollisionRectangle().Top + (mogelijkeCollisionObjecten[i].GetCollisionRectangle().Height / 2) &&
                    myCollisionRectangle.GetCollisionRectangle().Right >= mogelijkeCollisionObjecten[i].GetCollisionRectangle().Left + 5 &&
                    myCollisionRectangle.GetCollisionRectangle().Left <= mogelijkeCollisionObjecten[i].GetCollisionRectangle().Right - 5)
                {
                    BottomCollisions.Add(mogelijkeCollisionObjecten[i]);
                    BottomCollisionHeight = mogelijkeCollisionObjecten[i].GetCollisionRectangle().Top;
                }

                //Check right
                if (myCollisionRectangle.GetCollisionRectangle().Right >= mogelijkeCollisionObjecten[i].GetCollisionRectangle().Left - 2 &&
                    myCollisionRectangle.GetCollisionRectangle().Right <= mogelijkeCollisionObjecten[i].GetCollisionRectangle().Left + 2 &&
                    myCollisionRectangle.GetCollisionRectangle().Bottom >= mogelijkeCollisionObjecten[i].GetCollisionRectangle().Top + 8 &&
                    myCollisionRectangle.GetCollisionRectangle().Top <= mogelijkeCollisionObjecten[i].GetCollisionRectangle().Bottom - 8)
                {
                    RightCollisions.Add(mogelijkeCollisionObjecten[i]);
                }

                // Check left
                if (myCollisionRectangle.GetCollisionRectangle().Left >= mogelijkeCollisionObjecten[i].GetCollisionRectangle().Right - 2 &&
                    myCollisionRectangle.GetCollisionRectangle().Left <= mogelijkeCollisionObjecten[i].GetCollisionRectangle().Right + 2 &&
                    myCollisionRectangle.GetCollisionRectangle().Bottom >= mogelijkeCollisionObjecten[i].GetCollisionRectangle().Top + 8 &&
                    myCollisionRectangle.GetCollisionRectangle().Top <= mogelijkeCollisionObjecten[i].GetCollisionRectangle().Bottom - 8)
                {
                    LeftCollisions.Add(mogelijkeCollisionObjecten[i]);
                }

                //Check top
                if (myCollisionRectangle.GetCollisionRectangle().Top <= mogelijkeCollisionObjecten[i].GetCollisionRectangle().Bottom + 5 &&
                    myCollisionRectangle.GetCollisionRectangle().Top >= mogelijkeCollisionObjecten[i].GetCollisionRectangle().Bottom - (mogelijkeCollisionObjecten[i].GetCollisionRectangle().Height / 2) &&
                    myCollisionRectangle.GetCollisionRectangle().Right >= mogelijkeCollisionObjecten[i].GetCollisionRectangle().Left + 5 &&
                    myCollisionRectangle.GetCollisionRectangle().Left <= mogelijkeCollisionObjecten[i].GetCollisionRectangle().Right - 5)
                {
                    TopCollisions.Add(mogelijkeCollisionObjecten[i]);
                }
            }
        }
Exemplo n.º 23
0
 public void checkBulletCollisionPlayer(ICollide collObject)
 {
     if (bullets.projectileList.Capacity != 0)
     {
         for (int i = 0; i < bullets.projectileList.Count; i++)
         {
             if (bullets.projectileList[i].collRect.Intersects(collObject.getCollisionRect()))
             {
                 if (bullets.projectileList[i].source is Enemy)
                 {
                     bullets.projectileList[i].isDeath = true;
                     collObject.gotHit();
                 }
             }
         }
     }
 }
Exemplo n.º 24
0
        private ICollide CheckCollision()
        {
            ICollide retVal = null;

            // If I'm not colliding with myself or an object of my same type, return that object
            if (collidables.Count > 1)
            {
                foreach (var item in collidables)
                {
                    if (item.Key.GetType() != this.parentObject.GetType() && // Objects of the same type don't collide
                        this.colliderRectangle.IntersectsWith(item.Value))   // If there is a collision
                    {
                        // Return the parent object of the colliding item
                        return(item.Key);
                    }
                }
            }
            return(retVal);
        }
Exemplo n.º 25
0
        public void Collide(float s, PhysicsGroupType groupType, ICollide other)
        {
            if (groupType == PhysicsGroupType.Physical)
            {
                Weapon.Collide(s, groupType, other);

                CollisionResult playerCollision = other.Collide(s, groupType, this.collision, null);
                if (playerCollision)
                {
                    if (collisionResult)
                    {
                        //Not sure if necessary, but if we have multiple collisions in a single frame, stop all movement.
                        collisionResult.PositionA = collision.Position;
                        collisionResult.VelocityA = Vector2.Zero;
                    }
                    else
                    {
                        collisionResult = playerCollision;
                    }
                    TakeDamage(playerCollision.Identity);
                }
            }
        }
Exemplo n.º 26
0
 public static void EnumNodes(DbvtNode root, ICollide collideable)
 {
     collideable.Process(root);
     if (root.IsInternal())
     {
         EnumNodes(root._children[0], collideable);
         EnumNodes(root._children[1], collideable);
     }
 }
Exemplo n.º 27
0
 //Projectile collisionobjecten toevoegen aan lijst
 public void AddProjectileCollisionObjects(ICollide collisionRectangle)
 {
     projectileCollisionObjecten.Add(collisionRectangle);
 }
Exemplo n.º 28
0
 public void Add(ICollide actor)
 {
     group.Add(actor);
 }
Exemplo n.º 29
0
 public static void EnumNodes(DbvtNode root, ICollide policy)
 {
     btDbvt_enumNodes(root._native, policy._native);
 }
Exemplo n.º 30
0
        public static void CollideTTpersistentStack(DbvtNode root0,
                                                    DbvtNode root1,
                                                    ICollide collideable)
        {
            //CollideTT(root0, root1, collideable);
            //return;
            if (root0 != null && root1 != null)
            {
                int depth    = 1;
                int treshold = DOUBLE_STACKSIZE - 4;

                m_stkStack.Resize(DOUBLE_STACKSIZE);
                m_stkStack[0] = new sStkNN(root0, root1);
                do
                {
                    sStkNN p = m_stkStack[--depth];
                    if (depth > treshold)
                    {
                        m_stkStack.Resize(m_stkStack.Count * 2);
                        treshold = m_stkStack.Count - 4;
                    }
                    if (p.a == p.b)
                    {
                        if (p.a.IsInternal())
                        {
                            m_stkStack[depth++] = new sStkNN(p.a._children[0], p.a._children[0]);
                            m_stkStack[depth++] = new sStkNN(p.a._children[1], p.a._children[1]);
                            m_stkStack[depth++] = new sStkNN(p.a._children[0], p.a._children[1]);
                        }
                    }
                    else if (DbvtAabbMm.Intersect(ref p.a.volume, ref p.b.volume))
                    {
                        if (p.a.IsInternal())
                        {
                            if (p.b.IsInternal())
                            {
                                m_stkStack[depth++] = new sStkNN(p.a._children[0], p.b._children[0]);
                                m_stkStack[depth++] = new sStkNN(p.a._children[1], p.b._children[0]);
                                m_stkStack[depth++] = new sStkNN(p.a._children[0], p.b._children[1]);
                                m_stkStack[depth++] = new sStkNN(p.a._children[1], p.b._children[1]);
                            }
                            else
                            {
                                m_stkStack[depth++] = new sStkNN(p.a._children[0], p.b);
                                m_stkStack[depth++] = new sStkNN(p.a._children[1], p.b);
                            }
                        }
                        else
                        {
                            if (p.b.IsInternal())
                            {
                                m_stkStack[depth++] = new sStkNN(p.a, p.b._children[0]);
                                m_stkStack[depth++] = new sStkNN(p.a, p.b._children[1]);
                            }
                            else
                            {
                                collideable.Process(p.a, p.b);
                            }
                        }
                    }
                } while (depth > 0);
            }
        }
Exemplo n.º 31
0
        /*
        public static void CollideKdop(DbvtNode root, Vector3 normals, float offsets, int count, ICollide policy)
        {
            btDbvt_collideKDOP(root._native, ref normals, offsets._native, count, policy._native);
        }

        public static void CollideOcl(DbvtNode root, Vector3 normals, float offsets, Vector3 sortaxis, int count, ICollide policy)
        {
            btDbvt_collideOCL(root._native, ref normals, offsets._native, ref sortaxis, count, policy._native);
        }

        public static void CollideOcl(DbvtNode root, Vector3 normals, float offsets, Vector3 sortaxis, int count, ICollide policy, bool fullsort)
        {
            btDbvt_collideOCL2(root._native, ref normals, offsets._native, ref sortaxis, count, policy._native, fullsort);
        }
        */
        public void CollideTT(DbvtNode root0, DbvtNode root1, ICollide policy)
        {
            btDbvt_collideTT(_native, root0._native, root1._native, policy._native);
        }
Exemplo n.º 32
0
		public static void rayTest( btDbvtNode root,
								ref btVector3 rayFrom,
								ref btVector3 rayTo,
								ICollide policy )
		{

			using( btDbvtStackDataBlock stackDataBlock = new btDbvtStackDataBlock() )
			{
				if( root != null )
				{
					btVector3 rayDir = ( rayTo - rayFrom );
					rayDir.normalize();

					///what about division by zero? -. just set rayDirection[i] to INF/BT_LARGE_FLOAT
					btVector3 rayDirectionInverse = new btVector3(
						rayDir.x == 0.0f ? btScalar.BT_LARGE_FLOAT : 1.0f / rayDir.x,
						rayDir.y == 0.0f ? btScalar.BT_LARGE_FLOAT : 1.0f / rayDir.y,
						rayDir.z == 0.0f ? btScalar.BT_LARGE_FLOAT : 1.0f / rayDir.z );

					stackDataBlock.signs[0] = rayDirectionInverse.x < 0.0f ? (uint)1 :0;
					stackDataBlock.signs[1] = rayDirectionInverse.y < 0.0f ? (uint)1 :0;
					stackDataBlock.signs[2] = rayDirectionInverse.z < 0.0f ? (uint)1 :0;


					btVector3 tmp; rayTo.Sub( ref rayFrom, out tmp );
					double lambda_max = btVector3.dot( ref rayDir, ref tmp );


					int depth = 1;
					int treshold = DOUBLE_STACKSIZE - 2;

					stackDataBlock.stack.Count = ( DOUBLE_STACKSIZE );
					stackDataBlock.stack[0] = root;
					do
					{
						btDbvtNode node = stackDataBlock.stack[--depth];

						stackDataBlock.bounds0 = node.volume._min;
						stackDataBlock.bounds1 = node.volume._max;

						double tmin = 1.0f, lambda_min = 0.0f;
						bool result1 = btAabbUtil.btRayAabb2( ref rayFrom, ref rayDirectionInverse, stackDataBlock.signs
							, ref stackDataBlock.bounds0
							, ref stackDataBlock.bounds1
							, out tmin, lambda_min, lambda_max );

#if COMPARE_BTRAY_AABB2
				double param=1.0f;
				bool result2 = AabbUtil.RayAabb(ref rayFrom,ref rayTo,node.volume.Mins(),node.volume.Maxs(),param,resultNormal);
				Debug.Assert(result1 == result2);
#endif //TEST_BTRAY_AABB2

						if( result1 )
						{
							if( node.IsInternal() )
							{
								if( depth > treshold )
								{
									stackDataBlock.stack.Count = ( stackDataBlock.stack.Count * 2 );
									treshold = stackDataBlock.stack.Count - 2;
								}
								stackDataBlock.stack[depth++] = node._children0;
								stackDataBlock.stack[depth++] = node._children1;
							}
							else
							{
								policy.Process( node );
							}
						}
					} while( depth != 0 );

				}
			}
		}
Exemplo n.º 33
0
		public static void rayTestInternal( btDbvtNode root,
									ref btVector3 rayFrom,
									ref btVector3 rayTo,
									ref btVector3 rayDirectionInverse,
									uint[] signs,
									double lambda_max,
									ref btVector3 aabbMin,
									ref btVector3 aabbMax,
									ICollide policy )
		{
			using( btDbvtStackDataBlock stackDataBlock = BulletGlobals.DbvtStackDataBlockPool.Get() )
			{
				//	(void) rayTo;
				//DBVT_CHECKTYPE
				if( root != null )
				{
					btVector3 resultNormal = new btVector3( 0, 1, 0 );

					int depth = 1;
					int treshold = DOUBLE_STACKSIZE - 2;
					stackDataBlock.stack[0] = root;
					do
					{
						btDbvtNode node = stackDataBlock.stack[--depth];
						node.volume._min.Sub( ref aabbMax, out stackDataBlock.bounds0 );
						node.volume._max.Sub( ref aabbMin, out stackDataBlock.bounds1 );
						double tmin = 1.0f, lambda_min = 0.0f;
						bool result1 = btAabbUtil.btRayAabb2( ref rayFrom, ref rayDirectionInverse, signs
							, ref stackDataBlock.bounds0
							, ref stackDataBlock.bounds1
							, out tmin, lambda_min, lambda_max );
						if( result1 )
						{
							if( node.IsInternal() )
							{
								if( depth > treshold )
								{
									stackDataBlock.stack.Count = ( stackDataBlock.stack.Count * 2 );
									treshold = stackDataBlock.stack.Count - 2;
								}
								stackDataBlock.stack[depth++] = node._children0;
								stackDataBlock.stack[depth++] = node._children1;
							}
							else
							{
								policy.Process( node );
							}
						}
					} while( depth != 0 );
				}

			}
		}
Exemplo n.º 34
0
		public static void CollideTT( btDbvtNode root0, btDbvtNode root1, ICollide collideable )
		{
			CollideTTCount++;
			Debug.Assert( CollideTTCount < 2 );
			CollideTTStack.Clear();

			if( root0 != null && root1 != null )
			{
				int depth = 1;
				int treshold = DOUBLE_STACKSIZE - 4;
				CollideTTStack[0].Initialize( root0, root1 );

				do
				{
					sStkNN p = CollideTTStack[--depth];

					if( depth > treshold )
					{
						CollideTTStack.Count = ( CollideTTStack.Count * 2 );
						treshold = CollideTTStack.Count - 4;
					}

					if( p.a == p.b )
					{
						if( p.a.IsInternal() )
						{
							CollideTTStack[depth++].Initialize( p.a._children0, p.a._children0 );
							CollideTTStack[depth++].Initialize( p.a._children1, p.a._children1 );
							CollideTTStack[depth++].Initialize( p.a._children0, p.a._children1 );
						}
					}
					else if( btDbvtVolume.Intersect( ref p.a.volume, ref p.b.volume ) )
					{
						if( p.a.IsInternal() )
						{
							if( p.b.IsInternal() )
							{
								CollideTTStack[depth++].Initialize( p.a._children0, p.b._children0 );
								CollideTTStack[depth++].Initialize( p.a._children1, p.b._children0 );
								CollideTTStack[depth++].Initialize( p.a._children0, p.b._children1 );
								CollideTTStack[depth++].Initialize( p.a._children1, p.b._children1 );
							}
							else
							{
								CollideTTStack[depth++].Initialize( p.a._children0, p.b );
								CollideTTStack[depth++].Initialize( p.a._children1, p.b );
							}
						}
						else
						{
							if( p.b.IsInternal() )
							{
								CollideTTStack[depth++].Initialize( p.a, p.b._children0 );
								CollideTTStack[depth++].Initialize( p.a, p.b._children1 );
							}
							else
							{
								collideable.Process( p.a, p.b );
							}
						}
					}
				} while( depth > 0 );
			}
			CollideTTCount--;
		}
Exemplo n.º 35
0
		public static void CollideTTpersistentStack( btDbvtNode root0,
								  btDbvtNode root1,
								  ICollide collideable )
		{
			//CollideTT(root0, root1, collideable);
			//return;
			if( root0 != null && root1 != null )
			{
				int depth = 1;
				int treshold = m_stkStack.Length - 4;

				//m_stkStack.Capacity = DOUBLE_STACKSIZE;
				m_stkStack[0].Initialize( root0, root1 );
				do
				{
					sStkNN p = m_stkStack[--depth];
					if( depth > treshold )
					{
						sStkNN[] newArray = new sStkNN[m_stkStack.Length * 2];
						for( int n = 0; n < depth; n++ )
							newArray[n] = m_stkStack[n];
						m_stkStack = newArray;
						treshold = newArray.Length - 4;
					}
					if( p.a == p.b )
					{
						if( p.a.IsInternal() )
						{
							m_stkStack[depth++].Initialize( p.a._children0, p.a._children0 );
							m_stkStack[depth++].Initialize( p.a._children1, p.a._children1 );
							m_stkStack[depth++].Initialize( p.a._children0, p.a._children1 );
						}
					}
					else if( btDbvtVolume.Intersect( ref p.a.volume, ref p.b.volume ) )
					{
						if( p.a.IsInternal() )
						{
							if( p.b.IsInternal() )
							{
								m_stkStack[depth++].Initialize( p.a._children0, p.b._children0 );
								m_stkStack[depth++].Initialize( p.a._children1, p.b._children0 );
								m_stkStack[depth++].Initialize( p.a._children0, p.b._children1 );
								m_stkStack[depth++].Initialize( p.a._children1, p.b._children1 );
							}
							else
							{
								m_stkStack[depth++].Initialize( p.a._children0, p.b );
								m_stkStack[depth++].Initialize( p.a._children1, p.b );
							}
						}
						else
						{
							if( p.b.IsInternal() )
							{
								m_stkStack[depth++].Initialize( p.a, p.b._children0 );
								m_stkStack[depth++].Initialize( p.a, p.b._children1 );
							}
							else
							{
								collideable.Process( p.a, p.b );
							}
						}
					}
				} while( depth > 0 );
			}
		}
Exemplo n.º 36
0
		public static void EnumLeaves( btDbvtNode root, ICollide collideable )
		{
			if( root.IsInternal() )
			{
				EnumLeaves( root._children0, collideable );
				EnumLeaves( root._children1, collideable );
			}
			else
			{
				collideable.Process( root );
			}
		}
Exemplo n.º 37
0
 public static void CollideTV(DbvtNode root, ref DbvtAabbMm volume, ICollide collideable, Stack<DbvtNode> collideTVStack, ref int collideTVCount)
 {
     collideTVCount++;
     //Debug.Assert(CollideTVCount < 2);
     collideTVStack.Clear();
     if (root != null)
     {
         collideTVStack.Push(root);
         do
         {
             DbvtNode n = collideTVStack.Pop();
             if (DbvtAabbMm.Intersect(ref n.volume, ref volume))
             {
                 if (n.IsInternal())
                 {
                     collideTVStack.Push(n._children[0]);
                     collideTVStack.Push(n._children[1]);
                 }
                 else
                 {
                     collideable.Process(n);
                 }
             }
         } while (collideTVStack.Count > 0);
     }
     collideTVCount--;
 }
Exemplo n.º 38
0
        public void RayTestInternal(DbvtNode root,
                                    ref IndexedVector3 rayFrom,
                                    ref IndexedVector3 rayTo,
                                    ref IndexedVector3 rayDirectionInverse,
                                    bool[] signs,
                                    float lambda_max,
                                    ref IndexedVector3 aabbMin,
                                    ref IndexedVector3 aabbMax,
                                    ICollide policy)
        {
            using (DbvtStackDataBlock stackDataBlock = BulletGlobals.DbvtStackDataBlockPool.Get())
            {
                //    (void) rayTo;
                //DBVT_CHECKTYPE
                if (root != null)
                {
                    IndexedVector3 resultNormal = new IndexedVector3(0, 1, 0);

                    int depth = 1;
                    int treshold = DOUBLE_STACKSIZE - 2;
                    stackDataBlock.stack[0] = root;
                    do
                    {
                        DbvtNode node = stackDataBlock.stack[--depth];
                        stackDataBlock.bounds[0] = node.volume.Mins() - aabbMax;
                        stackDataBlock.bounds[1] = node.volume.Maxs() - aabbMin;
                        float tmin = 1.0f, lambda_min = 0.0f;
                        bool result1 = AabbUtil2.RayAabb2(ref rayFrom, ref rayDirectionInverse, signs, stackDataBlock.bounds, out tmin, lambda_min, lambda_max);
                        if (result1)
                        {
                            if (node.IsInternal())
                            {
                                if (depth > treshold)
                                {
                                    stackDataBlock.stack.Resize(stackDataBlock.stack.Count * 2);
                                    treshold = stackDataBlock.stack.Count - 2;
                                }
                                stackDataBlock.stack[depth++] = node._children[0];
                                stackDataBlock.stack[depth++] = node._children[1];
                            }
                            else
                            {
                                policy.Process(node);
                            }
                        }
                    } while (depth != 0);
                }

            }
        }
Exemplo n.º 39
0
 public void CollideTTPersistentStack(DbvtNode root0, DbvtNode root1, ICollide policy)
 {
     btDbvt_collideTTpersistentStack(_native, root0._native, root1._native, policy._native);
 }
Exemplo n.º 40
0
		public static void CollideTV( btDbvtNode root, ref btDbvtVolume volume, ICollide collideable )
		{
			CollideTVCount++;
			Debug.Assert( CollideTVCount < 2 );
			CollideTVStack.Clear();
			if( root != null )
			{
				CollideTVStack.Push( root );
				do
				{
					btDbvtNode n = CollideTVStack.Pop();
					if( btDbvtVolume.Intersect( ref n.volume, ref volume ) )
					{
						if( n.IsInternal() )
						{
							CollideTVStack.Push( n._children0 );
							CollideTVStack.Push( n._children1 );
						}
						else
						{
							collideable.Process( n );
						}
					}
				} while( CollideTVStack.Count > 0 );
			}
			CollideTVCount--;
		}
Exemplo n.º 41
0
        public static void CollideTT(DbvtNode root0, DbvtNode root1, ICollide collideable)
        {
            CollideTTCount++;
            Debug.Assert(CollideTTCount < 2);
            CollideTTStack.Clear();

            if (root0 != null && root1 != null)
            {
                int depth    = 1;
                int treshold = DOUBLE_STACKSIZE - 4;
                CollideTTStack[0] = new sStkNN(root0, root1);

                do
                {
                    sStkNN p = CollideTTStack[--depth];

                    if (depth > treshold)
                    {
                        CollideTTStack.Resize(CollideTTStack.Count * 2);
                        treshold = CollideTTStack.Count - 4;
                    }

                    if (p.a == p.b)
                    {
                        if (p.a.IsInternal())
                        {
                            CollideTTStack[depth++] = new sStkNN(p.a._children[0], p.a._children[0]);
                            CollideTTStack[depth++] = new sStkNN(p.a._children[1], p.a._children[1]);
                            CollideTTStack[depth++] = new sStkNN(p.a._children[0], p.a._children[1]);
                        }
                    }
                    else if (DbvtAabbMm.Intersect(ref p.a.volume, ref p.b.volume))
                    {
                        if (p.a.IsInternal())
                        {
                            if (p.b.IsInternal())
                            {
                                CollideTTStack[depth++] = new sStkNN(p.a._children[0], p.b._children[0]);
                                CollideTTStack[depth++] = new sStkNN(p.a._children[1], p.b._children[0]);
                                CollideTTStack[depth++] = new sStkNN(p.a._children[0], p.b._children[1]);
                                CollideTTStack[depth++] = new sStkNN(p.a._children[1], p.b._children[1]);
                            }
                            else
                            {
                                CollideTTStack[depth++] = new sStkNN(p.a._children[0], p.b);
                                CollideTTStack[depth++] = new sStkNN(p.a._children[1], p.b);
                            }
                        }
                        else
                        {
                            if (p.b.IsInternal())
                            {
                                CollideTTStack[depth++] = new sStkNN(p.a, p.b._children[0]);
                                CollideTTStack[depth++] = new sStkNN(p.a, p.b._children[1]);
                            }
                            else
                            {
                                collideable.Process(p.a, p.b);
                            }
                        }
                    }
                } while (depth > 0);
            }
            CollideTTCount--;
        }
Exemplo n.º 42
0
 public CollisionEventArgs(ICollide collidingObject)
 {
     this.otherObject = collidingObject;
 }
Exemplo n.º 43
0
        public static void RayTest(DbvtNode root,
                                   ref IndexedVector3 rayFrom,
                                   ref IndexedVector3 rayTo,
                                   ICollide policy)
        {
            using (DbvtStackDataBlock stackDataBlock = BulletGlobals.DbvtStackDataBlockPool.Get())
            {
                if (root != null)
                {
                    IndexedVector3 rayDir = (rayTo - rayFrom);
                    rayDir.Normalize();

                    ///what about division by zero? -. just set rayDirection[i] to INF/BT_LARGE_FLOAT
                    IndexedVector3 rayDirectionInverse = new IndexedVector3(
                        rayDir.X == 0.0f ? MathUtil.BT_LARGE_FLOAT : 1.0f / rayDir.X,
                        rayDir.Y == 0.0f ? MathUtil.BT_LARGE_FLOAT : 1.0f / rayDir.Y,
                        rayDir.Z == 0.0f ? MathUtil.BT_LARGE_FLOAT : 1.0f / rayDir.Z);

                    stackDataBlock.signs[0] = rayDirectionInverse.X < 0.0f;
                    stackDataBlock.signs[1] = rayDirectionInverse.Y < 0.0f;
                    stackDataBlock.signs[2] = rayDirectionInverse.Z < 0.0f;


                    float lambda_max = IndexedVector3.Dot(rayDir, (rayTo - rayFrom));


                    int depth    = 1;
                    int treshold = DOUBLE_STACKSIZE - 2;

                    stackDataBlock.stack.Resize(DOUBLE_STACKSIZE);
                    stackDataBlock.stack[0] = root;
                    do
                    {
                        DbvtNode node = stackDataBlock.stack[--depth];

                        stackDataBlock.bounds[0] = node.volume.Mins();
                        stackDataBlock.bounds[1] = node.volume.Maxs();

                        float tmin = 1.0f, lambda_min = 0.0f;
                        bool  result1 = AabbUtil2.RayAabb2(ref rayFrom, ref rayDirectionInverse, stackDataBlock.signs, stackDataBlock.bounds, out tmin, lambda_min, lambda_max);

#if COMPARE_BTRAY_AABB2
                        float param   = 1.0f;
                        bool  result2 = AabbUtil.RayAabb(ref rayFrom, ref rayTo, node.volume.Mins(), node.volume.Maxs(), param, resultNormal);
                        Debug.Assert(result1 == result2);
#endif //TEST_BTRAY_AABB2

                        if (result1)
                        {
                            if (node.IsInternal())
                            {
                                if (depth > treshold)
                                {
                                    stackDataBlock.stack.Resize(stackDataBlock.stack.Count * 2);
                                    treshold = stackDataBlock.stack.Count - 2;
                                }
                                stackDataBlock.stack[depth++] = node._children[0];
                                stackDataBlock.stack[depth++] = node._children[1];
                            }
                            else
                            {
                                policy.Process(node);
                            }
                        }
                    } while (depth != 0);
                }
            }
        }
Exemplo n.º 44
0
 public static void CollideTU(DbvtNode root, ICollide policy)
 {
     btDbvt_collideTU(root._native, policy._native);
 }
Exemplo n.º 45
0
 public static void RayTest(DbvtNode root, Vector3 rayFrom, Vector3 rayTo, ICollide policy)
 {
     btDbvt_rayTest(root._native, ref rayFrom, ref rayTo, policy._native);
 }
Exemplo n.º 46
0
 public void RayTestInternal(DbvtNode root, Vector3 rayFrom, Vector3 rayTo, Vector3 rayDirectionInverse, uint[] signs, float lambdaMax, Vector3 aabbMin, Vector3 aabbMax, ICollide policy)
 {
     btDbvt_rayTestInternal(_native, root._native, ref rayFrom, ref rayTo, ref rayDirectionInverse, signs, lambdaMax, ref aabbMin, ref aabbMax, policy._native);
 }
Exemplo n.º 47
0
 public void Remove(ICollide actor)
 {
     group.Remove(actor);
 }
Exemplo n.º 48
0
 public void CollideTV(DbvtNode root, DbvtVolume volume, ICollide policy)
 {
     btDbvt_collideTV(_native, root._native, volume._native, policy._native);
 }
Exemplo n.º 49
0
        public static void RayTest(DbvtNode root,
                                ref IndexedVector3 rayFrom,
                                ref IndexedVector3 rayTo,
                                ICollide policy)
        {

            using (DbvtStackDataBlock stackDataBlock = BulletGlobals.DbvtStackDataBlockPool.Get())
            {
                if (root != null)
                {
                    IndexedVector3 rayDir = (rayTo - rayFrom);
                    rayDir.Normalize();

                    ///what about division by zero? -. just set rayDirection[i] to INF/BT_LARGE_FLOAT
                    IndexedVector3 rayDirectionInverse = new IndexedVector3(
                        rayDir.X == 0.0f ? MathUtil.BT_LARGE_FLOAT : 1.0f / rayDir.X,
                        rayDir.Y == 0.0f ? MathUtil.BT_LARGE_FLOAT : 1.0f / rayDir.Y,
                        rayDir.Z == 0.0f ? MathUtil.BT_LARGE_FLOAT : 1.0f / rayDir.Z);

                    stackDataBlock.signs[0] = rayDirectionInverse.X < 0.0f;
                    stackDataBlock.signs[1] = rayDirectionInverse.Y < 0.0f;
                    stackDataBlock.signs[2] = rayDirectionInverse.Z < 0.0f;


                    float lambda_max = IndexedVector3.Dot(rayDir, (rayTo - rayFrom));


                    int depth = 1;
                    int treshold = DOUBLE_STACKSIZE - 2;

                    stackDataBlock.stack.Resize(DOUBLE_STACKSIZE);
                    stackDataBlock.stack[0] = root;
                    do
                    {
                        DbvtNode node = stackDataBlock.stack[--depth];

                        stackDataBlock.bounds[0] = node.volume.Mins();
                        stackDataBlock.bounds[1] = node.volume.Maxs();

                        float tmin = 1.0f, lambda_min = 0.0f;
                        bool result1 = AabbUtil2.RayAabb2(ref rayFrom, ref rayDirectionInverse, stackDataBlock.signs, stackDataBlock.bounds, out tmin, lambda_min, lambda_max);

#if COMPARE_BTRAY_AABB2
				float param=1.0f;
				bool result2 = AabbUtil.RayAabb(ref rayFrom,ref rayTo,node.volume.Mins(),node.volume.Maxs(),param,resultNormal);
				Debug.Assert(result1 == result2);
#endif //TEST_BTRAY_AABB2

                        if (result1)
                        {
                            if (node.IsInternal())
                            {
                                if (depth > treshold)
                                {
                                    stackDataBlock.stack.Resize(stackDataBlock.stack.Count * 2);
                                    treshold = stackDataBlock.stack.Count - 2;
                                }
                                stackDataBlock.stack[depth++] = node._children[0];
                                stackDataBlock.stack[depth++] = node._children[1];
                            }
                            else
                            {
                                policy.Process(node);
                            }
                        }
                    } while (depth != 0);

                }
            }
        }
Exemplo n.º 50
0
        public static void CollideTTpersistentStack(DbvtNode root0,
                                  DbvtNode root1,
                                  ICollide collideable)
        {
            //CollideTT(root0, root1, collideable);
            //return;
            if (root0 != null && root1 != null)
            {
                int depth = 1;
                int treshold = DOUBLE_STACKSIZE - 4;

                m_stkStack.Resize(DOUBLE_STACKSIZE);
                m_stkStack[0] = new sStkNN(root0, root1);
                do
                {
                    sStkNN p = m_stkStack[--depth];
                    if (depth > treshold)
                    {
                        m_stkStack.Resize(m_stkStack.Count * 2);
                        treshold = m_stkStack.Count - 4;
                    }
                    if (p.a == p.b)
                    {
                        if (p.a.IsInternal())
                        {
                            m_stkStack[depth++] = new sStkNN(p.a._children[0], p.a._children[0]);
                            m_stkStack[depth++] = new sStkNN(p.a._children[1], p.a._children[1]);
                            m_stkStack[depth++] = new sStkNN(p.a._children[0], p.a._children[1]);
                        }
                    }
                    else if (DbvtAabbMm.Intersect(ref p.a.volume, ref p.b.volume))
                    {
                        if (p.a.IsInternal())
                        {
                            if (p.b.IsInternal())
                            {
                                m_stkStack[depth++] = new sStkNN(p.a._children[0], p.b._children[0]);
                                m_stkStack[depth++] = new sStkNN(p.a._children[1], p.b._children[0]);
                                m_stkStack[depth++] = new sStkNN(p.a._children[0], p.b._children[1]);
                                m_stkStack[depth++] = new sStkNN(p.a._children[1], p.b._children[1]);
                            }
                            else
                            {
                                m_stkStack[depth++] = new sStkNN(p.a._children[0], p.b);
                                m_stkStack[depth++] = new sStkNN(p.a._children[1], p.b);
                            }
                        }
                        else
                        {
                            if (p.b.IsInternal())
                            {
                                m_stkStack[depth++] = new sStkNN(p.a, p.b._children[0]);
                                m_stkStack[depth++] = new sStkNN(p.a, p.b._children[1]);
                            }
                            else
                            {
                                collideable.Process(p.a, p.b);
                            }
                        }
                    }
                } while (depth > 0);
            }
        }