diff --git a/ANX.Framework/Audio/NoAudioHardwareException.cs b/ANX.Framework/Audio/NoAudioHardwareException.cs index a2c42056..218e3cfd 100644 --- a/ANX.Framework/Audio/NoAudioHardwareException.cs +++ b/ANX.Framework/Audio/NoAudioHardwareException.cs @@ -9,7 +9,7 @@ using ANX.Framework.NonXNA.Development; namespace ANX.Framework.Audio { #if !WINDOWSMETRO //TODO: search replacement for Win8 - [SerializableAttribute] + [Serializable] #endif [PercentageComplete(99)] [Developer("AstrorEnales")] diff --git a/ANX.Framework/Audio/RendererDetail.cs b/ANX.Framework/Audio/RendererDetail.cs index 4110ef07..1a5b0168 100644 --- a/ANX.Framework/Audio/RendererDetail.cs +++ b/ANX.Framework/Audio/RendererDetail.cs @@ -49,13 +49,10 @@ namespace ANX.Framework.Audio #region Equality public override bool Equals(object obj) { - if (obj is RendererDetail) - return this == (RendererDetail)obj; - - return false; + return obj is RendererDetail && this == (RendererDetail)obj; } - public static bool operator ==(RendererDetail lhs, RendererDetail rhs) + public static bool operator ==(RendererDetail lhs, RendererDetail rhs) { return lhs.friendlyName.Equals(rhs.friendlyName) && lhs.rendererId.Equals(rhs.rendererId); diff --git a/ANX.Framework/CurveKey.cs b/ANX.Framework/CurveKey.cs index 38edf125..24e2bd63 100644 --- a/ANX.Framework/CurveKey.cs +++ b/ANX.Framework/CurveKey.cs @@ -1,4 +1,5 @@ using System; +using ANX.Framework.NonXNA.Development; // This file is part of the ANX.Framework created by the // "ANX.Framework developer group" and released under the Ms-PL license. @@ -6,6 +7,9 @@ using System; namespace ANX.Framework { + [PercentageComplete(100)] + [Developer("???")] + [TestState(TestStateAttribute.TestState.InProgress)] public class CurveKey : IEquatable, IComparable { #region Public diff --git a/ANX.Framework/Graphics/BasicEffect.cs b/ANX.Framework/Graphics/BasicEffect.cs index 2dfb5574..314c3345 100644 --- a/ANX.Framework/Graphics/BasicEffect.cs +++ b/ANX.Framework/Graphics/BasicEffect.cs @@ -9,7 +9,7 @@ using ANX.Framework.NonXNA.Development; namespace ANX.Framework.Graphics { [PercentageComplete(100)] - [TestState(TestStateAttribute.TestState.InProgress)] + [TestState(TestStateAttribute.TestState.Tested)] [Developer("AstrorEnales")] public class BasicEffect : Effect, IEffectMatrices, IEffectLights, IEffectFog { diff --git a/ANX.Framework/Input/GamePadThumbSticks.cs b/ANX.Framework/Input/GamePadThumbSticks.cs index 97e4a5a2..59d7c654 100644 --- a/ANX.Framework/Input/GamePadThumbSticks.cs +++ b/ANX.Framework/Input/GamePadThumbSticks.cs @@ -28,19 +28,16 @@ namespace ANX.Framework.Input public GamePadThumbSticks (Vector2 leftThumbstick, Vector2 rightThumbstick) { - this.left = Vector2.Clamp(leftThumbstick, -Vector2.One, Vector2.One); - this.right = Vector2.Clamp(rightThumbstick, -Vector2.One, Vector2.One); + left = Vector2.Clamp(leftThumbstick, -Vector2.One, Vector2.One); + right = Vector2.Clamp(rightThumbstick, -Vector2.One, Vector2.One); } public override bool Equals(object obj) { - if (obj != null && obj.GetType() == typeof(GamePadThumbSticks)) - return this == (GamePadThumbSticks)obj; - - return false; + return obj is GamePadThumbSticks && this == (GamePadThumbSticks)obj; } - public static bool operator ==(GamePadThumbSticks lhs, GamePadThumbSticks rhs) + public static bool operator ==(GamePadThumbSticks lhs, GamePadThumbSticks rhs) { return lhs.left == rhs.left && lhs.right == rhs.right; } @@ -52,7 +49,7 @@ namespace ANX.Framework.Input public override int GetHashCode() { - return this.left.GetHashCode() ^ this.right.GetHashCode(); + return left.GetHashCode() ^ right.GetHashCode(); } public override string ToString() diff --git a/ANX.Framework/Input/GamePadTriggers.cs b/ANX.Framework/Input/GamePadTriggers.cs index d3a2c199..10d9d176 100644 --- a/ANX.Framework/Input/GamePadTriggers.cs +++ b/ANX.Framework/Input/GamePadTriggers.cs @@ -33,13 +33,10 @@ namespace ANX.Framework.Input public override bool Equals(object obj) { - if (obj != null && obj.GetType() == typeof(GamePadTriggers)) - return this == (GamePadTriggers)obj; - - return false; + return obj is GamePadTriggers && this == (GamePadTriggers)obj; } - public static bool operator ==(GamePadTriggers lhs, GamePadTriggers rhs) + public static bool operator ==(GamePadTriggers lhs, GamePadTriggers rhs) { return lhs.Left == rhs.Left && lhs.Right == rhs.Right; } diff --git a/ANX.Framework/Input/KeyboardState.cs b/ANX.Framework/Input/KeyboardState.cs index 6f25a623..1309bc1e 100644 --- a/ANX.Framework/Input/KeyboardState.cs +++ b/ANX.Framework/Input/KeyboardState.cs @@ -13,18 +13,15 @@ namespace ANX.Framework.Input public struct KeyboardState { #region Private - private KeyState[] keyState; + private readonly KeyState[] keyState; #endregion - public KeyState this[Keys key] - { - get - { - return keyState[(int)key]; - } - } + public KeyState this[Keys key] + { + get { return keyState[(int)key]; } + } - public KeyboardState(params Keys[] keys) + public KeyboardState(params Keys[] keys) { keyState = new KeyState[255]; for (int i = 0; i < keys.Length; i++) @@ -48,13 +45,10 @@ namespace ANX.Framework.Input public override bool Equals(object obj) { - if (obj != null && obj.GetType() == typeof(KeyboardState)) - return this == (KeyboardState)obj; - - return false; + return obj is KeyboardState && this == (KeyboardState)obj; } - public static bool operator ==(KeyboardState lhs, KeyboardState rhs) + public static bool operator ==(KeyboardState lhs, KeyboardState rhs) { if (lhs.keyState.Length != rhs.keyState.Length) return false; diff --git a/ANX.Framework/TitleContainer.cs b/ANX.Framework/TitleContainer.cs index bedd5953..3c4b888d 100644 --- a/ANX.Framework/TitleContainer.cs +++ b/ANX.Framework/TitleContainer.cs @@ -1,5 +1,4 @@ using System.IO; -using ANX.Framework.NonXNA; using ANX.Framework.NonXNA.PlatformSystem; using ANX.Framework.NonXNA.Development; diff --git a/Samples/BasicEffectSample/BaseScene.cs b/Samples/BasicEffectSample/BaseScene.cs index d3f11104..f3a2c08b 100644 --- a/Samples/BasicEffectSample/BaseScene.cs +++ b/Samples/BasicEffectSample/BaseScene.cs @@ -1,4 +1,5 @@ using System; +using ANX.Framework; using ANX.Framework.Content; using ANX.Framework.Graphics; @@ -9,10 +10,56 @@ using ANX.Framework.Graphics; namespace BasicEffectSample { public abstract class BaseScene - { + { + protected BasicEffect effect; + protected VertexBuffer vertices; + protected IndexBuffer indices; + public abstract string Name { get; } + public abstract void Initialize(ContentManager content, GraphicsDevice graphicsDevice); public abstract void Draw(GraphicsDevice graphicsDevice); + + protected void EnableLightingMode(LightingMode mode) + { + effect.LightingEnabled = true; + if (mode == LightingMode.VertexLighting) + { + effect.EnableDefaultLighting(); + effect.PreferPerPixelLighting = false; + } + else if (mode == LightingMode.OneLight) + { + effect.DirectionalLight0.Enabled = true; + effect.DirectionalLight1.Enabled = false; + effect.DirectionalLight2.Enabled = false; + effect.PreferPerPixelLighting = false; + } + else if (mode == LightingMode.PixelLighting) + { + effect.EnableDefaultLighting(); + effect.PreferPerPixelLighting = true; + } + } + + protected void ToggleFog(bool enabled) + { + if (enabled) + { + effect.FogStart = 1f; + effect.FogEnd = 15f; + effect.FogColor = Color.Gray.ToVector3(); + } + + effect.FogEnabled = enabled; + } + + protected void SetCameraMatrices() + { + effect.World = Camera.World; + effect.View = Camera.View; + effect.Projection = Camera.Projection; + } } } diff --git a/Samples/BasicEffectSample/BasicEffectSample.csproj b/Samples/BasicEffectSample/BasicEffectSample.csproj index 2312f75b..1b835fd8 100644 --- a/Samples/BasicEffectSample/BasicEffectSample.csproj +++ b/Samples/BasicEffectSample/BasicEffectSample.csproj @@ -81,20 +81,29 @@ + - - + + + + + + + + + + diff --git a/Samples/BasicEffectSample/BasicEffectSample_Linux.csproj b/Samples/BasicEffectSample/BasicEffectSample_Linux.csproj index db83d1d6..60c7daf8 100644 --- a/Samples/BasicEffectSample/BasicEffectSample_Linux.csproj +++ b/Samples/BasicEffectSample/BasicEffectSample_Linux.csproj @@ -79,20 +79,29 @@ + - - + + + + + + + + + + diff --git a/Samples/BasicEffectSample/BasicEffectSample_PSVita.csproj b/Samples/BasicEffectSample/BasicEffectSample_PSVita.csproj index e317af41..09aa0788 100644 --- a/Samples/BasicEffectSample/BasicEffectSample_PSVita.csproj +++ b/Samples/BasicEffectSample/BasicEffectSample_PSVita.csproj @@ -79,20 +79,29 @@ + - - + + + + + + + + + + diff --git a/Samples/BasicEffectSample/BasicEffectSample_WindowsMetro.csproj b/Samples/BasicEffectSample/BasicEffectSample_WindowsMetro.csproj index 69fede11..43d082e7 100644 --- a/Samples/BasicEffectSample/BasicEffectSample_WindowsMetro.csproj +++ b/Samples/BasicEffectSample/BasicEffectSample_WindowsMetro.csproj @@ -56,20 +56,29 @@ + - - + + + + + + + + + + diff --git a/Samples/BasicEffectSample/Game1.cs b/Samples/BasicEffectSample/Game1.cs index 3ae527f6..31bfb312 100644 --- a/Samples/BasicEffectSample/Game1.cs +++ b/Samples/BasicEffectSample/Game1.cs @@ -18,7 +18,7 @@ namespace BasicEffectSample KeyboardState lastState; - BaseScene[] allScenes = + private readonly BaseScene[] allScenes = { // Basic new DiffuseNoFogScene(), @@ -31,37 +31,37 @@ namespace BasicEffectSample new VertexColorTextureFogScene(), // Vertex Lighting - new VertexLightingDiffuseNoFogScene(), - new VertexLightingDiffuseFogScene(), - //new VertexLightingVertexColorNoFogScene(), - //new VertexLightingVertexColorFogScene(), - //new VertexLightingTextureNoFogScene(), - //new VertexLightingTextureFogScene(), - //new VertexLightingVertexColorTextureNoFogScene(), - //new VertexLightingVertexColorTextureFogScene(), + new LitDiffuseNoFogScene(LightingMode.VertexLighting), + new LitDiffuseFogScene(LightingMode.VertexLighting), + new LitVertexColorNoFogScene(LightingMode.VertexLighting), + new LitVertexColorFogScene(LightingMode.VertexLighting), + new LitTextureNoFogScene(LightingMode.VertexLighting), + new LitTextureFogScene(LightingMode.VertexLighting), + new LitVertexColorTextureNoFogScene(LightingMode.VertexLighting), + new LitVertexColorTextureFogScene(LightingMode.VertexLighting), // One Light - //new OneLightNoFogScene(), - //new OneLightFogScene(), - //new OneLightVertexColorNoFogScene(), - //new OneLightVertexColorFogScene(), - //new OneLightTextureNoFogScene(), - //new OneLightTextureFogScene(), - //new OneLightVertexColorTextureNoFogScene(), - //new OneLightVertexColorTextureFogScene(), + new LitDiffuseNoFogScene(LightingMode.OneLight), + new LitDiffuseFogScene(LightingMode.OneLight), + new LitVertexColorNoFogScene(LightingMode.OneLight), + new LitVertexColorFogScene(LightingMode.OneLight), + new LitTextureNoFogScene(LightingMode.OneLight), + new LitTextureFogScene(LightingMode.OneLight), + new LitVertexColorTextureNoFogScene(LightingMode.OneLight), + new LitVertexColorTextureFogScene(LightingMode.OneLight), // Pixel Lighting - //new PixelLightingNoFogScene(), - //new PixelLightingFogScene(), - //new PixelLightingVertexColorNoFogScene(), - //new PixelLightingVertexColorFogScene(), - //new PixelLightingTextureNoFogScene(), - //new PixelLightingTextureFogScene(), - //new PixelLightingVertexColorTextureNoFogScene(), - //new PixelLightingVertexColorTextureFogScene(), + new LitDiffuseNoFogScene(LightingMode.PixelLighting), + new LitDiffuseFogScene(LightingMode.PixelLighting), + new LitVertexColorNoFogScene(LightingMode.PixelLighting), + new LitVertexColorFogScene(LightingMode.PixelLighting), + new LitTextureNoFogScene(LightingMode.PixelLighting), + new LitTextureFogScene(LightingMode.PixelLighting), + new LitVertexColorTextureNoFogScene(LightingMode.PixelLighting), + new LitVertexColorTextureFogScene(LightingMode.PixelLighting), }; - int currentSceneIndex = 0; + int currentSceneIndex; public Game1() { diff --git a/Samples/BasicEffectSample/LightingMode.cs b/Samples/BasicEffectSample/LightingMode.cs new file mode 100644 index 00000000..9ea45cd6 --- /dev/null +++ b/Samples/BasicEffectSample/LightingMode.cs @@ -0,0 +1,15 @@ +using System; + +// This file is part of the ANX.Framework created by the +// "ANX.Framework developer group" and released under the Ms-PL license. +// For details see: http://anxframework.codeplex.com/license + +namespace BasicEffectSample +{ + public enum LightingMode + { + VertexLighting, + OneLight, + PixelLighting + } +} diff --git a/Samples/BasicEffectSample/Scenes/DiffuseFogScene.cs b/Samples/BasicEffectSample/Scenes/DiffuseFogScene.cs index f952b7df..c80eb288 100644 --- a/Samples/BasicEffectSample/Scenes/DiffuseFogScene.cs +++ b/Samples/BasicEffectSample/Scenes/DiffuseFogScene.cs @@ -11,17 +11,10 @@ namespace BasicEffectSample.Scenes { public class DiffuseFogScene : BaseScene { - public override string Name - { - get - { - return "DiffuseColor with Fog"; - } - } - - private BasicEffect effect; - private VertexBuffer vertices; - private IndexBuffer indices; + public override string Name + { + get { return "DiffuseColor with Fog"; } + } public override void Initialize(ContentManager content, GraphicsDevice graphicsDevice) { @@ -30,7 +23,7 @@ namespace BasicEffectSample.Scenes new VertexElement(0, VertexElementFormat.Vector3, VertexElementUsage.Position, 0)); vertices = new VertexBuffer(graphicsDevice, declaration, 4, BufferUsage.WriteOnly); - vertices.SetData(new Vector3[] + vertices.SetData(new[] { new Vector3(-5f, 0f, -5f), new Vector3(-5f, 0f, 5f), @@ -39,21 +32,16 @@ namespace BasicEffectSample.Scenes }); indices = new IndexBuffer(graphicsDevice, IndexElementSize.SixteenBits, 6, BufferUsage.WriteOnly); - indices.SetData(new ushort[] { 0, 2, 1, 0, 3, 2 }); + indices.SetData(new ushort[] { 0, 2, 1, 0, 3, 2 }); } public override void Draw(GraphicsDevice graphicsDevice) - { - effect.FogStart = 1f; - effect.FogEnd = 15f; - effect.FogColor = Color.Gray.ToVector3(); - effect.World = Camera.World; - effect.View = Camera.View; - effect.Projection = Camera.Projection; + { + ToggleFog(true); + SetCameraMatrices(); effect.DiffuseColor = Color.Red.ToVector3(); effect.EmissiveColor = Color.Black.ToVector3(); effect.LightingEnabled = false; - effect.FogEnabled = true; effect.CurrentTechnique.Passes[0].Apply(); graphicsDevice.Indices = indices; diff --git a/Samples/BasicEffectSample/Scenes/DiffuseNoFogScene.cs b/Samples/BasicEffectSample/Scenes/DiffuseNoFogScene.cs index d3ce1d01..bc84d2ce 100644 --- a/Samples/BasicEffectSample/Scenes/DiffuseNoFogScene.cs +++ b/Samples/BasicEffectSample/Scenes/DiffuseNoFogScene.cs @@ -11,26 +11,19 @@ namespace BasicEffectSample.Scenes { public class DiffuseNoFogScene : BaseScene { - public override string Name - { - get - { - return "DiffuseColor"; - } - } - - private BasicEffect effect; - private VertexBuffer vertices; - private IndexBuffer indices; + public override string Name + { + get { return "DiffuseColor"; } + } public override void Initialize(ContentManager content, GraphicsDevice graphicsDevice) { effect = new BasicEffect(graphicsDevice); var declaration = new VertexDeclaration(12, - new VertexElement(0, VertexElementFormat.Vector3, VertexElementUsage.Position, 0)); + new VertexElement(0, VertexElementFormat.Vector3, VertexElementUsage.Position, 0)); vertices = new VertexBuffer(graphicsDevice, declaration, 4, BufferUsage.WriteOnly); - vertices.SetData(new Vector3[] + vertices.SetData(new[] { new Vector3(-5f, 0f, -5f), new Vector3(-5f, 0f, 5f), @@ -39,18 +32,16 @@ namespace BasicEffectSample.Scenes }); indices = new IndexBuffer(graphicsDevice, IndexElementSize.SixteenBits, 6, BufferUsage.WriteOnly); - indices.SetData(new ushort[] { 0, 2, 1, 0, 3, 2 }); + indices.SetData(new ushort[] { 0, 2, 1, 0, 3, 2 }); } public override void Draw(GraphicsDevice graphicsDevice) - { - effect.World = Camera.World; - effect.View = Camera.View; - effect.Projection = Camera.Projection; + { + SetCameraMatrices(); effect.DiffuseColor = Color.Red.ToVector3(); effect.EmissiveColor = Color.Black.ToVector3(); - effect.LightingEnabled = false; - effect.FogEnabled = false; + effect.LightingEnabled = false; + ToggleFog(false); effect.CurrentTechnique.Passes[0].Apply(); graphicsDevice.Indices = indices; diff --git a/Samples/BasicEffectSample/Scenes/VertexLightingDiffuseNoFogScene.cs b/Samples/BasicEffectSample/Scenes/LitDiffuseFogScene.cs similarity index 67% rename from Samples/BasicEffectSample/Scenes/VertexLightingDiffuseNoFogScene.cs rename to Samples/BasicEffectSample/Scenes/LitDiffuseFogScene.cs index 08917b10..5b1f19f7 100644 --- a/Samples/BasicEffectSample/Scenes/VertexLightingDiffuseNoFogScene.cs +++ b/Samples/BasicEffectSample/Scenes/LitDiffuseFogScene.cs @@ -9,25 +9,25 @@ using ANX.Framework; namespace BasicEffectSample.Scenes { - public class VertexLightingDiffuseNoFogScene : BaseScene + public class LitDiffuseFogScene : BaseScene { - public override string Name - { - get - { - return "VertexLighting with DiffuseColor"; - } - } + public override string Name + { + get { return mode + "VertexLighting with DiffuseColor and Fog"; } + } - private BasicEffect effect; - private VertexBuffer vertices; - private IndexBuffer indices; + private readonly LightingMode mode; + + public LitDiffuseFogScene(LightingMode setMode) + { + mode = setMode; + } public override void Initialize(ContentManager content, GraphicsDevice graphicsDevice) { effect = new BasicEffect(graphicsDevice); - var elements = new VertexElement[] + var elements = new[] { new VertexElement(0, VertexElementFormat.Vector3, VertexElementUsage.Position, 0), new VertexElement(12, VertexElementFormat.Vector3, VertexElementUsage.Normal, 0), @@ -35,7 +35,7 @@ namespace BasicEffectSample.Scenes var declaration = new VertexDeclaration(24, elements); vertices = new VertexBuffer(graphicsDevice, declaration, 6, BufferUsage.WriteOnly); - vertices.SetData(new Vector3[] + vertices.SetData(new[] { new Vector3(0f, 0f, -5f), new Vector3(-1f, 0f, 0f), new Vector3(0f, 0f, 5f), new Vector3(-1f, 0f, 0f), @@ -46,23 +46,19 @@ namespace BasicEffectSample.Scenes }); indices = new IndexBuffer(graphicsDevice, IndexElementSize.SixteenBits, 12, BufferUsage.WriteOnly); - indices.SetData(new ushort[] { 0, 2, 1, 2, 3, 1, 2, 4, 3, 4, 5, 3 }); + indices.SetData(new ushort[] { 0, 2, 1, 2, 3, 1, 2, 4, 3, 4, 5, 3 }); } public override void Draw(GraphicsDevice graphicsDevice) - { - effect.World = Camera.World; - effect.View = Camera.View; - effect.Projection = Camera.Projection; + { + ToggleFog(true); + SetCameraMatrices(); effect.DiffuseColor = Color.LightGreen.ToVector3(); effect.EmissiveColor = Color.Black.ToVector3(); - effect.LightingEnabled = true; - effect.PreferPerPixelLighting = false; - effect.FogEnabled = false; - effect.EnableDefaultLighting(); + EnableLightingMode(mode); - effect.CurrentTechnique.Passes[0].Apply(); + effect.CurrentTechnique.Passes[0].Apply(); graphicsDevice.Indices = indices; graphicsDevice.SetVertexBuffer(vertices); diff --git a/Samples/BasicEffectSample/Scenes/VertexLightingDiffuseFogScene.cs b/Samples/BasicEffectSample/Scenes/LitDiffuseNoFogScene.cs similarity index 64% rename from Samples/BasicEffectSample/Scenes/VertexLightingDiffuseFogScene.cs rename to Samples/BasicEffectSample/Scenes/LitDiffuseNoFogScene.cs index 14490ce2..a7d2676c 100644 --- a/Samples/BasicEffectSample/Scenes/VertexLightingDiffuseFogScene.cs +++ b/Samples/BasicEffectSample/Scenes/LitDiffuseNoFogScene.cs @@ -9,25 +9,25 @@ using ANX.Framework; namespace BasicEffectSample.Scenes { - public class VertexLightingDiffuseFogScene : BaseScene + public class LitDiffuseNoFogScene : BaseScene { - public override string Name - { - get - { - return "VertexLighting with DiffuseColor and Fog"; - } - } + public override string Name + { + get { return mode + " with DiffuseColor"; } + } - private BasicEffect effect; - private VertexBuffer vertices; - private IndexBuffer indices; + private readonly LightingMode mode; + + public LitDiffuseNoFogScene(LightingMode setMode) + { + mode = setMode; + } public override void Initialize(ContentManager content, GraphicsDevice graphicsDevice) { effect = new BasicEffect(graphicsDevice); - var elements = new VertexElement[] + var elements = new[] { new VertexElement(0, VertexElementFormat.Vector3, VertexElementUsage.Position, 0), new VertexElement(12, VertexElementFormat.Vector3, VertexElementUsage.Normal, 0), @@ -35,7 +35,7 @@ namespace BasicEffectSample.Scenes var declaration = new VertexDeclaration(24, elements); vertices = new VertexBuffer(graphicsDevice, declaration, 6, BufferUsage.WriteOnly); - vertices.SetData(new Vector3[] + vertices.SetData(new[] { new Vector3(0f, 0f, -5f), new Vector3(-1f, 0f, 0f), new Vector3(0f, 0f, 5f), new Vector3(-1f, 0f, 0f), @@ -46,24 +46,17 @@ namespace BasicEffectSample.Scenes }); indices = new IndexBuffer(graphicsDevice, IndexElementSize.SixteenBits, 12, BufferUsage.WriteOnly); - indices.SetData(new ushort[] { 0, 2, 1, 2, 3, 1, 2, 4, 3, 4, 5, 3 }); + indices.SetData(new ushort[] { 0, 2, 1, 2, 3, 1, 2, 4, 3, 4, 5, 3 }); } public override void Draw(GraphicsDevice graphicsDevice) - { - effect.FogStart = 1f; - effect.FogEnd = 15f; - effect.FogColor = Color.Gray.ToVector3(); - effect.World = Camera.World; - effect.View = Camera.View; - effect.Projection = Camera.Projection; + { + SetCameraMatrices(); effect.DiffuseColor = Color.LightGreen.ToVector3(); - effect.EmissiveColor = Color.Black.ToVector3(); - effect.LightingEnabled = true; - effect.PreferPerPixelLighting = false; - effect.FogEnabled = true; + effect.EmissiveColor = Color.Black.ToVector3(); + ToggleFog(false); - effect.EnableDefaultLighting(); + EnableLightingMode(mode); effect.CurrentTechnique.Passes[0].Apply(); diff --git a/Samples/BasicEffectSample/Scenes/LitTextureFogScene.cs b/Samples/BasicEffectSample/Scenes/LitTextureFogScene.cs new file mode 100644 index 00000000..805ff9e8 --- /dev/null +++ b/Samples/BasicEffectSample/Scenes/LitTextureFogScene.cs @@ -0,0 +1,67 @@ +using System; +using ANX.Framework.Graphics; +using ANX.Framework.Content; +using ANX.Framework; + +// This file is part of the ANX.Framework created by the +// "ANX.Framework developer group" and released under the Ms-PL license. +// For details see: http://anxframework.codeplex.com/license + +namespace BasicEffectSample.Scenes +{ + public class LitTextureFogScene : BaseScene + { + public override string Name + { + get { return mode + " with Texture and Fog"; } + } + + private Texture2D texture; + private readonly LightingMode mode; + + public LitTextureFogScene(LightingMode setMode) + { + mode = setMode; + } + + public override void Initialize(ContentManager content, GraphicsDevice graphicsDevice) + { + texture = content.Load("Textures/stone_tile"); + effect = new BasicEffect(graphicsDevice); + + vertices = new VertexBuffer(graphicsDevice, VertexPositionNormalTexture.VertexDeclaration, 6, BufferUsage.WriteOnly); + float textureFactor = 1f / 7f; + vertices.SetData(new[] + { + new VertexPositionNormalTexture(new Vector3(0f, 0f, -5f), new Vector3(-1f, 0f, 0f), new Vector2(0, 0)), + new VertexPositionNormalTexture(new Vector3(0f, 0f, 5f), new Vector3(-1f, 0f, 0f), new Vector2(0, 1)), + new VertexPositionNormalTexture(new Vector3(0f, 2f, -5f), Vector3.Normalize(new Vector3(-1f, 1f, 0f)), new Vector2(textureFactor * 2f, 0)), + new VertexPositionNormalTexture(new Vector3(0f, 2f, 5f), Vector3.Normalize(new Vector3(-1f, 1f, 0f)), new Vector2(textureFactor * 2f, 1)), + new VertexPositionNormalTexture(new Vector3(5f, 2f, -5f), new Vector3(0f, 1f, 0f), new Vector2(1, 0)), + new VertexPositionNormalTexture(new Vector3(5f, 2f, 5f), new Vector3(0f, 1f, 0f), new Vector2(1, 1)) + }); + + indices = new IndexBuffer(graphicsDevice, IndexElementSize.SixteenBits, 12, BufferUsage.WriteOnly); + indices.SetData(new ushort[] { 0, 2, 1, 2, 3, 1, 2, 4, 3, 4, 5, 3 }); + } + + public override void Draw(GraphicsDevice graphicsDevice) + { + ToggleFog(true); + SetCameraMatrices(); + effect.DiffuseColor = Color.White.ToVector3(); + effect.EmissiveColor = Color.Black.ToVector3(); + effect.TextureEnabled = true; + effect.VertexColorEnabled = false; + effect.Texture = texture; + + EnableLightingMode(mode); + + effect.CurrentTechnique.Passes[0].Apply(); + + graphicsDevice.Indices = indices; + graphicsDevice.SetVertexBuffer(vertices); + graphicsDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, 6, 0, 4); + } + } +} diff --git a/Samples/BasicEffectSample/Scenes/LitTextureNoFogScene.cs b/Samples/BasicEffectSample/Scenes/LitTextureNoFogScene.cs new file mode 100644 index 00000000..bc7b3ebe --- /dev/null +++ b/Samples/BasicEffectSample/Scenes/LitTextureNoFogScene.cs @@ -0,0 +1,67 @@ +using System; +using ANX.Framework.Graphics; +using ANX.Framework.Content; +using ANX.Framework; + +// This file is part of the ANX.Framework created by the +// "ANX.Framework developer group" and released under the Ms-PL license. +// For details see: http://anxframework.codeplex.com/license + +namespace BasicEffectSample.Scenes +{ + public class LitTextureNoFogScene : BaseScene + { + public override string Name + { + get { return mode + " with Texture"; } + } + + private Texture2D texture; + private readonly LightingMode mode; + + public LitTextureNoFogScene(LightingMode setMode) + { + mode = setMode; + } + + public override void Initialize(ContentManager content, GraphicsDevice graphicsDevice) + { + texture = content.Load("Textures/stone_tile"); + effect = new BasicEffect(graphicsDevice); + + vertices = new VertexBuffer(graphicsDevice, VertexPositionNormalTexture.VertexDeclaration, 6, BufferUsage.WriteOnly); + float textureFactor = 1f / 7f; + vertices.SetData(new[] + { + new VertexPositionNormalTexture(new Vector3(0f, 0f, -5f), new Vector3(-1f, 0f, 0f), new Vector2(0, 0)), + new VertexPositionNormalTexture(new Vector3(0f, 0f, 5f), new Vector3(-1f, 0f, 0f), new Vector2(0, 1)), + new VertexPositionNormalTexture(new Vector3(0f, 2f, -5f), Vector3.Normalize(new Vector3(-1f, 1f, 0f)), new Vector2(textureFactor * 2f, 0)), + new VertexPositionNormalTexture(new Vector3(0f, 2f, 5f), Vector3.Normalize(new Vector3(-1f, 1f, 0f)), new Vector2(textureFactor * 2f, 1)), + new VertexPositionNormalTexture(new Vector3(5f, 2f, -5f), new Vector3(0f, 1f, 0f), new Vector2(1, 0)), + new VertexPositionNormalTexture(new Vector3(5f, 2f, 5f), new Vector3(0f, 1f, 0f), new Vector2(1, 1)) + }); + + indices = new IndexBuffer(graphicsDevice, IndexElementSize.SixteenBits, 12, BufferUsage.WriteOnly); + indices.SetData(new ushort[] { 0, 2, 1, 2, 3, 1, 2, 4, 3, 4, 5, 3 }); + } + + public override void Draw(GraphicsDevice graphicsDevice) + { + SetCameraMatrices(); + effect.DiffuseColor = Color.White.ToVector3(); + effect.EmissiveColor = Color.Black.ToVector3(); + effect.VertexColorEnabled = false; + effect.TextureEnabled = true; + effect.Texture = texture; + + ToggleFog(false); + EnableLightingMode(mode); + + effect.CurrentTechnique.Passes[0].Apply(); + + graphicsDevice.Indices = indices; + graphicsDevice.SetVertexBuffer(vertices); + graphicsDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, 6, 0, 4); + } + } +} diff --git a/Samples/BasicEffectSample/Scenes/LitVertexColorFogScene.cs b/Samples/BasicEffectSample/Scenes/LitVertexColorFogScene.cs new file mode 100644 index 00000000..a0f0b587 --- /dev/null +++ b/Samples/BasicEffectSample/Scenes/LitVertexColorFogScene.cs @@ -0,0 +1,64 @@ +using System; +using ANX.Framework.Graphics; +using ANX.Framework.Content; +using ANX.Framework; +using BasicEffectSample.VertexTypes; + +// This file is part of the ANX.Framework created by the +// "ANX.Framework developer group" and released under the Ms-PL license. +// For details see: http://anxframework.codeplex.com/license + +namespace BasicEffectSample.Scenes +{ + public class LitVertexColorFogScene : BaseScene + { + public override string Name + { + get { return mode + "with VertexColor and Fog"; } + } + + private readonly LightingMode mode; + + public LitVertexColorFogScene(LightingMode setMode) + { + mode = setMode; + } + + public override void Initialize(ContentManager content, GraphicsDevice graphicsDevice) + { + effect = new BasicEffect(graphicsDevice); + + vertices = new VertexBuffer(graphicsDevice, VertexPositionNormalColor.VertexDeclaration, 6, BufferUsage.WriteOnly); + vertices.SetData(new[] + { + new VertexPositionNormalColor(new Vector3(0f, 0f, -5f), new Vector3(-1f, 0f, 0f), Color.OrangeRed), + new VertexPositionNormalColor(new Vector3(0f, 0f, 5f), new Vector3(-1f, 0f, 0f), Color.LightGreen), + new VertexPositionNormalColor(new Vector3(0f, 2f, -5f), Vector3.Normalize(new Vector3(-1f, 1f, 0f)), Color.OrangeRed), + new VertexPositionNormalColor(new Vector3(0f, 2f, 5f), Vector3.Normalize(new Vector3(-1f, 1f, 0f)), Color.LightGreen), + new VertexPositionNormalColor(new Vector3(5f, 2f, -5f), new Vector3(0f, 1f, 0f), Color.OrangeRed), + new VertexPositionNormalColor(new Vector3(5f, 2f, 5f), new Vector3(0f, 1f, 0f), Color.LightGreen) + }); + + indices = new IndexBuffer(graphicsDevice, IndexElementSize.SixteenBits, 12, BufferUsage.WriteOnly); + indices.SetData(new ushort[] { 0, 2, 1, 2, 3, 1, 2, 4, 3, 4, 5, 3 }); + } + + public override void Draw(GraphicsDevice graphicsDevice) + { + ToggleFog(true); + SetCameraMatrices(); + effect.DiffuseColor = Color.White.ToVector3(); + effect.EmissiveColor = Color.Black.ToVector3(); + effect.VertexColorEnabled = true; + effect.TextureEnabled = false; + + EnableLightingMode(mode); + + effect.CurrentTechnique.Passes[0].Apply(); + + graphicsDevice.Indices = indices; + graphicsDevice.SetVertexBuffer(vertices); + graphicsDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, 6, 0, 4); + } + } +} diff --git a/Samples/BasicEffectSample/Scenes/LitVertexColorNoFogScene.cs b/Samples/BasicEffectSample/Scenes/LitVertexColorNoFogScene.cs new file mode 100644 index 00000000..d7f2ccda --- /dev/null +++ b/Samples/BasicEffectSample/Scenes/LitVertexColorNoFogScene.cs @@ -0,0 +1,64 @@ +using System; +using ANX.Framework.Graphics; +using ANX.Framework.Content; +using ANX.Framework; +using BasicEffectSample.VertexTypes; + +// This file is part of the ANX.Framework created by the +// "ANX.Framework developer group" and released under the Ms-PL license. +// For details see: http://anxframework.codeplex.com/license + +namespace BasicEffectSample.Scenes +{ + public class LitVertexColorNoFogScene : BaseScene + { + public override string Name + { + get { return mode + " with VertexColor"; } + } + + private readonly LightingMode mode; + + public LitVertexColorNoFogScene(LightingMode setMode) + { + mode = setMode; + } + + public override void Initialize(ContentManager content, GraphicsDevice graphicsDevice) + { + effect = new BasicEffect(graphicsDevice); + + vertices = new VertexBuffer(graphicsDevice, VertexPositionNormalColor.VertexDeclaration, 6, BufferUsage.WriteOnly); + vertices.SetData(new[] + { + new VertexPositionNormalColor(new Vector3(0f, 0f, -5f), new Vector3(-1f, 0f, 0f), Color.OrangeRed), + new VertexPositionNormalColor(new Vector3(0f, 0f, 5f), new Vector3(-1f, 0f, 0f), Color.LightGreen), + new VertexPositionNormalColor(new Vector3(0f, 2f, -5f), Vector3.Normalize(new Vector3(-1f, 1f, 0f)), Color.OrangeRed), + new VertexPositionNormalColor(new Vector3(0f, 2f, 5f), Vector3.Normalize(new Vector3(-1f, 1f, 0f)), Color.LightGreen), + new VertexPositionNormalColor(new Vector3(5f, 2f, -5f), new Vector3(0f, 1f, 0f), Color.OrangeRed), + new VertexPositionNormalColor(new Vector3(5f, 2f, 5f), new Vector3(0f, 1f, 0f), Color.LightGreen) + }); + + indices = new IndexBuffer(graphicsDevice, IndexElementSize.SixteenBits, 12, BufferUsage.WriteOnly); + indices.SetData(new ushort[] { 0, 2, 1, 2, 3, 1, 2, 4, 3, 4, 5, 3 }); + } + + public override void Draw(GraphicsDevice graphicsDevice) + { + SetCameraMatrices(); + effect.DiffuseColor = Color.White.ToVector3(); + effect.EmissiveColor = Color.Black.ToVector3(); + effect.VertexColorEnabled = true; + effect.TextureEnabled = false; + + ToggleFog(false); + EnableLightingMode(mode); + + effect.CurrentTechnique.Passes[0].Apply(); + + graphicsDevice.Indices = indices; + graphicsDevice.SetVertexBuffer(vertices); + graphicsDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, 6, 0, 4); + } + } +} diff --git a/Samples/BasicEffectSample/Scenes/LitVertexColorTextureFogScene.cs b/Samples/BasicEffectSample/Scenes/LitVertexColorTextureFogScene.cs new file mode 100644 index 00000000..731f0a19 --- /dev/null +++ b/Samples/BasicEffectSample/Scenes/LitVertexColorTextureFogScene.cs @@ -0,0 +1,68 @@ +using System; +using ANX.Framework.Graphics; +using ANX.Framework.Content; +using ANX.Framework; +using BasicEffectSample.VertexTypes; + +// This file is part of the ANX.Framework created by the +// "ANX.Framework developer group" and released under the Ms-PL license. +// For details see: http://anxframework.codeplex.com/license + +namespace BasicEffectSample.Scenes +{ + public class LitVertexColorTextureFogScene : BaseScene + { + public override string Name + { + get { return mode + " with VertexColor, Texture and Fog"; } + } + + private Texture2D texture; + private readonly LightingMode mode; + + public LitVertexColorTextureFogScene(LightingMode setMode) + { + mode = setMode; + } + + public override void Initialize(ContentManager content, GraphicsDevice graphicsDevice) + { + texture = content.Load("Textures/stone_tile"); + effect = new BasicEffect(graphicsDevice); + + vertices = new VertexBuffer(graphicsDevice, VertexPositionNormalColorTexture.VertexDeclaration, 6, BufferUsage.WriteOnly); + float textureFactor = 1f / 7f; + vertices.SetData(new[] + { + new VertexPositionNormalColorTexture(new Vector3(0f, 0f, -5f), new Vector3(-1f, 0f, 0f), Color.OrangeRed, new Vector2(0, 0)), + new VertexPositionNormalColorTexture(new Vector3(0f, 0f, 5f), new Vector3(-1f, 0f, 0f), Color.LightGreen, new Vector2(0, 1)), + new VertexPositionNormalColorTexture(new Vector3(0f, 2f, -5f), Vector3.Normalize(new Vector3(-1f, 1f, 0f)), Color.OrangeRed, new Vector2(textureFactor * 2f, 0)), + new VertexPositionNormalColorTexture(new Vector3(0f, 2f, 5f), Vector3.Normalize(new Vector3(-1f, 1f, 0f)), Color.LightGreen, new Vector2(textureFactor * 2f, 1)), + new VertexPositionNormalColorTexture(new Vector3(5f, 2f, -5f), new Vector3(0f, 1f, 0f), Color.OrangeRed, new Vector2(1, 0)), + new VertexPositionNormalColorTexture(new Vector3(5f, 2f, 5f), new Vector3(0f, 1f, 0f), Color.LightGreen, new Vector2(1, 1)) + }); + + indices = new IndexBuffer(graphicsDevice, IndexElementSize.SixteenBits, 12, BufferUsage.WriteOnly); + indices.SetData(new ushort[] { 0, 2, 1, 2, 3, 1, 2, 4, 3, 4, 5, 3 }); + } + + public override void Draw(GraphicsDevice graphicsDevice) + { + ToggleFog(true); + SetCameraMatrices(); + effect.DiffuseColor = Color.White.ToVector3(); + effect.EmissiveColor = Color.Black.ToVector3(); + effect.VertexColorEnabled = true; + effect.TextureEnabled = true; + effect.Texture = texture; + + EnableLightingMode(mode); + + effect.CurrentTechnique.Passes[0].Apply(); + + graphicsDevice.Indices = indices; + graphicsDevice.SetVertexBuffer(vertices); + graphicsDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, 6, 0, 4); + } + } +} diff --git a/Samples/BasicEffectSample/Scenes/LitVertexColorTextureNoFogScene.cs b/Samples/BasicEffectSample/Scenes/LitVertexColorTextureNoFogScene.cs new file mode 100644 index 00000000..6f56705f --- /dev/null +++ b/Samples/BasicEffectSample/Scenes/LitVertexColorTextureNoFogScene.cs @@ -0,0 +1,68 @@ +using System; +using ANX.Framework.Graphics; +using ANX.Framework.Content; +using ANX.Framework; +using BasicEffectSample.VertexTypes; + +// This file is part of the ANX.Framework created by the +// "ANX.Framework developer group" and released under the Ms-PL license. +// For details see: http://anxframework.codeplex.com/license + +namespace BasicEffectSample.Scenes +{ + public class LitVertexColorTextureNoFogScene : BaseScene + { + public override string Name + { + get { return mode + " with VertexColor and Texture"; } + } + + private Texture2D texture; + private readonly LightingMode mode; + + public LitVertexColorTextureNoFogScene(LightingMode setMode) + { + mode = setMode; + } + + public override void Initialize(ContentManager content, GraphicsDevice graphicsDevice) + { + texture = content.Load("Textures/stone_tile"); + effect = new BasicEffect(graphicsDevice); + + vertices = new VertexBuffer(graphicsDevice, VertexPositionNormalColorTexture.VertexDeclaration, 6, BufferUsage.WriteOnly); + float textureFactor = 1f / 7f; + vertices.SetData(new[] + { + new VertexPositionNormalColorTexture(new Vector3(0f, 0f, -5f), new Vector3(-1f, 0f, 0f), Color.OrangeRed, new Vector2(0, 0)), + new VertexPositionNormalColorTexture(new Vector3(0f, 0f, 5f), new Vector3(-1f, 0f, 0f), Color.LightGreen, new Vector2(0, 1)), + new VertexPositionNormalColorTexture(new Vector3(0f, 2f, -5f), Vector3.Normalize(new Vector3(-1f, 1f, 0f)), Color.OrangeRed, new Vector2(textureFactor * 2f, 0)), + new VertexPositionNormalColorTexture(new Vector3(0f, 2f, 5f), Vector3.Normalize(new Vector3(-1f, 1f, 0f)), Color.LightGreen, new Vector2(textureFactor * 2f, 1)), + new VertexPositionNormalColorTexture(new Vector3(5f, 2f, -5f), new Vector3(0f, 1f, 0f), Color.OrangeRed, new Vector2(1, 0)), + new VertexPositionNormalColorTexture(new Vector3(5f, 2f, 5f), new Vector3(0f, 1f, 0f), Color.LightGreen, new Vector2(1, 1)) + }); + + indices = new IndexBuffer(graphicsDevice, IndexElementSize.SixteenBits, 12, BufferUsage.WriteOnly); + indices.SetData(new ushort[] { 0, 2, 1, 2, 3, 1, 2, 4, 3, 4, 5, 3 }); + } + + public override void Draw(GraphicsDevice graphicsDevice) + { + SetCameraMatrices(); + effect.DiffuseColor = Color.White.ToVector3(); + effect.EmissiveColor = Color.Black.ToVector3(); + effect.VertexColorEnabled = true; + effect.TextureEnabled = true; + effect.Texture = texture; + + ToggleFog(false); + EnableLightingMode(mode); + + effect.CurrentTechnique.Passes[0].Apply(); + + graphicsDevice.Indices = indices; + graphicsDevice.SetVertexBuffer(vertices); + graphicsDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, 6, 0, 4); + } + } +} diff --git a/Samples/BasicEffectSample/Scenes/TextureFogScene.cs b/Samples/BasicEffectSample/Scenes/TextureFogScene.cs index 15d1c266..e40c46e3 100644 --- a/Samples/BasicEffectSample/Scenes/TextureFogScene.cs +++ b/Samples/BasicEffectSample/Scenes/TextureFogScene.cs @@ -11,17 +11,11 @@ namespace BasicEffectSample.Scenes { public class TextureFogScene : BaseScene { - public override string Name - { - get - { - return "Texture with Fog"; - } - } + public override string Name + { + get { return "Texture with Fog"; } + } - private BasicEffect effect; - private VertexBuffer vertices; - private IndexBuffer indices; private Texture2D texture; public override void Initialize(ContentManager content, GraphicsDevice graphicsDevice) @@ -30,7 +24,7 @@ namespace BasicEffectSample.Scenes effect = new BasicEffect(graphicsDevice); vertices = new VertexBuffer(graphicsDevice, VertexPositionTexture.VertexDeclaration, 4, BufferUsage.WriteOnly); - vertices.SetData(new[] + vertices.SetData(new[] { new VertexPositionTexture(new Vector3(-5f, 0f, -5f), new Vector2(0, 0)), new VertexPositionTexture(new Vector3(-5f, 0f, 5f), new Vector2(0, 1)), @@ -39,24 +33,19 @@ namespace BasicEffectSample.Scenes }); indices = new IndexBuffer(graphicsDevice, IndexElementSize.SixteenBits, 6, BufferUsage.WriteOnly); - indices.SetData(new ushort[] { 0, 2, 1, 0, 3, 2 }); + indices.SetData(new ushort[] { 0, 2, 1, 0, 3, 2 }); } public override void Draw(GraphicsDevice graphicsDevice) { - effect.FogStart = 1f; - effect.FogEnd = 15f; - effect.FogColor = Color.Gray.ToVector3(); - effect.World = Camera.World; - effect.View = Camera.View; - effect.Projection = Camera.Projection; + ToggleFog(true); + SetCameraMatrices(); effect.DiffuseColor = Color.White.ToVector3(); effect.EmissiveColor = Color.Black.ToVector3(); effect.LightingEnabled = false; effect.VertexColorEnabled = false; effect.TextureEnabled = true; effect.Texture = texture; - effect.FogEnabled = true; effect.CurrentTechnique.Passes[0].Apply(); graphicsDevice.Indices = indices; diff --git a/Samples/BasicEffectSample/Scenes/TextureNoFogScene.cs b/Samples/BasicEffectSample/Scenes/TextureNoFogScene.cs index 21b36127..407e4341 100644 --- a/Samples/BasicEffectSample/Scenes/TextureNoFogScene.cs +++ b/Samples/BasicEffectSample/Scenes/TextureNoFogScene.cs @@ -11,17 +11,11 @@ namespace BasicEffectSample.Scenes { public class TextureNoFogScene : BaseScene { - public override string Name - { - get - { - return "Texture"; - } - } + public override string Name + { + get { return "Texture"; } + } - private BasicEffect effect; - private VertexBuffer vertices; - private IndexBuffer indices; private Texture2D texture; public override void Initialize(ContentManager content, GraphicsDevice graphicsDevice) @@ -30,7 +24,7 @@ namespace BasicEffectSample.Scenes effect = new BasicEffect(graphicsDevice); vertices = new VertexBuffer(graphicsDevice, VertexPositionTexture.VertexDeclaration, 4, BufferUsage.WriteOnly); - vertices.SetData(new[] + vertices.SetData(new[] { new VertexPositionTexture(new Vector3(-5f, 0f, -5f), new Vector2(0, 0)), new VertexPositionTexture(new Vector3(-5f, 0f, 5f), new Vector2(0, 1)), @@ -39,21 +33,21 @@ namespace BasicEffectSample.Scenes }); indices = new IndexBuffer(graphicsDevice, IndexElementSize.SixteenBits, 6, BufferUsage.WriteOnly); - indices.SetData(new ushort[] { 0, 2, 1, 0, 3, 2 }); + indices.SetData(new ushort[] { 0, 2, 1, 0, 3, 2 }); } public override void Draw(GraphicsDevice graphicsDevice) - { - effect.World = Camera.World; - effect.View = Camera.View; - effect.Projection = Camera.Projection; + { + SetCameraMatrices(); effect.DiffuseColor = Color.White.ToVector3(); effect.EmissiveColor = Color.Black.ToVector3(); effect.LightingEnabled = false; effect.VertexColorEnabled = false; effect.TextureEnabled = true; - effect.FogEnabled = false; effect.Texture = texture; + + ToggleFog(false); + effect.CurrentTechnique.Passes[0].Apply(); graphicsDevice.Indices = indices; diff --git a/Samples/BasicEffectSample/Scenes/VertexColorFogScene.cs b/Samples/BasicEffectSample/Scenes/VertexColorFogScene.cs index c761a6a7..61fa2d53 100644 --- a/Samples/BasicEffectSample/Scenes/VertexColorFogScene.cs +++ b/Samples/BasicEffectSample/Scenes/VertexColorFogScene.cs @@ -11,24 +11,17 @@ namespace BasicEffectSample.Scenes { public class VertexColorFogScene : BaseScene { - public override string Name - { - get - { - return "VertexColor with Fog"; - } - } - - private BasicEffect effect; - private VertexBuffer vertices; - private IndexBuffer indices; + public override string Name + { + get { return "VertexColor with Fog"; } + } public override void Initialize(ContentManager content, GraphicsDevice graphicsDevice) { effect = new BasicEffect(graphicsDevice); vertices = new VertexBuffer(graphicsDevice, VertexPositionColor.VertexDeclaration, 4, BufferUsage.WriteOnly); - vertices.SetData(new[] + vertices.SetData(new[] { new VertexPositionColor(new Vector3(-5f, 0f, -5f), Color.Red), new VertexPositionColor(new Vector3(-5f, 0f, 5f), Color.Green), @@ -37,21 +30,16 @@ namespace BasicEffectSample.Scenes }); indices = new IndexBuffer(graphicsDevice, IndexElementSize.SixteenBits, 6, BufferUsage.WriteOnly); - indices.SetData(new ushort[] { 0, 2, 1, 0, 3, 2 }); + indices.SetData(new ushort[] { 0, 2, 1, 0, 3, 2 }); } public override void Draw(GraphicsDevice graphicsDevice) - { - effect.FogStart = 1f; - effect.FogEnd = 15f; - effect.FogColor = Color.Gray.ToVector3(); - effect.World = Camera.World; - effect.View = Camera.View; - effect.Projection = Camera.Projection; + { + ToggleFog(true); + SetCameraMatrices(); effect.EmissiveColor = Color.Black.ToVector3(); effect.VertexColorEnabled = true; effect.LightingEnabled = false; - effect.FogEnabled = true; effect.CurrentTechnique.Passes[0].Apply(); graphicsDevice.Indices = indices; diff --git a/Samples/BasicEffectSample/Scenes/VertexColorNoFogScene.cs b/Samples/BasicEffectSample/Scenes/VertexColorNoFogScene.cs index d66481b9..abec6b3b 100644 --- a/Samples/BasicEffectSample/Scenes/VertexColorNoFogScene.cs +++ b/Samples/BasicEffectSample/Scenes/VertexColorNoFogScene.cs @@ -11,24 +11,17 @@ namespace BasicEffectSample.Scenes { public class VertexColorNoFogScene : BaseScene { - public override string Name - { - get - { - return "VertexColor"; - } - } - - private BasicEffect effect; - private VertexBuffer vertices; - private IndexBuffer indices; + public override string Name + { + get { return "VertexColor"; } + } public override void Initialize(ContentManager content, GraphicsDevice graphicsDevice) { effect = new BasicEffect(graphicsDevice); vertices = new VertexBuffer(graphicsDevice, VertexPositionColor.VertexDeclaration, 4, BufferUsage.WriteOnly); - vertices.SetData(new[] + vertices.SetData(new[] { new VertexPositionColor(new Vector3(-5f, 0f, -5f), Color.Red), new VertexPositionColor(new Vector3(-5f, 0f, 5f), Color.Green), @@ -41,14 +34,12 @@ namespace BasicEffectSample.Scenes } public override void Draw(GraphicsDevice graphicsDevice) - { - effect.World = Camera.World; - effect.View = Camera.View; - effect.Projection = Camera.Projection; + { + SetCameraMatrices(); effect.VertexColorEnabled = true; effect.LightingEnabled = false; - effect.EmissiveColor = Color.Black.ToVector3(); - effect.FogEnabled = false; + effect.EmissiveColor = Color.Black.ToVector3(); + ToggleFog(false); effect.CurrentTechnique.Passes[0].Apply(); graphicsDevice.Indices = indices; diff --git a/Samples/BasicEffectSample/Scenes/VertexColorTextureFogScene.cs b/Samples/BasicEffectSample/Scenes/VertexColorTextureFogScene.cs index bb31d323..e580735c 100644 --- a/Samples/BasicEffectSample/Scenes/VertexColorTextureFogScene.cs +++ b/Samples/BasicEffectSample/Scenes/VertexColorTextureFogScene.cs @@ -11,17 +11,11 @@ namespace BasicEffectSample.Scenes { public class VertexColorTextureFogScene : BaseScene { - public override string Name - { - get - { - return "VertexColor with Texture and Fog"; - } - } + public override string Name + { + get { return "VertexColor with Texture and Fog"; } + } - private BasicEffect effect; - private VertexBuffer vertices; - private IndexBuffer indices; private Texture2D texture; public override void Initialize(ContentManager content, GraphicsDevice graphicsDevice) @@ -30,7 +24,7 @@ namespace BasicEffectSample.Scenes effect = new BasicEffect(graphicsDevice); vertices = new VertexBuffer(graphicsDevice, VertexPositionColorTexture.VertexDeclaration, 4, BufferUsage.WriteOnly); - vertices.SetData(new[] + vertices.SetData(new[] { new VertexPositionColorTexture(new Vector3(-5f, 0f, -5f), Color.Red, new Vector2(0, 0)), new VertexPositionColorTexture(new Vector3(-5f, 0f, 5f), Color.Green, new Vector2(0, 1)), @@ -39,23 +33,18 @@ namespace BasicEffectSample.Scenes }); indices = new IndexBuffer(graphicsDevice, IndexElementSize.SixteenBits, 6, BufferUsage.WriteOnly); - indices.SetData(new ushort[] { 0, 2, 1, 0, 3, 2 }); + indices.SetData(new ushort[] { 0, 2, 1, 0, 3, 2 }); } public override void Draw(GraphicsDevice graphicsDevice) - { - effect.FogStart = 1f; - effect.FogEnd = 15f; - effect.FogColor = Color.Gray.ToVector3(); - effect.World = Camera.World; - effect.View = Camera.View; - effect.Projection = Camera.Projection; + { + ToggleFog(true); + SetCameraMatrices(); effect.VertexColorEnabled = true; effect.EmissiveColor = Color.Black.ToVector3(); effect.LightingEnabled = false; effect.TextureEnabled = true; effect.Texture = texture; - effect.FogEnabled = true; effect.CurrentTechnique.Passes[0].Apply(); graphicsDevice.Indices = indices; diff --git a/Samples/BasicEffectSample/Scenes/VertexColorTextureNoFogScene.cs b/Samples/BasicEffectSample/Scenes/VertexColorTextureNoFogScene.cs index 23abe283..fe87ae2f 100644 --- a/Samples/BasicEffectSample/Scenes/VertexColorTextureNoFogScene.cs +++ b/Samples/BasicEffectSample/Scenes/VertexColorTextureNoFogScene.cs @@ -11,18 +11,12 @@ namespace BasicEffectSample.Scenes { public class VertexColorTextureNoFogScene : BaseScene { - public override string Name - { - get - { - return "VertexColor with Texture"; - } - } + public override string Name + { + get { return "VertexColor with Texture"; } + } - private BasicEffect effect; - private VertexBuffer vertices; - private IndexBuffer indices; - private Texture2D texture; + private Texture2D texture; public override void Initialize(ContentManager content, GraphicsDevice graphicsDevice) { @@ -30,7 +24,7 @@ namespace BasicEffectSample.Scenes effect = new BasicEffect(graphicsDevice); vertices = new VertexBuffer(graphicsDevice, VertexPositionColorTexture.VertexDeclaration, 4, BufferUsage.WriteOnly); - vertices.SetData(new[] + vertices.SetData(new[] { new VertexPositionColorTexture(new Vector3(-5f, 0f, -5f), Color.Red, new Vector2(0, 0)), new VertexPositionColorTexture(new Vector3(-5f, 0f, 5f), Color.Green, new Vector2(0, 1)), @@ -39,20 +33,18 @@ namespace BasicEffectSample.Scenes }); indices = new IndexBuffer(graphicsDevice, IndexElementSize.SixteenBits, 6, BufferUsage.WriteOnly); - indices.SetData(new ushort[] { 0, 2, 1, 0, 3, 2 }); + indices.SetData(new ushort[] { 0, 2, 1, 0, 3, 2 }); } public override void Draw(GraphicsDevice graphicsDevice) - { - effect.World = Camera.World; - effect.View = Camera.View; - effect.Projection = Camera.Projection; + { + SetCameraMatrices(); effect.VertexColorEnabled = true; effect.LightingEnabled = false; effect.EmissiveColor = Color.Black.ToVector3(); effect.TextureEnabled = true; - effect.Texture = texture; - effect.FogEnabled = false; + effect.Texture = texture; + ToggleFog(false); effect.CurrentTechnique.Passes[0].Apply(); graphicsDevice.Indices = indices; diff --git a/Samples/BasicEffectSample/VertexTypes/VertexPositionNormalColor.cs b/Samples/BasicEffectSample/VertexTypes/VertexPositionNormalColor.cs new file mode 100644 index 00000000..3099543a --- /dev/null +++ b/Samples/BasicEffectSample/VertexTypes/VertexPositionNormalColor.cs @@ -0,0 +1,44 @@ +using System; +using ANX.Framework; +using ANX.Framework.Graphics; + +// This file is part of the ANX.Framework created by the +// "ANX.Framework developer group" and released under the Ms-PL license. +// For details see: http://anxframework.codeplex.com/license + +namespace BasicEffectSample.VertexTypes +{ + public struct VertexPositionNormalColor : IVertexType + { + public Vector3 Position; + public Vector3 Normal; + public Color Color; + + public static readonly VertexDeclaration VertexDeclaration; + + VertexDeclaration IVertexType.VertexDeclaration + { + get { return VertexDeclaration; } + } + + public VertexPositionNormalColor(Vector3 position, Vector3 normal, Color color) + { + Position = position; + Normal = normal; + Color = color; + } + + static VertexPositionNormalColor() + { + VertexElement[] elements = + { + new VertexElement(0, VertexElementFormat.Vector3, VertexElementUsage.Position, 0), + new VertexElement(12, VertexElementFormat.Vector3, VertexElementUsage.Normal, 0), + new VertexElement(24, VertexElementFormat.Color, VertexElementUsage.Color, 0) + }; + + VertexDeclaration = new VertexDeclaration(28, elements); + VertexDeclaration.Name = "VertexPositionNormalColor.VertexDeclaration"; + } + } +} diff --git a/Samples/BasicEffectSample/VertexTypes/VertexPositionNormalColorTexture.cs b/Samples/BasicEffectSample/VertexTypes/VertexPositionNormalColorTexture.cs new file mode 100644 index 00000000..d62bbbd0 --- /dev/null +++ b/Samples/BasicEffectSample/VertexTypes/VertexPositionNormalColorTexture.cs @@ -0,0 +1,47 @@ +using System; +using ANX.Framework; +using ANX.Framework.Graphics; + +// This file is part of the ANX.Framework created by the +// "ANX.Framework developer group" and released under the Ms-PL license. +// For details see: http://anxframework.codeplex.com/license + +namespace BasicEffectSample.VertexTypes +{ + public struct VertexPositionNormalColorTexture : IVertexType + { + public Vector3 Position; + public Vector3 Normal; + public Color Color; + public Vector2 TextureCoordinate; + + public static readonly VertexDeclaration VertexDeclaration; + + VertexDeclaration IVertexType.VertexDeclaration + { + get { return VertexDeclaration; } + } + + public VertexPositionNormalColorTexture(Vector3 position, Vector3 normal, Color color, Vector2 texcoord) + { + Position = position; + Normal = normal; + Color = color; + TextureCoordinate = texcoord; + } + + static VertexPositionNormalColorTexture() + { + VertexElement[] elements = + { + new VertexElement(0, VertexElementFormat.Vector3, VertexElementUsage.Position, 0), + new VertexElement(12, VertexElementFormat.Vector3, VertexElementUsage.Normal, 0), + new VertexElement(24, VertexElementFormat.Color, VertexElementUsage.Color, 0), + new VertexElement(28, VertexElementFormat.Vector2, VertexElementUsage.TextureCoordinate, 0) + }; + + VertexDeclaration = new VertexDeclaration(36, elements); + VertexDeclaration.Name = "VertexPositionNormalColorTexture.VertexDeclaration"; + } + } +}