Пример #1
0
        private void SetProxyIdForEntity(AABBEntity entity, int newId)
        {
            if (entity.ProxyIdsByTree == null)
            {
                entity.ProxyIdsByTree = new Dictionary <long, int>();
            }

            entity.ProxyIdsByTree[TreeId] = newId;
        }
Пример #2
0
        public void Remove(AABBEntity entity)
        {
            int proxyId = GetProxyIdForEntity(entity);

            Log.Trace("Remove entity " + proxyId, "Remove");

            if (proxyId != PROXY_ID_UNITIALIZED)
            {
                MathTree.RemoveProxy(proxyId);
                SetProxyIdForEntity(entity, PROXY_ID_UNITIALIZED);
            }

            Log.Trace("Finished Remove entity " + proxyId, "Remove");
        }
Пример #3
0
        public BoundingBoxD GetEntityAABB(AABBEntity entity)
        {
            BoundingBoxD bbox = entity.BoundingBox;

            //Include entity velocity to be able to hit fast moving objects
            if (entity.WorldTranslation != null && entity.LinearVelocity != null)
            {
                bbox = bbox.Include(
                    entity.WorldTranslation +
                    entity.LinearVelocity *
                    MyEngineConstants.UPDATE_STEP_SIZE_IN_SECONDS * 5
                    );
            }

            return(bbox);
        }
Пример #4
0
        // We define these here because AABBEntity is an interface

        private int GetProxyIdForEntity(AABBEntity entity)
        {
            if (entity.ProxyIdsByTree == null)
            {
                entity.ProxyIdsByTree = new Dictionary <long, int>();
            }

            if (!entity.ProxyIdsByTree.ContainsKey(TreeId))
            {
                return(PROXY_ID_UNITIALIZED);
            }
            else
            {
                return(entity.ProxyIdsByTree[TreeId]);
            }
        }
Пример #5
0
        public void Move(AABBEntity entity)
        {
            int proxyId = GetProxyIdForEntity(entity);

            if (proxyId != PROXY_ID_UNITIALIZED)
            {
                BoundingBoxD bbox = GetEntityAABB(entity);

                if (bbox.Size == Vector3D.Zero)  // remove entities with zero bounding boxes
                {
                    Remove(entity);
                    return;
                }

                MathTree.MoveProxy(proxyId, ref bbox, Vector3D.Zero);
            }
        }
Пример #6
0
        public void Add(AABBEntity entity)
        {
            int proxyId = GetProxyIdForEntity(entity);

            Log.Trace("Add entity " + proxyId, "Add");

            BoundingBoxD bbox = GetEntityAABB(entity);

            if (bbox.Size == Vector3D.Zero)
            {
                return;                              // don't add entities with zero bounding boxes
            }
            int newProxyId = MathTree.AddProxy(ref bbox, entity, 0);

            SetProxyIdForEntity(entity, newProxyId);

            Log.Trace("Finished Add entity " + newProxyId, "Add");
        }