Exemplo n.º 1
0
        /// <summary>
        /// Metoda vyrenderuje kolizni mapu
        /// </summary>
        /// <remarks>Metoda predpoklada, ze bude volana po testech, ktere provadi metoda Render, proto je doporucovano volat ji z metody Render</remarks>
        /// <param name="time">Cas uplynuly od spusteni aplikace v milisekundach</param>
        /// <seealso cref="Render"/>
        private void RenderCollisionMap(float time)
        {
            Matrix view = CameraDriver.GetTerainViewMatrix(new Vector3(0, 5000, 0), new Vector3(0, 0, 1));
            Matrix proj = CameraDriver.GetTerainOrthoProjectionMatrix();

            collisionMap.BeginScene();
            device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.White, 1.0f, 0);

            IRenderable terrain = (IRenderable)CameraDriver.GetAttachedTerain();

            if (terrain != null)
            {
                terrain.SetVisible(false);
            }

            List <Scene.SceneManager.SceneObject> objects = sceneManager.GetObjectsOfType(Type.GetType("WiccanRede.Objects.Building"), false);

            sceneManager.BeginRenderObject(time, sceneManager[null], view, proj);

            foreach (Scene.SceneManager.SceneObject obj in objects)
            {
                sceneManager.RenderObject(obj.generalObject);
            }

            sceneManager.EndRenderObject();

            if (terrain != null)
            {
                terrain.SetVisible(true);
            }

            if (terrain != null)
            {
                sceneManager.SetComputeVisibility(false);
                terrain.ResetVisibility();

                sceneManager.BeginRenderObject(time, sceneManager["TerrainCollission"], view, proj);
                sceneManager.RenderObject(terrain);
                sceneManager.EndRenderObject();

                sceneManager.SetComputeVisibility(true);
            }

            collisionMap.EndScene(Filter.Point);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Metoda nacte vsechny zdroje, mela by byt volana pouze jednou po inicializaci
        /// </summary>
        public void ResourcesLoad()
        {
            Logger.AddInfo("Nacitani resourcu");

            LoadSceneFromXml(@"Resources/data.xml");
            terrain = (WiccanRede.Objects.Terrain)CameraDriver.GetAttachedTerain();
            InitDetails();

            Logger.AddInfo("Resources nacteny");
            if (occlusion == null)
            {
                occlusion = new OcclusionCulling(device, sceneManager);
            }

            cursorTexture     = TextureLoader.FromFile(device, @"Resources/Textures/cursor.dds");
            this.cursorSprite = new Sprite(device);

            hud = new HUD(device, form);
            hud.onResolutionChange();
        }
Exemplo n.º 3
0
        /// <summary>
        /// Funkce se postara o rendering cele sceny
        /// </summary>
        /// <param name="time">Cas uplynuly od spusteni aplikace v milisekundach</param>
        public void Render(float time)
        {
            sceneManager.ResetCounters();

            #region Rendering tests
            bool deviceLost = initializator.IsDeviceLost();
            if (deviceLost)
            {
                ResourceUnload();
            }

            if (!initializator.BeginRender())
            {
                return;
            }

            if (unloadResources)
            {
                DeviceReset();
                unloadResources = false;
            }
            #endregion

            #region Vyrenderovani kolizni mapy (1x)
            if (terrain != null && terrain.GetCollissionMap() == null)
            {
                RenderCollisionMap(0);
                terrain.SetCollissionMap(BitmapOperation.TextureToColorArray(collisionMap.GetTexture()), true);
            }
            #endregion

            #region Generovani shadow mapy podle prvniho svetla, existuje-li nejake

            if ((int)currentDetail >= 2)
            {
                List <SceneManager.SceneObject> lights = sceneManager.GetDirectionLights();

                if (lights.Count > 0)
                {
                    Vector4 moonPosition = lights[0].light.GetLightPosition();

                    Matrix view = CameraDriver.GetTerainViewMatrix(new Vector3(moonPosition.X, moonPosition.Y, moonPosition.Z));
                    Matrix OrthoProjectionMatrix = CameraDriver.GetTerainOrthoProjectionMatrix();
                    sceneManager.SetLightViewProjection(view * OrthoProjectionMatrix);
                    sceneManager.SetRenderShadowsNonEmitterObjects(false);
                    sceneManager.SetComputeVisibility(false);
                    shadowMap.BeginScene();
                    device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.White, 1f, 0);

                    if (enableshadows)
                    {
                        sceneManager.RenderSceneBasic(time, sceneManager["ShadowMap"]);
                    }
                    shadowMap.EndScene(Filter.Linear);
                    sceneManager.SetShadowMap(shadowMap.GetTexture());

                    sceneManager.SetRenderShadowsNonEmitterObjects(true);
                    sceneManager.SetComputeVisibility(true);
                }
            }

            #endregion

            #region Nastaveni optimalizace
            if (usedoptimize == OptimizeType.QuadTree)
            {
                sceneManager.SetComputeVisibility(true);
            }
            else if (usedoptimize == OptimizeType.OcclussionCulling)
            {
                occlusion.DoCulling();
                sceneManager.SetComputeVisibility(false);
            }
            #endregion

            device.BeginScene();

            sceneManager.RenderScene(time, sceneManager["Shadows"]);

            if (showBoundingSpheres)
            {
                sceneManager.RenderSceneBasic(time, sceneManager["Base"], true, false);
            }

            RenderHUD();

            device.EndScene();

            initializator.EndRender();
            CountFPS();
        }