示例#1
0
        public override void Build()
        {
            Destination.Resize(Width, Height);

            var model = new SphereModel(Source);

            double longitude_extent = EasternLongitudinalBound - WesternLongitudinalBound;
            double latitude_extent  = NorthernLatitudinalBound - SouthernLatitudinalBound;
            double xdelta           = longitude_extent / (double)Width;
            double ydelta           = latitude_extent / (double)Height;
            double curr_longitude   = WesternLongitudinalBound;
            double curr_latitude    = SouthernLatitudinalBound;

            for (int y = 0; y < Height; ++y)
            {
                curr_longitude = WesternLongitudinalBound;
                for (int x = 0; x < Width; ++x)
                {
                    double value = model[curr_latitude, curr_longitude];
                    Destination[x, y] = value;
                    curr_longitude   += xdelta;
                }
                curr_latitude += ydelta;
            }
        }
示例#2
0
        /// <summary>
        ///     Se llama cada vez que hay que refrescar la pantalla.
        ///     Escribir aquí todo el código referido al renderizado.
        /// </summary>
        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.SetRenderTarget(RenderTarget);
            GraphicsDevice.Clear(Color.CornflowerBlue);

            SphereModel.Draw(LavaSphereWorld, Camera.View, Camera.Projection, LavaTexture);
            SphereModel.Draw(WaterSphereWorld, Camera.View, Camera.Projection, WaterTexture);
            SphereModel.Draw(RockSphereWorld, Camera.View, Camera.Projection, RockTexture);
            FloorQuad.Draw(FloorWorld, Camera.View, Camera.Projection, FloorTexture);

            DrawRobot();

            if (LightingEnabled)
            {
                LightCube.Draw(Matrix.CreateTranslation(LightOnePosition), Camera.View, Camera.Projection, Color.Red);
                LightCube.Draw(Matrix.CreateTranslation(LightTwoPosition), Camera.View, Camera.Projection, Color.Blue);
            }

            GraphicsDevice.SetRenderTarget(null);
            GraphicsDevice.Clear(Color.Black);

            Effect.CurrentTechnique = Effect.Techniques["PostProcessing"];
            Effect.Parameters["ModelTexture"].SetValue(RenderTarget);
            FullScreenQuad.Draw(Effect);



            base.Draw(gameTime);
        }
        public void Shutdown()
        {
            // Release the light object.
            Light  = null;
            Light2 = null;
            // Release the camera object.
            Camera = null;

            // Release the second render to texture object.
            RenderTexture2?.Shutdown();
            RenderTexture2 = null;
            // Release the shadow shader object.
            ShadowShader?.ShutDown();
            ShadowShader = null;
            // Release the depth shader object.
            DepthShader?.ShutDown();
            DepthShader = null;
            /// Release the render to texture object.
            RenderTexture?.Shutdown();
            RenderTexture = null;
            // Release the ground model object.
            GroundModel?.Shutdown();
            GroundModel = null;
            // Release the sphere model object.
            SphereModel?.Shutdown();
            SphereModel = null;
            // Release the cube model object.
            CubeModel?.Shutdown();
            CubeModel = null;
            // Release the Direct3D object.
            D3D?.ShutDown();
            D3D = null;
        }
        public void OnAwake()
        {
            var         SphereData = Data.SphereData;
            GameObject  instance   = GameObject.Instantiate(SphereData.SphereStruct.Prefab);
            SphereModel Sphere     = new SphereModel(instance, SphereData);

            _context._sphereModel = Sphere;
        }
示例#5
0
        public override GeometryModel CreateSourceGeometryModel()
        {
            SphereModel sphere = new SphereModel();

            sphere.Radius = this.radius.ChangeUnit(Parent.Parent.Environment.DefaultLengthUnit);

            //Set the matrix
            sphere.CenterVector3 = this.center.GetDirectXVector(Parent.Parent.Environment.DefaultLengthUnit);
            sphere.WorldMatrix   = Matrix.Translation(sphere.CenterVector3);

            return(sphere);
        }
示例#6
0
        public MainViewModel()
        {
            //ModelBase m = new Extruded();
            //ModelBase m = new Revolved();
            //ModelBase m = new BoxModel();
            //ModelBase m = new СylinderModel();
            ModelBase m = new SphereModel();

            m.Update();

            VisualiseModel(m);
        }
示例#7
0
        public static SphereModel Map(BLLProgrammer_Sphere Programmer_Spheres)
        {
            var mvcSpheres = new List <MvcSphere>();
            var res        = new SphereModel()
            {
                ProgId = Programmer_Spheres.IdProgrammer,
            };

            foreach (var item in Programmer_Spheres.Spheres)
            {
                res.Spheres.Add(GetMVCEntity(item));
            }
            return(res);
        }
示例#8
0
        protected override void OnInitialize()
        {
            SphereModel sphere = new SphereModel(_coder, SPHERE_BREAKUPS);

            GlProgram wProgram = new GlProgram(
                new Shader(ShaderTypes.Vertex, File.ReadAllText(Path.Combine(SHADERS_DIR, WORLD_SHADERS, "vertex.glsl"))),
                new Shader(ShaderTypes.Fragment, File.ReadAllText(Path.Combine(SHADERS_DIR, WORLD_SHADERS, "fragment.glsl")))
                );

            GlProgram gProgram = new GlProgram(
                new Shader(ShaderTypes.Vertex, File.ReadAllText(Path.Combine(SHADERS_DIR, GUI_SHADERS, "vertex.glsl"))),
                new Shader(ShaderTypes.Fragment, File.ReadAllText(Path.Combine(SHADERS_DIR, GUI_SHADERS, "fragment.glsl")))
                );

            _universe.Add(new SpaceObject(2, 100000, sphere)
            {
                Position = new Vector3(0, 0, 0)
            });
            _universe.Add(new SpaceObject(8, 50, sphere)
            {
                Position = new Vector3(-500, -500, 0), Velocity = new Vector3(30f, 0, -5f)
            });
            _universe.Add(new SpaceObject(0, 250, sphere)
            {
                Position = new Vector3(500, -500, 0), Velocity = new Vector3(30f, 0, 5f)
            });
            _universe.Add(_rocket = new RocketObject(55, new RocketModel(_coder))
            {
                Position = new Vector3(500, 500, 500), Velocity = new Vector3(-30f, 0f, 0f)
            });

            RenderHandle handle = new RenderHandle(this, wProgram);

            _layer = new SceneLayer(_universe, handle);
            AddLayer(_layer);
            _cam = new OrbitalCamera(_layer.Camera)
            {
                Distance = 250
            };
            Font fnt = new Font(Path.Combine(ASSETS_DIR, FONT_DIR, FONT_FILE));

            AddLayer(new GuiFuelLayer(_rocket, this, gProgram, new GuiVertexCoder(), fnt));
            GuiLayer tutorial = new GuiLayer(this, gProgram, new GuiVertexCoder(), fnt);

            tutorial.Add(_tutorialLbl);
            AddLayer(tutorial);
            Background = new Color(50, 50, 50, 255);
            base.OnInitialize();
        }
示例#9
0
        /// <summary>
        ///     Libero los recursos que se cargaron en el juego.
        /// </summary>
        protected override void UnloadContent()
        {
            // Libero los recursos.
            Content.Unload();

            FloorQuad.Dispose();
            SphereModel.Dispose();
            FullScreenQuad.Dispose();

            if (LightingEnabled)
            {
                LightCube.Dispose();
            }
            base.UnloadContent();
        }
示例#10
0
        private void OnTriggerEnter(Collider other)
        {
            SphereModel sphereModel = other.GetComponent <SphereModel>();

            if (sphereModel == null)
            {
                return;
            }

            if (_timeOut > Time.realtimeSinceStartup - _lastAnimationTime && _activated)
            {
                return;
            }
            _activated         = true;
            _lastAnimationTime = Time.realtimeSinceStartup;
            _animatorController.SetBool(GATE_PARAMETER, true);
        }
示例#11
0
        /// <summary>
        /// Create the primitives to be drawed
        /// </summary>
        public override void Initialize()
        {
            if (sphereMesh != null)
            {
                sphereMesh.Dispose();
            }

            model = source as SphereModel;

            //Create the mesh
            sphereMesh = new AutoMesh(d3d, Mesh.Sphere(d3d.Dx, model.Radius, Direct3dRender.DefaultSlices, Direct3dRender.DefaultStacks));

            //Get the bounding box
            sphereMesh.BoundingBox(out minVector3, out maxVector3);

            minVector3.TransformCoordinate(model.WorldMatrix);
            maxVector3.TransformCoordinate(model.WorldMatrix);

            model.MinVector3 = minVector3;
            model.MaxVector3 = maxVector3;
        }
示例#12
0
        public void Shutdown()
        {
            // Release the light object.
            Light = null;
            // Release the camera object.
            Camera = null;

            // Release the soft shadow shader object.
            SoftShadowShader?.ShutDown();
            SoftShadowShader = null;
            // Release the full screen ortho window object.
            FullScreenWindow?.Shutdown();
            FullScreenWindow = null;
            // Release the up sample render to texture object.
            UpSampleTexure?.Shutdown();
            UpSampleTexure = null;
            // Release the vertical blur shader object.
            VerticalBlurShader?.ShutDown();
            VerticalBlurShader = null;
            // Release the vertical blur render to texture object.
            VerticalBlurTexture?.Shutdown();
            VerticalBlurTexture = null;
            // Release the horizontal blur shader object.
            HorizontalBlurShader?.ShutDown();
            HorizontalBlurShader = null;
            // Release the horizontal blur render to texture object.
            HorizontalBlurTexture?.Shutdown();
            HorizontalBlurTexture = null;
            // Release the texture shader object.
            TextureShader?.ShutDown();
            TextureShader = null;
            // Release the small ortho window object.
            SmallWindow?.Shutdown();
            SmallWindow = null;
            // Release the down sample render to texture object.
            DownSampleTexure?.Shutdown();
            DownSampleTexure = null;
            // Release the shadow shader object.
            ShadowShader?.ShutDown();
            ShadowShader = null;
            // Release the black and white render to texture.
            BlackWhiteRenderTexture?.Shutdown();
            BlackWhiteRenderTexture = null;
            // Release the depth shader object.
            DepthShader?.ShutDown();
            DepthShader = null;
            /// Release the render to texture object.
            RenderTexture?.Shutdown();
            RenderTexture = null;
            // Release the ground model object.
            GroundModel?.Shutdown();
            GroundModel = null;
            // Release the sphere model object.
            SphereModel?.Shutdown();
            SphereModel = null;
            // Release the cube model object.
            CubeModel?.Shutdown();
            CubeModel = null;
            // Release the Direct3D object.
            D3D?.ShutDown();
            D3D = null;
        }
示例#13
0
 public override IModel Create(float radius)
 {
     return(SphereModel.GetModel(radius));
 }
示例#14
0
 /// <summary>
 /// Clean up any resources being used.
 /// </summary>
 protected override void PerformDispose( )
 {
     sphereMesh.Dispose( );
     model = null;
 }
示例#15
0
        private bool RenderBlackAndWhiteShadows()
        {
            // Set the render target to be the render to texture.
            BlackWhiteRenderTexture.SetRenderTarget(D3D.DeviceContext);

            // Clear the render to texture.
            BlackWhiteRenderTexture.ClearRenderTarget(D3D.DeviceContext, 0.0f, 0.0f, 0.0f, 1.0f);

            // Generate the view matrix based on the camera's position.
            Camera.Render();

            // Generate the light view matrix based on the light's position.
            Light.GenerateViewMatrix();

            // Get the world, view, and projection matrices from the camera and d3d objects.
            Matrix cameraViewMatrix = Camera.ViewMatrix;
            Matrix worldMatrix      = D3D.WorldMatrix;
            Matrix projectionMatrix = D3D.ProjectionMatrix;

            // Get the light's view and projection matrices from the light object.
            Matrix lightViewMatrix       = Light.ViewMatrix;
            Matrix lightProjectionMatrix = Light.ProjectionMatrix;

            // Setup the translation matrix for the cube model.
            Vector3 cubePosition = CubeModel.GetPosition();

            Matrix.Translation(cubePosition.X, cubePosition.Y, cubePosition.Z, out worldMatrix);

            // Render the cube model using the shadow shader.
            CubeModel.Render(D3D.DeviceContext);
            if (!ShadowShader.Render(D3D.DeviceContext, CubeModel.IndexCount, worldMatrix, cameraViewMatrix, projectionMatrix, lightViewMatrix, lightProjectionMatrix, RenderTexture.ShaderResourceView, Light.Position))
            {
                return(false);
            }

            // Reset the world matrix.
            worldMatrix = D3D.WorldMatrix;

            // Setup the translation matrix for the sphere model.
            Vector3 spherePosition = SphereModel.GetPosition();

            Matrix.Translation(spherePosition.X, spherePosition.Y, spherePosition.Z, out worldMatrix);

            // Render the sphere model using the shadow shader.
            SphereModel.Render(D3D.DeviceContext);
            if (!ShadowShader.Render(D3D.DeviceContext, SphereModel.IndexCount, worldMatrix, cameraViewMatrix, projectionMatrix, lightViewMatrix, lightProjectionMatrix, RenderTexture.ShaderResourceView, Light.Position))
            {
                return(false);
            }

            // Reset the world matrix.
            worldMatrix = D3D.WorldMatrix;

            // Setup the translation matrix for the ground model.
            Vector3 groundPosition = GroundModel.GetPosition();

            Matrix.Translation(groundPosition.X, groundPosition.Y, groundPosition.Z, out worldMatrix);

            // Render the ground model using the shadow shader.
            GroundModel.Render(D3D.DeviceContext);
            if (!ShadowShader.Render(D3D.DeviceContext, SphereModel.IndexCount, worldMatrix, cameraViewMatrix, projectionMatrix, lightViewMatrix, lightProjectionMatrix, RenderTexture.ShaderResourceView, Light.Position))
            {
                return(false);
            }

            // Reset the render target back to the original back buffer and not the render to texture anymore.
            D3D.SetBackBufferRenderTarget();

            // Reset the viewport back to the original.
            D3D.ResetViewPort();

            return(true);
        }
示例#16
0
 /// <summary>
 /// 一个球体的模型。
 /// </summary>
 /// <param name="radius"></param>
 /// <param name="latitudeParts">用纬线把地球切割为几块。</param>
 /// <param name="longitudeParts">用经线把地球切割为几块。</param>
 public Sphere(float radius = 1.0f, int latitudeParts = 10, int longitudeParts = 40)
 {
     this.model   = new SphereModel(radius, latitudeParts, longitudeParts);
     this.Lengths = new vec3(radius * 2, radius * 2, radius * 2);
 }
        public bool Render()
        {
            // First render the scene to a texture.
            if (!RenderSceneToTexture())
            {
                return(false);
            }

            // Render the scene to texture again but use the second light's view point.
            if (!RenderSceneToTexture2())
            {
                return(false);
            }

            // Clear the buffers to begin the scene.
            D3D.BeginScene(0.0f, 0.0f, 0.0f, 1.0f);

            // Generate the view matrix based on the camera's position.
            Camera.Render();

            // Generate the light view matrix based on the light's position.
            Light.GenerateViewMatrix();

            // Do the same for the second light.
            Light2.GenerateViewMatrix();

            // Get the world, view, and projection matrices from the camera and d3d objects.
            Matrix viewMatrix       = Camera.ViewMatrix;
            Matrix worldMatrix      = D3D.WorldMatrix;
            Matrix projectionMatrix = D3D.ProjectionMatrix;

            // Get the light's view and projection matrices from the light object.
            Matrix lightViewMatrix       = Light.ViewMatrix;
            Matrix lightProjectionMatrix = Light.ProjectionMatrix;

            // Do the same for the second light.
            Matrix lightViewMatrix2       = Light2.ViewMatrix;
            Matrix lightProjectionMatrix2 = Light2.ProjectionMatrix;

            // Setup the translation matrix for the cube model.
            Vector3 cubePosition = CubeModel.GetPosition();

            Matrix.Translation(cubePosition.X, cubePosition.Y, cubePosition.Z, out worldMatrix);

            // Put the cube model vertex and index buffers on the graphics pipeline to prepare them for drawing.
            CubeModel.Render(D3D.DeviceContext);

            // Render the model using the shadow shader.
            if (!ShadowShader.Render(D3D.DeviceContext, CubeModel.IndexCount, worldMatrix, viewMatrix, projectionMatrix, lightViewMatrix, lightProjectionMatrix, CubeModel.Texture.TextureResource, RenderTexture.ShaderResourceView, Light.Position, Light.AmbientColor, Light.DiffuseColour, lightViewMatrix2, lightProjectionMatrix2, RenderTexture2.ShaderResourceView, Light2.Position, Light2.DiffuseColour))
            {
                return(false);
            }

            // Reset the world matrix.
            worldMatrix = D3D.WorldMatrix;

            // Setup the translation matrix for the sphere model.
            Vector3 spherePosition = SphereModel.GetPosition();

            Matrix.Translation(spherePosition.X, spherePosition.Y, spherePosition.Z, out worldMatrix);

            // Put the model vertex and index buffers on the graphics pipeline to prepare them for drawing.
            SphereModel.Render(D3D.DeviceContext);
            if (!ShadowShader.Render(D3D.DeviceContext, SphereModel.IndexCount, worldMatrix, viewMatrix, projectionMatrix, lightViewMatrix, lightProjectionMatrix, SphereModel.Texture.TextureResource, RenderTexture.ShaderResourceView, Light.Position, Light.AmbientColor, Light.DiffuseColour, lightViewMatrix2, lightProjectionMatrix2, RenderTexture2.ShaderResourceView, Light2.Position, Light2.DiffuseColour))
            {
                return(false);
            }

            // Reset the world matrix.
            worldMatrix = D3D.WorldMatrix;

            // Setup the translation matrix for the ground model.
            Vector3 groundPosition = GroundModel.GetPosition();

            Matrix.Translation(groundPosition.X, groundPosition.Y, groundPosition.Z, out worldMatrix);

            // Render the ground model using the shadow shader.
            GroundModel.Render(D3D.DeviceContext);
            if (!ShadowShader.Render(D3D.DeviceContext, GroundModel.IndexCount, worldMatrix, viewMatrix, projectionMatrix, lightViewMatrix, lightProjectionMatrix, GroundModel.Texture.TextureResource, RenderTexture.ShaderResourceView, Light.Position, Light.AmbientColor, Light.DiffuseColour, lightViewMatrix2, lightProjectionMatrix2, RenderTexture2.ShaderResourceView, Light2.Position, Light2.DiffuseColour))
            {
                return(false);
            }

            // Present the rendered scene to the screen.
            D3D.EndScene();

            return(true);
        }
        private bool RenderSceneToTexture2()
        {
            // Set the render target to be the render to texture.
            RenderTexture2.SetRenderTarget(D3D.DeviceContext);

            // Clear the render to texture.
            RenderTexture2.ClearRenderTarget(D3D.DeviceContext, 0.0f, 0.0f, 0.0f, 1.0f);

            // Generate the light view matrix based on the light's position.
            Light2.GenerateViewMatrix();

            // Get the world matrix from the d3d object.
            Matrix worldMareix = D3D.WorldMatrix;

            // Get the view and orthographic matrices from the light object.
            Matrix lightViewMatrix  = Light2.ViewMatrix;
            Matrix lightOrthoMatrix = Light2.ProjectionMatrix;

            // Setup the translation matrix for the cube model.
            Vector3 cubePosition = CubeModel.GetPosition();

            Matrix.Translation(cubePosition.X, cubePosition.Y, cubePosition.Z, out worldMareix);

            // Render the cube model with the depth shader.
            CubeModel.Render(D3D.DeviceContext);
            if (!DepthShader.Render(D3D.DeviceContext, CubeModel.IndexCount, worldMareix, lightViewMatrix, lightOrthoMatrix))
            {
                return(false);
            }

            // Reset the world matrix.
            worldMareix = D3D.WorldMatrix;

            // Setup the translation matrix for the sphere model.
            Vector3 spherePosition = SphereModel.GetPosition();

            Matrix.Translation(spherePosition.X, spherePosition.Y, spherePosition.Z, out worldMareix);

            // Render the sphere model with the depth shader.
            SphereModel.Render(D3D.DeviceContext);
            if (!DepthShader.Render(D3D.DeviceContext, SphereModel.IndexCount, worldMareix, lightViewMatrix, lightOrthoMatrix))
            {
                return(false);
            }

            // Reset the world matrix.
            worldMareix = D3D.WorldMatrix;

            // Setup the translation matrix for the ground model.
            Vector3 groundPosition = GroundModel.GetPosition();

            Matrix.Translation(groundPosition.X, groundPosition.Y, groundPosition.Z, out worldMareix);

            // Render the ground model with the depth shader.
            GroundModel.Render(D3D.DeviceContext);
            if (!DepthShader.Render(D3D.DeviceContext, GroundModel.IndexCount, worldMareix, lightViewMatrix, lightOrthoMatrix))
            {
                return(false);
            }

            // Reset the render target back to the original back buffer and not the render to texture anymore.
            D3D.SetBackBufferRenderTarget();

            // Reset the viewport back to the original.
            D3D.ResetViewPort();

            return(true);
        }
示例#19
0
        public bool Render()
        {
            // First render the scene to a texture.
            if (!RenderSceneToTexture())
            {
                return(false);
            }

            // Next render the shadowed scene in black and white.
            if (!RenderBlackAndWhiteShadows())
            {
                return(false);
            }

            // Then down sample the black and white scene texture.
            if (!DownSampleTexture())
            {
                return(false);
            }

            // Perform a horizontal blur on the down sampled texture.
            if (!RenderHorizontalBlurToTexture())
            {
                return(false);
            }

            // Now perform a vertical blur on the texture.
            if (!RenderVerticalBlurToTexture())
            {
                return(false);
            }

            // Finally up sample the final blurred render to texture that can now be used in the soft shadow shader.
            if (!UpSampleTexture())
            {
                return(false);
            }

            // Clear the buffers to begin the scene.
            D3D.BeginScene(0.0f, 0.0f, 0.0f, 1.0f);

            // Generate the view matrix based on the camera's position.
            Camera.Render();

            // Get the world, view, and projection matrices from the camera and d3d objects.
            Matrix viewMatrix       = Camera.ViewMatrix;
            Matrix worldMatrix      = D3D.WorldMatrix;
            Matrix projectionMatrix = D3D.ProjectionMatrix;

            // Setup the translation matrix for the cube model.
            Vector3 cubePosition = CubeModel.GetPosition();

            Matrix.Translation(cubePosition.X, cubePosition.Y, cubePosition.Z, out worldMatrix);

            // Render the cube model using the soft shadow shader.
            CubeModel.Render(D3D.DeviceContext);
            if (!SoftShadowShader.Render(D3D.DeviceContext, CubeModel.IndexCount, worldMatrix, viewMatrix, projectionMatrix, CubeModel.Texture.TextureResource, UpSampleTexure.ShaderResourceView, Light.Position, Light.AmbientColor, Light.DiffuseColour))
            {
                return(false);
            }

            // Reset the world matrix.
            worldMatrix = D3D.WorldMatrix;

            // Setup the translation matrix for the sphere model.
            Vector3 spherePosition = SphereModel.GetPosition();

            Matrix.Translation(spherePosition.X, spherePosition.Y, spherePosition.Z, out worldMatrix);

            // Render the sphere model using the soft shadow shader.
            SphereModel.Render(D3D.DeviceContext);
            if (!SoftShadowShader.Render(D3D.DeviceContext, SphereModel.IndexCount, worldMatrix, viewMatrix, projectionMatrix, SphereModel.Texture.TextureResource, UpSampleTexure.ShaderResourceView, Light.Position, Light.AmbientColor, Light.DiffuseColour))
            {
                return(false);
            }

            // Reset the world matrix.
            worldMatrix = D3D.WorldMatrix;

            // Setup the translation matrix for the ground model.
            Vector3 groundPosition = GroundModel.GetPosition();

            Matrix.Translation(groundPosition.X, groundPosition.Y, groundPosition.Z, out worldMatrix);

            // Render the ground model using the shadow shader.
            GroundModel.Render(D3D.DeviceContext);
            if (!SoftShadowShader.Render(D3D.DeviceContext, GroundModel.IndexCount, worldMatrix, viewMatrix, projectionMatrix, GroundModel.Texture.TextureResource, UpSampleTexure.ShaderResourceView, Light.Position, Light.AmbientColor, Light.DiffuseColour))
            {
                return(false);
            }

            // Present the rendered scene to the screen.
            D3D.EndScene();

            return(true);
        }