浏览代码

Add Grid to Animation Sample

Nikos Kastellanos 8 年之前
父节点
当前提交
b35b1805d5

+ 22 - 8
Samples/Animation/Game1.cs

@@ -5,6 +5,7 @@ using Microsoft.Xna.Framework;
 using Microsoft.Xna.Framework.Graphics;
 using Microsoft.Xna.Framework.Input;
 using tainicom.Aether.Animation;
+using tainicom.Aether.Shaders.Components;
 
 namespace Samples.Animation
 {
@@ -19,6 +20,8 @@ namespace Samples.Animation
         GraphicsDeviceManager graphics;
         SpriteBatch spriteBatch;
         SpriteFont font;
+        InfiniteGridComponent grid;
+
         Model _model_CPU;
         Model _model_GPU;
         Animations _animations;
@@ -41,7 +44,10 @@ namespace Samples.Animation
         {
             spriteBatch = new SpriteBatch(GraphicsDevice);
             font = Content.Load<SpriteFont>("font");
-            
+
+            grid = new InfiniteGridComponent(GraphicsDevice, Content);
+            grid.Initialize();
+                        
             _model_CPU = Content.Load<Model>("Dude/dude");
             _model_GPU = Content.Load<Model>("Dude/dude_GPU");
 
@@ -93,7 +99,21 @@ namespace Samples.Animation
         protected override void Draw(GameTime gameTime)
         {
             GraphicsDevice.Clear(Color.Black);
-            
+
+            float aspectRatio = graphics.GraphicsDevice.Viewport.AspectRatio;
+            Matrix projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(45.0f), aspectRatio, 0.01f, 500.0f);
+            Matrix view = Matrix.CreateLookAt(
+                new Vector3(0.0f, 35.0f, -Zoom),
+                new Vector3(0.0f, 35.0f, 0), 
+                Vector3.Up);
+
+            // Draw Grid
+            grid.Projection = projection;
+            grid.View = view;
+            //grid.EditMatrix = Matrix.Identity; // XY plane
+            grid.EditMatrix = Matrix.CreateFromAxisAngle(Vector3.UnitX, MathHelper.ToRadians(-90)); // XZ plane
+            grid.Draw(gameTime);
+
             GraphicsDevice.BlendState = BlendState.Opaque;
             GraphicsDevice.RasterizerState = RasterizerState.CullCounterClockwise;
             GraphicsDevice.DepthStencilState = DepthStencilState.Default;
@@ -105,14 +125,8 @@ namespace Samples.Animation
             else if (drawMode == DrawMode.GPU)
                 m = _model_GPU;
 
-            float aspectRatio = graphics.GraphicsDevice.Viewport.AspectRatio;
             Matrix[] transforms = new Matrix[m.Bones.Count];
             m.CopyAbsoluteBoneTransformsTo(transforms);
-            Matrix projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(45.0f), aspectRatio, 0.01f, 500.0f);
-            Matrix view = Matrix.CreateLookAt(
-                new Vector3(0.0f, 35.0f, -Zoom),
-                new Vector3(0.0f, 35.0f, 0), 
-                Vector3.Up);
 
             sw.Reset();
             sw.Start();

+ 4 - 0
Samples/Animation/Samples.Animation.WINDOWS.MG.csproj

@@ -68,6 +68,10 @@
       <Project>{f08d6d4c-60fb-4543-8d81-594080eb8051}</Project>
       <Name>Aether.Animation.WINDOWS.MG</Name>
     </ProjectReference>
+    <ProjectReference Include="..\..\Shaders\InfiniteGrid\Aether.Shaders.InfiniteGrid.WINDOWS.MG.csproj">
+      <Project>{08296a2e-becf-4db9-a518-8a613d07b80e}</Project>
+      <Name>Aether.Shaders.InfiniteGrid.WINDOWS.MG</Name>
+    </ProjectReference>
   </ItemGroup>
   <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
   <Import Project="$(MSBuildExtensionsPath)\MonoGame\v3.0\MonoGame.Content.Builder.targets" />

+ 4 - 0
Samples/Animation/Samples.Animation.WINDOWS.XNA.csproj

@@ -91,6 +91,10 @@
       <Project>{838D803F-F140-4763-A378-56DC27EDD5F3}</Project>
       <Name>Aether.Graphics.WINDOWS.XNA</Name>
     </ProjectReference>
+    <ProjectReference Include="..\..\Shaders\InfiniteGrid\Aether.Shaders.InfiniteGrid.WINDOWS.XNA.csproj">
+      <Project>{908EC8FF-B0ED-478A-B486-702E578AF64A}</Project>
+      <Name>Aether.Shaders.InfiniteGrid.WINDOWS.XNA</Name>
+    </ProjectReference>
     <ProjectReference Include="..\AnimationContent\Samples.AnimationContent.contentproj">
       <Name>Samples.AnimationContent %28Content%29</Name>
       <XnaReferenceType>Content</XnaReferenceType>