Esempio n. 1
0
        public Main()
        {
            mGraphics = new GraphicsDeviceManager(this)
            {
                GraphicsProfile = GraphicsProfile.HiDef, PreferredBackBufferWidth = 1920, PreferredBackBufferHeight = 1080
            };

            mCamera = new Camera(fieldOfView: 55.0f, aspectRatio: 2.0f, nearPlane: 1.0f, farPlane: 400.0f);
            mCamera.UpdatePerspective();

            mViewport = new Viewport(0, 0, 1920, 1080);

            mCamera.mLocation = new Vector3(0.0f, 20.0f, -10.0f);

            mScene = new Scene();
            mLight = new Light();

            mLight.mAmbient  = 0.1f;
            mLight.mLocation = new Vector3(1.0f, 1.0f, 0.0f) * 2000.0f;

            mCameraHandler  = new CameraHandler(mCamera, 4.0f, 2.0f, .05f);
            mFrustumCulling = new FrustumCulling();

            mScene.Add(mLight);

            IsMouseVisible = true;

            Content.RootDirectory = "Content";
        }
Esempio n. 2
0
        private void InitPhysics()
        {
            Quad = new CollisionQuad(-1.0f, 1.0f, 0.0f, 0.0f, -1.0f, 1.0f);
            Quad.LBNCoordinates = Vector3.TransformPosition(Quad.LBNCoordinates, m_modelMatrix);
            Quad.RTFCoordinates = Vector3.TransformPosition(Quad.RTFCoordinates, m_modelMatrix);

            // divide water collision box to avoid "bugs" with frustum culling
            m_collisionCheckPoints = FrustumCulling.divideWaterCollisionBox(Quad, m_frustumSquares);
        }
Esempio n. 3
0
        /// <summary> Returns whether the model should be rendered based on the given entity's position. </summary>
        public virtual bool ShouldRender(Entity p, FrustumCulling culling)
        {
            Vector3 pos    = p.Position;
            AABB    bb     = PickingBounds;
            float   maxLen = Math.Max(bb.Width, Math.Max(bb.Height, bb.Length)) * p.ModelScale;

            pos.Y += bb.Height / 2;             // centre Y coordinate
            return(culling.SphereInFrustum(pos.X, pos.Y, pos.Z, maxLen));
        }
Esempio n. 4
0
 public bool IsInViewFrustum(ref Matrix4 projectionMatrix, Matrix4 viewMatrix)
 {
     // set quad default value at beginning
     if (CQuad == null)
     {
         IsInCameraView = true;
     }
     else
     {
         IsInCameraView = FrustumCulling.isQuadIntersection(CQuad, viewMatrix, projectionMatrix);
     }
     return(IsInCameraView);
 }
Esempio n. 5
0
        // Implement method of iOptimizable interface
        public bool IsInViewFrustum(ref Matrix4 projectionMatrix, Matrix4 viewMatrix)
        {
            if (Object.Equals(this.m_collisionCheckPoints, null))
            {
                // disable optimization, keep water always in view frustum
                IsInCameraView = true;
            }
            else
            {
                IsInCameraView = this.IsInCameraView = FrustumCulling.isWaterIntersection(this.m_collisionCheckPoints, viewMatrix, ref projectionMatrix);
            }

            return(IsInCameraView);
        }
Esempio n. 6
0
        /// <summary>
        /// Updates the scene, including the camera and the animations.
        /// </summary>
        /// <param name="camera"></param>
        /// <param name="gameTime">The current game time</param>
        public virtual void Update(Camera camera, GameTime gameTime)
        {
            camera.UpdateView();
            camera.UpdatePerspective();

            var visibleActors = FrustumCulling.CullActorsOutsideFrustum(this, camera);

            mSky.Update(camera);

            var visibleShadowCasters = FrustumCulling.CullShadowCastersOutsideFrustum(this);

            if (mTerrain != null)
            {
                var visibleGrassPatches = FrustumCulling.CullGrassPatchesOutsideFrustum(mTerrain.mGrass, camera);
            }

            foreach (var actorBatch in mActorBatches)
            {
                foreach (var actor in actorBatch.mActors)
                {
                    actor.QuadTree = false;
                }
            }

            var actorBatches = mActorBatches.ToArray();

            foreach (var actorBatch in actorBatches)
            {
                var actors = actorBatch.mActors.ToArray();

                foreach (var actor in actors)
                {
                    actor.IActor?.Update(gameTime);
                }


                if (!actorBatch.mMesh.mMeshData.mIsSkinned)
                {
                    continue;
                }

                foreach (var actor in actors)
                {
                    actor.mAnimator.Update(gameTime, actor.ModelMatrix, actor.mRender);
                }
            }
        }
Esempio n. 7
0
 private void CheckComponentsAreVisible(ref Component parentComponent, ref Matrix4 viewMatrix, ref Matrix4 projectionMatrix, ref bool bVisible)
 {
     if (parentComponent.Bound != null)
     {
         bVisible = FrustumCulling.GetIsBoundInFrustum(parentComponent.Bound, ref viewMatrix, ref projectionMatrix);
         if (bVisible)
         {
             return;
         }
     }
     foreach (Component childComponent in parentComponent.ChildrenComponents)
     {
         var child = childComponent;
         CheckComponentsAreVisible(ref child, ref viewMatrix, ref projectionMatrix, ref bVisible);
         if (bVisible)
         {
             return;
         }
     }
 }
Esempio n. 8
0
        public Main()
        {
            // Enable user shader with HiDef
            mGraphics = new GraphicsDeviceManager(this)
            {
                GraphicsProfile = GraphicsProfile.HiDef, PreferredBackBufferWidth = 1280, PreferredBackBufferHeight = 720
            };

            Content.RootDirectory = "Content";

            mCamera = new Camera(new Vector3(15.0f * 4.0f, -25.0f, -65.0f), farPlane: 500.0f);

            mScene   = new Scene();
            mLight   = new Light(color: new Vector3(1.0f), ambient: 0.1f);
            mCulling = new FrustumCulling();

            mScene.Add(mLight);

            IsMouseVisible = true;
            mF1KeyDown     = false;
        }
 public override bool ShouldRender(Entity p, FrustumCulling culling)
 {
     block = Utils.FastByte(p.ModelName);
     CalcState(block);
     return(base.ShouldRender(p, culling));
 }
Esempio n. 10
0
    public void Start()
    {
        textColorRenderer = new TextColorRenderer();
        textColorRenderer.platform = platform;
        language.platform = platform;
        language.LoadTranslations();
        GameData gamedata = new GameData();
        gamedata.Start();
        Config3d config3d = new Config3d();
        if (platform.IsFastSystem())
        {
            config3d.viewdistance = 128;
        }
        else
        {
            config3d.viewdistance = 32;
        }

        ITerrainTextures terrainTextures = new ITerrainTextures();
        terrainTextures.game = this;
        d_TextureAtlasConverter = new TextureAtlasConverter();
        d_TerrainTextures = terrainTextures;

        FrustumCulling frustumculling = new FrustumCulling();
        frustumculling.d_GetCameraMatrix = this.CameraMatrix;
        frustumculling.platform = platform;
        d_FrustumCulling = frustumculling;

        TerrainChunkTesselatorCi terrainchunktesselator = new TerrainChunkTesselatorCi();
        d_TerrainChunkTesselator = terrainchunktesselator;
        d_Batcher = new MeshBatcher();
        d_Batcher.d_FrustumCulling = frustumculling;
        d_Batcher.game = this;
        d_FrustumCulling = frustumculling;
        d_Data = gamedata;
        d_DataMonsters = new GameDataMonsters();
        d_Config3d = config3d;

        ModDrawParticleEffectBlockBreak particle = new ModDrawParticleEffectBlockBreak();
        this.particleEffectBlockBreak = particle;
        this.d_Data = gamedata;
        d_TerrainTextures = terrainTextures;

        map.Reset(256, 256, 128);

        SunMoonRenderer sunmoonrenderer = new SunMoonRenderer();
        d_SunMoonRenderer = sunmoonrenderer;
        d_SunMoonRenderer = sunmoonrenderer;
        d_Heightmap = new InfiniteMapChunked2d();
        d_Heightmap.d_Map = this;
        d_Heightmap.Restart();
        d_TerrainChunkTesselator = terrainchunktesselator;
        terrainchunktesselator.game = this;

        Packet_Inventory inventory = new Packet_Inventory();
        inventory.RightHand = new Packet_Item[10];
        GameDataItemsClient dataItems = new GameDataItemsClient();
        dataItems.game = this;
        InventoryUtilClient inventoryUtil = new InventoryUtilClient();
        d_Inventory = inventory;
        d_InventoryUtil = inventoryUtil;
        inventoryUtil.d_Inventory = inventory;
        inventoryUtil.d_Items = dataItems;
        d_Inventory = inventory;
        platform.AddOnCrash(OnCrashHandlerLeave.Create(this));

        rnd = platform.RandomCreate();

        clientmods = new ClientMod[128];
        clientmodsCount = 0;
        modmanager.game = this;
        AddMod(new ModDrawMain());
        AddMod(new ModUpdateMain());
        AddMod(new ModNetworkProcess());
        AddMod(new ModUnloadRendererChunks());
        AddMod(new ModAutoCamera());
        AddMod(new ModFpsHistoryGraph());
        AddMod(new ModWalkSound());
        AddMod(new ModFallDamageToPlayer());
        AddMod(new ModBlockDamageToPlayer());
        AddMod(new ModLoadPlayerTextures());
        AddMod(new ModSendPosition());
        AddMod(new ModInterpolatePositions());
        AddMod(new ModRail());
        AddMod(new ModCompass());
        AddMod(new ModGrenade());
        AddMod(new ModBullet());
        AddMod(new ModExpire());
        AddMod(new ModReloadAmmo());
        AddMod(new ModPush());
        if (platform.IsFastSystem())
        {
            AddMod(new ModSkySphereAnimated());
        }
        else
        {
            AddMod(new ModSkySphereStatic());
        }
        AddMod(sunmoonrenderer);
        AddMod(new ModDrawTestModel());
        AddMod(new ModDrawLinesAroundSelectedBlock());
        AddMod(new ModDebugChunk());
        AddMod(new ModDrawArea());
        AddMod(new ModDrawTerrain());
        AddMod(new ModDrawPlayers());
        AddMod(new ModDrawPlayerNames());
        AddMod(new ModDrawText());
        AddMod(new ModDrawParticleEffectBlockBreak());
        AddMod(new ModDrawSprites());
        AddMod(new ModDrawMinecarts());
        AddMod(new ModDrawHand2d());
        AddMod(new ModDrawHand3d());
        AddMod(new ModGuiCrafting());
        AddMod(new ModDialog());
        AddMod(new ModPicking());
        AddMod(new ModClearInactivePlayersDrawInfo());
        AddMod(new ModCameraKeys());
        AddMod(new ModSendActiveMaterial());
        AddMod(new ModCamera());
        AddMod(new ModNetworkEntity());
        AddMod(new ModGuiInventory());
        AddMod(new ModGuiTouchButtons());
        AddMod(new ModGuiEscapeMenu());
        AddMod(new ModGuiMapLoading());
        AddMod(new ModDraw2dMisc());
        AddMod(new ModGuiChat());
        AddMod(new ModScreenshot());
        AddMod(new ModAudio());

        s = new BlockOctreeSearcher();
        s.platform = platform;

        //Prevent loding screen from immediately displaying lag symbol
        LastReceivedMilliseconds = platform.TimeMillisecondsFromStart();

        ENABLE_DRAW_TEST_CHARACTER = platform.IsDebuggerAttached();

        int maxTextureSize_ = platform.GlGetMaxTextureSize();
        if (maxTextureSize_ < 1024)
        {
            maxTextureSize_ = 1024;
        }
        maxTextureSize = maxTextureSize_;
        MapLoadingStart();
        platform.GlClearColorRgbaf(0, 0, 0, 1);
        if (d_Config3d.ENABLE_BACKFACECULLING)
        {
            platform.GlDepthMask(true);
            platform.GlEnableDepthTest();
            platform.GlCullFaceBack();
            platform.GlEnableCullFace();
        }
        platform.GlEnableLighting();
        platform.GlEnableColorMaterial();
        platform.GlColorMaterialFrontAndBackAmbientAndDiffuse();
        platform.GlShadeModelSmooth();
    }
Esempio n. 11
0
 public override bool ShouldRender( Player p, FrustumCulling culling )
 {
     block = Utils.FastByte( p.ModelName );
     CalcState( block );
     return base.ShouldRender( p, culling );
 }
Esempio n. 12
0
 /// <summary> Returns whether the model should be rendered based on the given entity's position. </summary>
 public virtual bool ShouldRender( Player p, FrustumCulling culling )
 {
     Vector3 pos = p.Position;
     AABB bb = PickingBounds;
     float maxLen = Math.Max( bb.Width, Math.Max( bb.Height, bb.Length ) );
     maxLen *= p.ModelScale;
     return culling.SphereInFrustum( pos.X, pos.Y + maxLen / 2, pos.Z, maxLen );
 }
Esempio n. 13
0
        private void MakeGame()
        {
            var            getfile       = this.getfile;
            var            gamedata      = new GameDataCsv();
            var            clientgame    = w;
            ICurrentSeason currentseason = clientgame;

            gamedata.CurrentSeason = currentseason;
            var network        = w;
            var mapstorage     = clientgame;
            var config3d       = new Config3d();
            var mapManipulator = new MapManipulator();
            var the3d          = new The3d();

            the3d.d_GetFile      = getfile;
            the3d.d_Config3d     = config3d;
            the3d.d_ViewportSize = w;
            w.d_The3d            = the3d;
            var          localplayerposition = w;
            var          physics             = new CharacterPhysics();
            var          internetgamefactory = this;
            ICompression compression         = new CompressionGzip(); //IsSinglePlayer ? (ICompression)new CompressionGzip() : new CompressionGzip();

            network.d_Compression = compression;
            network.d_ResetMap    = this;
            if (IsSinglePlayer)
            {
                var socket = new SocketDummy()
                {
                    network = this.dummyNetwork
                };
                network.main = socket;
            }
            else
            {
                network.main = new SocketNet(new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp));
            }
            var terrainTextures = new TerrainTextures();

            terrainTextures.d_GetFile = getfile;
            terrainTextures.d_The3d   = the3d;
            bool IsMono = Type.GetType("Mono.Runtime") != null;

            terrainTextures.d_TextureAtlasConverter = new TextureAtlasConverter();
            if (IsMono)
            {
                terrainTextures.d_TextureAtlasConverter.d_FastBitmapFactory = () => { return(new FastBitmapDummy()); };
            }
            else
            {
                terrainTextures.d_TextureAtlasConverter.d_FastBitmapFactory = () => { return(new FastBitmap()); };
            }
            terrainTextures.Start();
            w.d_TerrainTextures = terrainTextures;
            var blockrenderertorch = new BlockRendererTorch();

            blockrenderertorch.d_TerainRenderer = terrainTextures;
            blockrenderertorch.d_Data           = gamedata;
            //InfiniteMapChunked map = new InfiniteMapChunked();// { generator = new WorldGeneratorDummy() };
            var map = w;
            var terrainchunktesselator = new TerrainChunkTesselator();

            terrainchunktesselator.d_Config3d          = config3d;
            terrainchunktesselator.d_Data              = gamedata;
            terrainchunktesselator.d_MapStorage        = clientgame;
            terrainchunktesselator.d_MapStoragePortion = map;
            terrainchunktesselator.d_MapStorageLight   = clientgame;
            w.d_TerrainChunkTesselator = terrainchunktesselator;
            var frustumculling = new FrustumCulling()
            {
                d_GetCameraMatrix = the3d
            };

            w.d_Batcher = new MeshBatcher()
            {
                d_FrustumCulling = frustumculling
            };
            w.d_FrustumCulling   = frustumculling;
            w.BeforeRenderFrame += (a, b) => { frustumculling.CalcFrustumEquations(); };
            terrainchunktesselator.d_BlockRendererTorch = blockrenderertorch;
            terrainchunktesselator.d_TerrainTextures    = terrainTextures;
            //w.d_Map = clientgame.mapforphysics;
            w.d_Physics        = physics;
            w.d_Clients        = clientgame;
            w.d_Data           = gamedata;
            w.d_DataMonsters   = new GameDataMonsters(getfile);
            w.d_GetFile        = getfile;
            w.d_Config3d       = config3d;
            w.d_MapManipulator = mapManipulator;
            w.PickDistance     = 4.5f;
            var skysphere = new SkySphere();

            skysphere.d_MeshBatcher = new MeshBatcher()
            {
                d_FrustumCulling = new FrustumCullingDummy()
            };
            skysphere.d_LocalPlayerPosition = localplayerposition;
            skysphere.d_The3d = the3d;
            w.skysphere       = skysphere;
            var textrenderer = new ManicDigger.Renderers.TextRenderer();

            w.d_TextRenderer = textrenderer;
            Inventory inventory = Inventory.Create();

            weapon = new WeaponBlockInfo()
            {
                d_Data = gamedata, d_Terrain = terrainTextures, d_Viewport = w, d_Map = clientgame, d_Shadows = w, d_Inventory = inventory, d_LocalPlayerPosition = w
            };
            w.d_Weapon = new WeaponRenderer()
            {
                d_Info = weapon, d_BlockRendererTorch = blockrenderertorch, d_LocalPlayerPosition = w
            };
            var playerrenderer = new CharacterRendererMonsterCode();

            playerrenderer.Load(new List <string>(MyStream.ReadAllLines(getfile.GetFile("player.mdc"))));
            w.d_CharacterRenderer = playerrenderer;
            particle = new ParticleEffectBlockBreak()
            {
                d_Data = gamedata, d_Map = clientgame, d_Terrain = terrainTextures
            };
            w.particleEffectBlockBreak = particle;
            w.ENABLE_FINITEINVENTORY   = false;
            w.d_Shadows       = w;
            clientgame.d_Data = gamedata;
            clientgame.d_CraftingTableTool = new CraftingTableTool()
            {
                d_Map = mapstorage
            };
            clientgame.d_Audio       = audio;
            clientgame.d_RailMapUtil = new RailMapUtil()
            {
                d_Data = gamedata, d_MapStorage = clientgame
            };
            clientgame.d_MinecartRenderer = new MinecartRenderer()
            {
                d_GetFile = getfile, d_The3d = the3d
            };
            clientgame.d_TerrainTextures = terrainTextures;
            clientgame.d_GetFile         = getfile;
            var craftingrecipes = new CraftingRecipes();

            craftingrecipes.data      = gamedata;
            w.d_CraftingRecipes       = craftingrecipes;
            network.d_CraftingRecipes = craftingrecipes;
            w.Reset(10 * 1000, 10 * 1000, 128);
            clientgame.d_Map = map;
            PlayerSkinDownloader playerskindownloader = new PlayerSkinDownloader();

            playerskindownloader.d_Exit     = exit;
            playerskindownloader.d_The3d    = the3d;
            playerskindownloader.skinserver = "http://fragmer.net/md/skins/";
            w.playerskindownloader          = playerskindownloader;
            w.d_FpsHistoryGraphRenderer     = new HudFpsHistoryGraphRenderer()
            {
                d_Draw = the3d, d_ViewportSize = w
            };
            w.d_Screenshot = new Screenshot()
            {
                d_GameWindow = maingamewindow
            };
            w.d_FrustumCulling   = frustumculling;
            physics.d_Map        = clientgame.mapforphysics;
            physics.d_Data       = gamedata;
            audio.d_GetFile      = getfile;
            audio.d_GameExit     = exit;
            this.map             = map;
            the3d.d_Terrain      = terrainTextures;
            the3d.d_TextRenderer = textrenderer;
            w.d_CurrentShadows   = this;
            var sunmoonrenderer = new SunMoonRenderer()
            {
                d_Draw2d = the3d, d_LocalPlayerPosition = w, d_GetFile = getfile, d_The3d = the3d
            };

            w.d_SunMoonRenderer          = sunmoonrenderer;
            clientgame.d_SunMoonRenderer = sunmoonrenderer;
            this.heightmap = new InfiniteMapChunked2d()
            {
                d_Map = map
            };
            heightmap.Restart();
            network.d_Heightmap = heightmap;
            this.light          = new InfiniteMapChunkedSimple()
            {
                d_Map = map
            };
            light.Restart();
            this.terrainchunktesselator      = terrainchunktesselator;
            w.d_TerrainChunkTesselator       = terrainchunktesselator;
            terrainchunktesselator.d_Shadows = w;
            if (fullshadows)
            {
                UseShadowsFull();
            }
            else
            {
                UseShadowsSimple();
            }
            w.d_HudChat = new ManicDigger.Gui.HudChat()
            {
                d_Draw2d = the3d, d_ViewportSize = w
            };

            var dataItems = new GameDataItemsBlocks()
            {
                d_Data = gamedata
            };
            var inventoryController = clientgame;
            var inventoryUtil       = new InventoryUtil();
            var hudInventory        = new HudInventory();

            hudInventory.dataItems      = dataItems;
            hudInventory.inventory      = inventory;
            hudInventory.inventoryUtil  = inventoryUtil;
            hudInventory.controller     = inventoryController;
            hudInventory.viewport_size  = w;
            hudInventory.mouse_current  = w;
            hudInventory.the3d          = the3d;
            hudInventory.getfile        = getfile;
            hudInventory.ActiveMaterial = w;
            hudInventory.viewport3d     = w;
            w.d_Inventory             = inventory;
            w.d_InventoryController   = inventoryController;
            w.d_InventoryUtil         = inventoryUtil;
            inventoryUtil.d_Inventory = inventory;
            inventoryUtil.d_Items     = dataItems;

            clientgame.d_Inventory = inventory;
            w.d_HudInventory       = hudInventory;
            if (Debugger.IsAttached)
            {
                new DependencyChecker(typeof(InjectAttribute)).CheckDependencies(
                    w, audio, gamedata, clientgame, network, mapstorage, getfile,
                    config3d, mapManipulator, w, the3d, exit,
                    localplayerposition, physics,
                    internetgamefactory, blockrenderertorch, playerrenderer,
                    map, terrainchunktesselator);
            }
        }
Esempio n. 14
0
    public void Update(Vector3 viewerPositon, bool isStillVisible, Vector3 positionA, float newScale)
    {
        //pokud uživatel změnil nějaká data, tak uzel musí přepočítat svoji novou pozici
        if (positionA != position)
        {
            scale    = newScale;
            position = positionA;
            Vector3 newPosition = CalculePositionOfSphere(positionA);
            bounds.center = newPosition;
            bounds.size   = (new Vector3(1, 1, 1) - newPosition.normalized) * scale;
            RecalculSteps();

            positionToDraw = new Vector4((position.x), (position.y), (position.z), scale);
        }

        //test nu frustum culling
        if (isStillVisible)
        {
            isVisible = FrustumCulling.Frustum(camera, bounds.center, scale * 0.5f, bounds);
        }

        if (!isVisible)
        {
            return;
        }
        //Vypočet vzdálenosti pozorovatele s jebližší bodem na bounding boxu
        var dist = Vector3.Distance(viewerPositon, bounds.ClosestPoint(viewerPositon));

        if (parentChunk != null)
        {
            var distParent = Vector3.Distance(viewerPositon, parentChunk.GetBounds().ClosestPoint(viewerPositon));

            //Zde pokud podmínka plati tak se provede merge---- takzvane se odstrani všichni potomci
            if (distParent / 2 > parentChunk.GetScale())
            {
                parentChunk.MergeChunk();
                return;
            }
        }
        //aktualizace uzlu
        if (chunkTree != null)
        {
            int i = 0;
            foreach (var item in chunkTree)
            {
                item.Update(viewerPositon, isVisible, steps[i], scale * 0.5f);
                i++;
            }
        }
        //Uzel si vytvoří 4 poduzly
        else if (scale * 2 > dist)
        {
            SubDivide(viewerPositon);
        }
        // Finalista na vykresleni
        else
        {
            isVisible = FrustumCulling.horizont(camera, bounds.center);
        }

        return;
    }