Esempio n. 1
0
        public void FetchCollisions()
        {
            CubeModel.UpdateBounds(transform, (svector3)Position, (svector3)Scale);
            Colliding     = ActiveCollisions.Count > 0;
            DeltaPosition = ((svector3)transform.position + (svector3)Position) - LastPosition;
            LastPosition  = ((svector3)transform.position + (svector3)Position);

            for (int i = 0; i < NucleonManager.Colliders.Length; i++)
            {
                NucleonBoxCollider BoxCollider = (NucleonBoxCollider)NucleonManager.Colliders[i];
                if (BoxCollider != this)
                {
                    bool Colliding = intersector.CC_I(CubeModel, BoxCollider.CubeModel);
                    CollisionCheck(Colliding, BoxCollider);

                    if (Colliding && DebugCollisionVertices)
                    {
                        List <svector3> CollidingPointsFetchList = new List <svector3>();
                        foreach (svector3 Vertice in CubeModel.Vertices)
                        {
                            if (intersector.PC_I(Vertice, BoxCollider.CubeModel))
                            {
                                CollidingPointsFetchList.Add(Vertice);
                            }
                        }
                        CollidingPoints = CollidingPointsFetchList;
                    }
                    if (!Colliding && DebugCollisionVertices)
                    {
                        CollidingPoints.Clear();
                    }
                }
            }
        }
Esempio n. 2
0
        private void CollisionCheck(bool Colliding, NucleonBoxCollider BoxCollider)
        {
            if (Colliding)
            {
                NucleonCollision Collision = new NucleonCollision();
                Collision.SelfCollider       = this;
                Collision.OtherCollider      = BoxCollider;
                Collision.CollisionDirection = DeltaPosition;

                Collision.TouchingMinX = CubeModel.MaxX >= BoxCollider.CubeModel.MinX && CubeModel.MaxX <= BoxCollider.CubeModel.MinX + (sfloat)0.1f;
                Collision.TouchingMaxX = CubeModel.MinX <= BoxCollider.CubeModel.MaxX && CubeModel.MinX >= BoxCollider.CubeModel.MaxX - (sfloat)0.1f;

                Collision.TouchingMinY = CubeModel.MaxY >= BoxCollider.CubeModel.MinY && CubeModel.MaxY <= BoxCollider.CubeModel.MinY + (sfloat)0.1f;
                Collision.TouchingMaxY = CubeModel.MinY <= BoxCollider.CubeModel.MaxY && CubeModel.MinY >= BoxCollider.CubeModel.MaxY - (sfloat)0.5f;

                Collision.TouchingMinZ = CubeModel.MaxZ >= BoxCollider.CubeModel.MinZ && CubeModel.MaxZ <= BoxCollider.CubeModel.MinZ + (sfloat)0.1f;
                Collision.TouchingMaxZ = CubeModel.MinZ <= BoxCollider.CubeModel.MaxZ && CubeModel.MinZ >= BoxCollider.CubeModel.MaxZ - (sfloat)0.1f;

                if (!ActiveCollisions.Contains(BoxCollider))
                {
                    ActiveCollisions.Add(BoxCollider);
                    Body?.OnNucleonCollisionEnter(Collision);
                }
            }
            else
            {
                if (ActiveCollisions.Contains(BoxCollider))
                {
                    NucleonCollisionExit CollisionExit = new NucleonCollisionExit();
                    CollisionExit.SelfCollider  = this;
                    CollisionExit.OtherCollider = BoxCollider;
                    CollisionExit.ExitDirection = DeltaPosition;

                    ActiveCollisions.Remove(BoxCollider);
                    Body?.OnNucleonCollisionExit(CollisionExit);
                }
            }
        }