Ejemplo n.º 1
0
        /// <summary>
        /// Function to update the world matrix for the mesh for AABB calculations.
        /// </summary>
        /// <param name="mesh">The mesh to update.</param>
        private void UpdateMeshWorldMatrix(MoveableMesh mesh)
        {
            DX.Vector2 position    = (DX.Vector2)mesh.Position + Offset;
            DX.Vector2 transformed = position;

            mesh.Position = new DX.Vector3(transformed / ParallaxLevel, mesh.Position.Z);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Function to update the entity during a frame.
        /// </summary>
        public void Update()
        {
            float depth = _position.Z;

            for (int meshIndex = 0; meshIndex < Layers.Count; ++meshIndex)
            {
                MeshAnimationController controller = _animController[meshIndex];
                MoveableMesh            mesh       = Layers[meshIndex].Mesh;
                IGorgonAnimation        animation  = Layers[meshIndex].Animation;

                if (animation == null)
                {
                    mesh.Rotation = Rotation;
                }

                mesh.Position = new DX.Vector3(_position.X, _position.Y, depth);
                mesh.Rotation = Rotation;

                if ((animation != null) && (controller.State != AnimationState.Playing))
                {
                    controller.Play(mesh, animation);
                }

                controller.Update();
                // Increase the depth of the mesh so that we
                depth -= 0.02f;
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Function to update the material on the shader for the specified mesh.
        /// </summary>
        /// <param name="mesh">The mesh to evaluate.</param>
        private void UpdateMaterial(MoveableMesh mesh)
        {
            // Send the material data over to the shader.
            var materialData = new Material
            {
                Albedo        = mesh.Material.Albedo,
                UVOffset      = mesh.Material.TextureOffset,
                SpecularPower = mesh.Material.SpecularPower
            };

            _materialBuffer.Buffer.SetData(ref materialData);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Function to render the layer data.
        /// </summary>
        public override void Render()
        {
            int drawCallIndex = 0;

            if (_drawPlanets.Count == 0)
            {
                return;
            }

            // Apply active lights
            Array.Clear(_lightData, 0, _lightData.Length);
            for (int i = 0; i < ActiveLights.Count.Min(_lightData.Length); ++i)
            {
                Light light = ActiveLights[i];

                if (light == null)
                {
                    continue;
                }

                _lightData[i] = new LightData
                {
                    SpecularPower = light.SpecularPower,
                    Attenuation   = light.Attenuation,
                    LightColor    = light.Color,
                    LightPosition = new DX.Vector3(light.Position.X, light.Position.Y, -light.Position.Z),
                    SpecularColor = GorgonColor.White,
                    Intensity     = light.Intensity
                };
            }

            if (ActiveLights.Count > 0)
            {
                _lightBuffer.Buffer.SetData(_lightData);
            }

            for (int i = 0; i < _drawPlanets.Count; ++i)
            {
                Planet planet = _drawPlanets[i];
                for (int j = 0; j < planet.Layers.Count; ++j)
                {
                    PlanetaryLayer layer = planet.Layers[j];
                    MoveableMesh   mesh  = layer.Mesh;

                    UpdateMaterial(mesh);
                    UpdateWorldTransform(mesh);

                    _graphics.Submit(_drawCalls[drawCallIndex++]);
                }
            }
        }
Ejemplo n.º 5
0
 /// <summary>
 /// Function to send the current world matrix for a mesh to the shader.
 /// </summary>
 /// <param name="mesh">The mesh containing the world matrix.</param>
 private void UpdateWorldTransform(MoveableMesh mesh)
 {
     UpdateMeshWorldMatrix(mesh);
     _worldBuffer.Buffer.SetData(ref mesh.WorldMatrix);
 }
Ejemplo n.º 6
0
 /// <summary>Initializes a new instance of the <see cref="T:Gorgon.Examples.PlanetaryLayer"/> class.</summary>
 /// <param name="mesh">The mesh.</param>
 public PlanetaryLayer(MoveableMesh mesh)
 {
     Mesh = mesh;
 }