Exemple #1
0
        public void TryEntityCollision(Component characterRootComponent)
        {
            CollisionUnit    characterCollisionUnit = CollisionUnits.Find(unit => unit.RootComponent == characterRootComponent);
            Component        collidedRootComponent = null;
            BoundBase        characterBound = characterCollisionUnit.GetFirstBoundingBox();
            List <BoundBase> collidedRootBounds = new List <BoundBase>();
            bool             bFrameBoundingBoxCollision = false, bRegularBoundingBoxCollision = false;

            // Check Collision. Step 1  - check axis aligned framing bounding boxes for collision -- (PRE COLLISION)
            CheckFrameBoundingBoxCollision(ref bFrameBoundingBoxCollision, ref characterRootComponent, ref characterCollisionUnit, ref collidedRootComponent, ref collidedRootBounds);

            // Check Collision. Step 2 - check all bounding boxes of concrete component for collision -- (PURE COLLISION DETECTION)
            List <BoundBase> collidedBounds = new List <BoundBase>();

            CheckRegularBoundingBoxCollision(ref bRegularBoundingBoxCollision, ref characterRootComponent, ref collidedRootComponent, ref collidedRootBounds, ref characterBound, ref collidedBounds);

            // Check Collision. Step 3 - Ray trace -- (BEHAVIOR OF COLLISION RESOLVING)
            BehaviorManager.ProcessCollision(CollisionOutput);

            // Clear all output after collision handling
            CollisionOutput.Clear();
        }
Exemple #2
0
        private void CheckFrameBoundingBoxCollision(ref bool bFrameBoundBoxCollision, ref Component characterRootComponent, ref CollisionUnit characterCollisionUnit,
                                                    ref Component collidedRootComponent, ref List <BoundBase> collidedRootBounds)
        {
            foreach (var unit in CollisionUnits)
            {
                if (characterCollisionUnit.RootComponent == unit.RootComponent)
                {
                    continue;
                }

                AABB aabb1 = characterCollisionUnit.GetAndTryUpdateFramingBoundingBox();
                AABB aabb2 = unit.GetAndTryUpdateFramingBoundingBox();
                if (GeometryMath.AABBAABB(aabb1, aabb2))
                {
                    bFrameBoundBoxCollision = true;
                    collidedRootComponent   = aabb2.ParentComponent.GetRootComponent();
                    collidedRootBounds.AddRange(unit.GetBoundingBoxes());
                }
            }

            if (bFrameBoundBoxCollision)
            {
                CollisionOutput.Add(new CollisionOutputFramingAABB(characterRootComponent, collidedRootComponent));
            }
            else
            {
                CollisionOutput.Add(new CollisionOutputNoCollided(characterRootComponent));
            }
        }
Exemple #3
0
        // when component's transform is changed notify bound boxes that they have to be changed
        public void NotifyCollisionObserver(Component rootComponent)
        {
            CollisionUnit characterCollisionUnit = CollisionUnits.Find(unit => unit.RootComponent == rootComponent);

            characterCollisionUnit.bBoundingBoxesTransformDirty = true;
        }