Beispiel #1
0
        public static void DetectCameraBuildingCollisions(Camera camera,Building building)
        {
            if (building.BoundingBox.Max.Y < camera.BoundingSphere.Center.Y)
                return;
            if(camera.BoundingSphere.Intersects(building.BoundingBox)){
                float leftSep = building.BoundingBox.Min.X - (camera.BoundingSphere.Center.X + camera.BoundingSphere.Radius) ;
                float rightSep =building.BoundingBox.Max.X -(camera.BoundingSphere.Center.X - camera.BoundingSphere.Radius);
                float topSep =  building.BoundingBox.Max.Z - (camera.BoundingSphere.Center.Z - camera.BoundingSphere.Radius);
                float botSep =  building.BoundingBox.Min.Z -(camera.BoundingSphere.Center.Z + camera.BoundingSphere.Radius);

                float moveXaxis=rightSep;
                if(Math.Abs(leftSep)<Math.Abs(rightSep))
                    moveXaxis = leftSep;
                float moveZaxis=topSep;
                if(Math.Abs(botSep)<Math.Abs(topSep))
                    moveZaxis = botSep;

                if (Math.Abs(moveXaxis) < Math.Abs(moveZaxis))
                {
                    camera.ShiftAlongX(moveXaxis);
                }
                else
                {
                    camera.ShiftAlongZ(moveZaxis);
                }

            }
        }
Beispiel #2
0
        public static Building makeBuilding(char c,Vector2 position)
        {
            Building b = new Building(theGame);
            int stories = c - '0';
            b.Texture = textures[stories];
            b.Height = stories * storyHeight;
            b.Position = new Vector3(position.X * blockSize.Width,0,position.Y*blockSize.Height);
            b.Size = blockSize;
            b.RoofTexture = roofTextures[stories % 4];

            b.Init();
            return b;
        }