Example #1
0
        public bool CheckCollide(ISpaceObject hiter, ISpaceObject dest)
        {
            Shape srcShape  = hiter.GetCollideShape();
            Shape destShape = dest.GetCollideShape();

            if (null == srcShape)
            {
                LogSystem.Error("CheckCollide:hiter obj({0}[{1}])'s shape is null", hiter.GetID(), hiter.GetObjType());
                return(false);
            }
            if (null == destShape)
            {
                LogSystem.Error("CheckCollide:dest obj({0}[{1}])'s shape is null", dest.GetID(), dest.GetObjType());
                return(false);
            }
            bool is_collide          = collide_detector_.Intersect(srcShape, destShape);
            bool is_allready_collide = IsAllreadyCollide(hiter, dest);

            if (is_collide)               // 碰撞
            {
                if (!is_allready_collide) // 之前没有碰撞,记录下相撞的物体
                //DLog._("spatialsystem", "{4} spatial collide obj({0},{1}) with obj({2},{3})",
                //           hiter.GetID(), hiter.GetObjType(), dest.GetID(),
                //           dest.GetObjType(), current_spatial_id_);
                {
                    hiter.OnCollideObject(dest);
                    dest.OnCollideObject(hiter);
                }
            }
            else if (is_allready_collide) // 当前没有碰撞,但是之前碰撞,即分离的情况
            //DLog._("spatialsystem", "{4} spatial depart obj({0},{1}) with obj({2},{3})",
            //           hiter.GetID(), hiter.GetObjType(),
            //           dest.GetID(), dest.GetObjType(), current_spatial_id_);
            {
                hiter.OnDepartObject(dest);
                dest.OnDepartObject(hiter);
            }
            return(is_collide);
        }