Browse Source

Add Audio3D and ShadowMapping samples

espes 13 years ago
parent
commit
29ffb097c1
40 changed files with 1611 additions and 0 deletions
  1. 104 0
      Audio3D/Audio3D.MacOS.csproj
  2. 195 0
      Audio3D/AudioManager.cs
  3. 74 0
      Audio3D/Cat.cs
  4. BIN
      Audio3D/Content/CatSound0.xnb
  5. BIN
      Audio3D/Content/CatSound1.xnb
  6. BIN
      Audio3D/Content/CatSound2.xnb
  7. BIN
      Audio3D/Content/CatTexture.xnb
  8. BIN
      Audio3D/Content/DogSound.xnb
  9. BIN
      Audio3D/Content/DogTexture.xnb
  10. BIN
      Audio3D/Content/checker.xnb
  11. 71 0
      Audio3D/Dog.cs
  12. 204 0
      Audio3D/Game.cs
  13. 27 0
      Audio3D/IAudioEmitter.cs
  14. 16 0
      Audio3D/Info.plist
  15. 45 0
      Audio3D/Main.cs
  16. 36 0
      Audio3D/Properties/AssemblyInfo.cs
  17. 79 0
      Audio3D/QuadDrawer.cs
  18. 109 0
      Audio3D/SpriteEntity.cs
  19. 44 0
      MonoGame.Samples.MacOS.sln
  20. BIN
      ShadowMapping/Content/DrawModel_0.xnb
  21. BIN
      ShadowMapping/Content/Grid_0.xnb
  22. BIN
      ShadowMapping/Content/dude.xnb
  23. BIN
      ShadowMapping/Content/grid.xnb
  24. BIN
      ShadowMapping/Content/headN_0.xnb
  25. BIN
      ShadowMapping/Content/headS_0.xnb
  26. BIN
      ShadowMapping/Content/head_0.xnb
  27. BIN
      ShadowMapping/Content/jacketN_0.xnb
  28. BIN
      ShadowMapping/Content/jacketS_0.xnb
  29. BIN
      ShadowMapping/Content/jacket_0.xnb
  30. BIN
      ShadowMapping/Content/pantsN_0.xnb
  31. BIN
      ShadowMapping/Content/pantsS_0.xnb
  32. BIN
      ShadowMapping/Content/pants_0.xnb
  33. BIN
      ShadowMapping/Content/upBodyC_0.xnb
  34. BIN
      ShadowMapping/Content/upBodyS_0.xnb
  35. BIN
      ShadowMapping/Content/upbodyN_0.xnb
  36. 16 0
      ShadowMapping/Info.plist
  37. 45 0
      ShadowMapping/Main.cs
  38. 25 0
      ShadowMapping/Properties/AssemblyInfo.cs
  39. 107 0
      ShadowMapping/ShadowMapping.MacOS.csproj
  40. 414 0
      ShadowMapping/ShadowMapping.cs

+ 104 - 0
Audio3D/Audio3D.MacOS.csproj

@@ -0,0 +1,104 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <ProductVersion>10.0.0</ProductVersion>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{D5C989FD-6AE3-417F-BCB9-7AE30F195A31}</ProjectGuid>
+    <ProjectTypeGuids>{948B3504-5B70-4649-8FE4-BDE1FB46EC69};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <OutputType>Exe</OutputType>
+    <RootNamespace>Audio3D</RootNamespace>
+    <AssemblyName>Audio3D</AssemblyName>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+    <DebugSymbols>true</DebugSymbols>
+    <DebugType>full</DebugType>
+    <Optimize>false</Optimize>
+    <OutputPath>bin\Debug</OutputPath>
+    <DefineConstants>DEBUG;</DefineConstants>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+    <EnablePackageSigning>false</EnablePackageSigning>
+    <IncludeMonoRuntime>false</IncludeMonoRuntime>
+    <ConsolePause>false</ConsolePause>
+    <EnableCodeSigning>false</EnableCodeSigning>
+    <CreatePackage>false</CreatePackage>
+    <CodeSigningKey>Mac Developer</CodeSigningKey>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+    <DebugType>none</DebugType>
+    <Optimize>true</Optimize>
+    <OutputPath>bin\Release</OutputPath>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+    <EnablePackageSigning>false</EnablePackageSigning>
+    <IncludeMonoRuntime>false</IncludeMonoRuntime>
+    <LinkMode>Full</LinkMode>
+    <ConsolePause>false</ConsolePause>
+    <EnableCodeSigning>false</EnableCodeSigning>
+    <CreatePackage>false</CreatePackage>
+    <CodeSigningKey>Mac Developer</CodeSigningKey>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'AppStore|AnyCPU' ">
+    <DebugType>none</DebugType>
+    <Optimize>true</Optimize>
+    <OutputPath>bin\AppStore</OutputPath>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+    <PackageSigningKey>3rd Party Mac Developer Installer</PackageSigningKey>
+    <IncludeMonoRuntime>true</IncludeMonoRuntime>
+    <LinkMode>Full</LinkMode>
+    <EnablePackageSigning>true</EnablePackageSigning>
+    <ConsolePause>false</ConsolePause>
+    <EnableCodeSigning>true</EnableCodeSigning>
+    <CreatePackage>true</CreatePackage>
+    <CodeSigningKey>3rd Party Mac Developer Application</CodeSigningKey>
+  </PropertyGroup>
+  <ItemGroup>
+    <Reference Include="System" />
+    <Reference Include="System.Xml" />
+    <Reference Include="System.Core" />
+    <Reference Include="System.Xml.Linq" />
+    <Reference Include="System.Drawing" />
+    <Reference Include="MonoMac" />
+  </ItemGroup>
+  <ItemGroup>
+    <ProjectReference Include="..\..\MonoGame.Framework\MonoGame.Framework.MacOS.csproj">
+      <Project>{36C538E6-C32A-4A8D-A39C-566173D7118E}</Project>
+      <Name>MonoGame.Framework.MacOS</Name>
+    </ProjectReference>
+    <ProjectReference Include="..\..\ThirdParty\Lidgren.Network\Lidgren.Network.MacOS.csproj">
+      <Project>{AE483C29-042E-4226-BA52-D247CE7676DA}</Project>
+      <Name>Lidgren.Network.MacOS</Name>
+    </ProjectReference>
+  </ItemGroup>
+  <ItemGroup>
+    <Compile Include="Main.cs" />
+    <Compile Include="Properties\AssemblyInfo.cs" />
+    <Compile Include="AudioManager.cs" />
+    <Compile Include="Cat.cs" />
+    <Compile Include="Dog.cs" />
+    <Compile Include="Game.cs" />
+    <Compile Include="IAudioEmitter.cs" />
+    <Compile Include="QuadDrawer.cs" />
+    <Compile Include="SpriteEntity.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="Info.plist" />
+  </ItemGroup>
+  <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
+  <Import Project="$(MSBuildExtensionsPath)\Mono\MonoMac\v0.0\Mono.MonoMac.targets" />
+  <ItemGroup>
+    <Folder Include="Content\" />
+  </ItemGroup>
+  <ItemGroup>
+    <Content Include="Content\CatSound0.xnb" />
+    <Content Include="Content\CatSound1.xnb" />
+    <Content Include="Content\CatSound2.xnb" />
+    <Content Include="Content\CatTexture.xnb" />
+    <Content Include="Content\DogSound.xnb" />
+    <Content Include="Content\DogTexture.xnb" />
+    <Content Include="Content\checker.xnb" />
+  </ItemGroup>
+</Project>

+ 195 - 0
Audio3D/AudioManager.cs

@@ -0,0 +1,195 @@
+#region File Description
+//-----------------------------------------------------------------------------
+// AudioManager.cs
+//
+// Microsoft XNA Community Game Platform
+// Copyright (C) Microsoft Corporation. All rights reserved.
+//-----------------------------------------------------------------------------
+#endregion
+
+#region Using Statements
+using System.Collections.Generic;
+using Microsoft.Xna.Framework;
+using Microsoft.Xna.Framework.Audio;
+#endregion
+
+namespace Audio3D
+{
+    /// <summary>
+    /// Audio manager keeps track of what 3D sounds are playing, updating
+    /// their settings as the camera and entities move around the world, and
+    /// automatically disposing sound effect instances after they finish playing.
+    /// </summary>
+    public class AudioManager : Microsoft.Xna.Framework.GameComponent
+    {
+        #region Fields
+
+
+        // List of all the sound effects that will be loaded into this manager.
+        static string[] soundNames =
+        {
+            "CatSound0",
+            "CatSound1",
+            "CatSound2",
+            "DogSound",
+        };
+
+
+        // The listener describes the ear which is hearing 3D sounds.
+        // This is usually set to match the camera.
+        public AudioListener Listener
+        {
+            get { return listener; }
+        }
+
+        AudioListener listener = new AudioListener();
+
+
+        // The emitter describes an entity which is making a 3D sound.
+        AudioEmitter emitter = new AudioEmitter();
+
+
+        // Store all the sound effects that are available to be played.
+        Dictionary<string, SoundEffect> soundEffects = new Dictionary<string, SoundEffect>();
+
+        
+        // Keep track of all the 3D sounds that are currently playing.
+        List<ActiveSound> activeSounds = new List<ActiveSound>();
+
+
+        #endregion
+
+
+        public AudioManager(Game game)
+            : base(game)
+        { }
+
+
+        /// <summary>
+        /// Initializes the audio manager.
+        /// </summary>
+        public override void Initialize()
+        {
+            // Set the scale for 3D audio so it matches the scale of our game world.
+            // DistanceScale controls how much sounds change volume as you move further away.
+            // DopplerScale controls how much sounds change pitch as you move past them.
+            SoundEffect.DistanceScale = 2000;
+            SoundEffect.DopplerScale = 0.1f;
+
+            // Load all the sound effects.
+            foreach (string soundName in soundNames)
+            {
+                soundEffects.Add(soundName, Game.Content.Load<SoundEffect>(soundName));
+            }
+
+            base.Initialize();
+        }
+
+
+        /// <summary>
+        /// Unloads the sound effect data.
+        /// </summary>
+        protected override void Dispose(bool disposing)
+        {
+            try
+            {
+                if (disposing)
+                {
+                    foreach (SoundEffect soundEffect in soundEffects.Values)
+                    {
+                        soundEffect.Dispose();
+                    }
+
+                    soundEffects.Clear();
+                }
+            }
+            finally
+            {
+                base.Dispose(disposing);
+            }
+        }
+
+        
+        /// <summary>
+        /// Updates the state of the 3D audio system.
+        /// </summary>
+        public override void Update(GameTime gameTime)
+        {
+            // Loop over all the currently playing 3D sounds.
+            int index = 0;
+
+            while (index < activeSounds.Count)
+            {
+                ActiveSound activeSound = activeSounds[index];
+
+                if (activeSound.Instance.State == SoundState.Stopped)
+                {
+                    // If the sound has stopped playing, dispose it.
+                    activeSound.Instance.Dispose();
+
+                    // Remove it from the active list.
+                    activeSounds.RemoveAt(index);
+                }
+                else
+                {
+                    // If the sound is still playing, update its 3D settings.
+                    Apply3D(activeSound);
+
+                    index++;
+                }
+            }
+
+            base.Update(gameTime);
+        }
+
+
+        /// <summary>
+        /// Triggers a new 3D sound.
+        /// </summary>
+        public SoundEffectInstance Play3DSound(string soundName, bool isLooped, IAudioEmitter emitter)
+        {
+            ActiveSound activeSound = new ActiveSound();
+
+            // Fill in the instance and emitter fields.
+            activeSound.Instance = soundEffects[soundName].CreateInstance();
+            activeSound.Instance.IsLooped = isLooped;
+
+            activeSound.Emitter = emitter;
+
+            // Set the 3D position of this sound, and then play it.
+            Apply3D(activeSound);
+
+            activeSound.Instance.Play();
+
+            // Remember that this sound is now active.
+            activeSounds.Add(activeSound);
+
+            return activeSound.Instance;
+        }
+
+
+        /// <summary>
+        /// Updates the position and velocity settings of a 3D sound.
+        /// </summary>
+        private void Apply3D(ActiveSound activeSound)
+        {
+            emitter.Position = activeSound.Emitter.Position;
+            emitter.Forward = activeSound.Emitter.Forward;
+            emitter.Up = activeSound.Emitter.Up;
+            emitter.Velocity = activeSound.Emitter.Velocity;
+
+            activeSound.Instance.Apply3D(listener, emitter);
+        }
+
+
+        /// <summary>
+        /// Internal helper class for keeping track of an active 3D sound,
+        /// and remembering which emitter object it is attached to.
+        /// </summary>
+        private class ActiveSound
+        {
+            public SoundEffectInstance Instance;
+            public IAudioEmitter Emitter;
+        }
+    }
+}

+ 74 - 0
Audio3D/Cat.cs

@@ -0,0 +1,74 @@
+#region File Description
+//-----------------------------------------------------------------------------
+// Cat.cs
+//
+// Microsoft XNA Community Game Platform
+// Copyright (C) Microsoft Corporation. All rights reserved.
+//-----------------------------------------------------------------------------
+#endregion
+
+#region Using Statements
+using System;
+using Microsoft.Xna.Framework;
+#endregion
+
+namespace Audio3D
+{
+    /// <summary>
+    /// Entity class which moves in a circle and plays cat sounds.
+    /// This uses a single-shot sound, which will stop automatically
+    /// when it finishes playing. See the Dog class for an example of
+    /// using a looping sound.
+    /// </summary>
+    class Cat : SpriteEntity
+    {
+        #region Fields
+
+        // How long until we should play the next sound.
+        TimeSpan timeDelay = TimeSpan.Zero;
+
+        // Random number generator for choosing between sound variations.
+        static Random random = new Random();
+
+        #endregion
+
+
+        /// <summary>
+        /// Updates the position of the cat, and plays sounds.
+        /// </summary>
+        public override void Update(GameTime gameTime, AudioManager audioManager)
+        {
+            // Move the cat in a big circle.
+            double time = gameTime.TotalGameTime.TotalSeconds;
+
+            float dx = (float)-Math.Cos(time);
+            float dz = (float)-Math.Sin(time);
+
+            Vector3 newPosition = new Vector3(dx, 0, dz) * 6000;
+
+            // Update entity position and velocity.
+            Velocity = newPosition - Position;
+            Position = newPosition;
+            if (Velocity == Vector3.Zero)
+                Forward = Vector3.Forward;
+            else
+                Forward = Vector3.Normalize(Velocity);
+
+            Up = Vector3.Up;
+
+            // If the time delay has run out, trigger another single-shot sound.
+            timeDelay -= gameTime.ElapsedGameTime;
+
+            if (timeDelay < TimeSpan.Zero)
+            {
+                // For variety, randomly choose between three slightly different
+                // variants of the sound (CatSound0, CatSound1, and CatSound2).
+                string soundName = "CatSound" + random.Next(3);
+
+                audioManager.Play3DSound(soundName, false, this);
+
+                timeDelay += TimeSpan.FromSeconds(1.25f);
+            }
+        }
+    }
+}

BIN
Audio3D/Content/CatSound0.xnb


BIN
Audio3D/Content/CatSound1.xnb


BIN
Audio3D/Content/CatSound2.xnb


BIN
Audio3D/Content/CatTexture.xnb


BIN
Audio3D/Content/DogSound.xnb


BIN
Audio3D/Content/DogTexture.xnb


BIN
Audio3D/Content/checker.xnb


+ 71 - 0
Audio3D/Dog.cs

@@ -0,0 +1,71 @@
+#region File Description
+//-----------------------------------------------------------------------------
+// Dog.cs
+//
+// Microsoft XNA Community Game Platform
+// Copyright (C) Microsoft Corporation. All rights reserved.
+//-----------------------------------------------------------------------------
+#endregion
+
+#region Using Statements
+using System;
+using Microsoft.Xna.Framework;
+using Microsoft.Xna.Framework.Audio;
+#endregion
+
+namespace Audio3D
+{
+    /// Entity class which sits in one place and plays dog sounds.
+    /// This uses a looping sound, which must be explicitly stopped
+    /// to prevent it going on forever. See the Cat class for an
+    /// example of using a single-shot sound.
+    class Dog : SpriteEntity
+    {
+        #region Fields
+
+        // How long until we should start or stop the sound.
+        TimeSpan timeDelay = TimeSpan.Zero;
+
+        // The sound which is currently playing, if any.
+        SoundEffectInstance activeSound = null;
+
+        #endregion
+
+
+        /// <summary>
+        /// Updates the position of the dog, and plays sounds.
+        /// </summary>
+        public override void Update(GameTime gameTime, AudioManager audioManager)
+        {
+            // Set the entity to a fixed position.
+            Position = new Vector3(0, 0, -4000);
+            Forward = Vector3.Forward;
+            Up = Vector3.Up;
+            Velocity = Vector3.Zero;
+
+            // If the time delay has run out, start or stop the looping sound.
+            // This would normally go on forever, but we stop it after a six
+            // second delay, then start it up again after four more seconds.
+            timeDelay -= gameTime.ElapsedGameTime;
+
+            if (timeDelay < TimeSpan.Zero)
+            {
+                if (activeSound == null)
+                {
+                    // If no sound is currently playing, trigger one.
+                    activeSound = audioManager.Play3DSound("DogSound", true, this);
+
+                    timeDelay += TimeSpan.FromSeconds(6);
+                }
+                else
+                {
+                    // Otherwise stop the current sound.
+                    activeSound.Stop(false);
+                    activeSound = null;
+
+                    timeDelay += TimeSpan.FromSeconds(4);
+                }
+            }
+        }
+    }
+}

+ 204 - 0
Audio3D/Game.cs

@@ -0,0 +1,204 @@
+#region File Description
+//-----------------------------------------------------------------------------
+// Game.cs
+//
+// Microsoft XNA Community Game Platform
+// Copyright (C) Microsoft Corporation. All rights reserved.
+//-----------------------------------------------------------------------------
+#endregion
+
+#region Using Statements
+using Microsoft.Xna.Framework;
+using Microsoft.Xna.Framework.Content;
+using Microsoft.Xna.Framework.Graphics;
+using Microsoft.Xna.Framework.Input;
+#endregion
+
+namespace Audio3D
+{
+    /// <summary>
+    /// Sample showing how to implement 3D audio.
+    /// </summary>
+    public class Audio3DGame : Microsoft.Xna.Framework.Game
+    {
+        #region Fields
+
+        GraphicsDeviceManager graphics;
+
+        AudioManager audioManager;
+
+        SpriteEntity cat;
+        SpriteEntity dog;
+
+        Texture2D checkerTexture;
+
+        QuadDrawer quadDrawer;
+
+        Vector3 cameraPosition = new Vector3(0, 512, 0);
+        Vector3 cameraForward = Vector3.Forward;
+        Vector3 cameraUp = Vector3.Up;
+        Vector3 cameraVelocity = Vector3.Zero;
+
+        KeyboardState currentKeyboardState;
+        GamePadState currentGamePadState;
+
+        #endregion
+
+        #region Initialization
+
+
+        public Audio3DGame()
+        {
+            Content.RootDirectory = "Content";
+
+            graphics = new GraphicsDeviceManager(this);
+
+            audioManager = new AudioManager(this);
+
+            Components.Add(audioManager);
+
+            cat = new Cat();
+            dog = new Dog();
+        }
+
+
+        /// <summary>
+        /// Load your graphics content.
+        /// </summary>
+        protected override void LoadContent()
+        {
+            cat.Texture = Content.Load<Texture2D>("CatTexture");
+            dog.Texture = Content.Load<Texture2D>("DogTexture");
+
+            checkerTexture = Content.Load<Texture2D>("checker");
+
+            quadDrawer = new QuadDrawer(graphics.GraphicsDevice);
+        }
+
+
+        #endregion
+
+        #region Update and Draw
+
+
+        /// <summary>
+        /// Allows the game to run logic.
+        /// </summary>
+        protected override void Update(GameTime gameTime)
+        {
+            HandleInput();
+
+            UpdateCamera();
+
+            // Tell the AudioManager about the new camera position.
+            audioManager.Listener.Position = cameraPosition;
+            audioManager.Listener.Forward = cameraForward;
+            audioManager.Listener.Up = cameraUp;
+            audioManager.Listener.Velocity = cameraVelocity;
+
+            // Tell our game entities to move around and play sounds.
+            cat.Update(gameTime, audioManager);
+            dog.Update(gameTime, audioManager);
+
+            base.Update(gameTime);
+        }
+
+
+        /// <summary>
+        /// This is called when the game should draw itself.
+        /// </summary>
+        protected override void Draw(GameTime gameTime)
+        {
+            GraphicsDevice device = graphics.GraphicsDevice;
+
+            device.Clear(Color.CornflowerBlue);
+
+            device.BlendState = BlendState.AlphaBlend;
+
+            // Compute camera matrices.
+            Matrix view = Matrix.CreateLookAt(cameraPosition,
+                                              cameraPosition + cameraForward,
+                                              cameraUp);
+
+            Matrix projection = Matrix.CreatePerspectiveFieldOfView(1, device.Viewport.AspectRatio,
+                                                                    1, 100000);
+
+            // Draw the checkered ground polygon.
+            Matrix groundTransform = Matrix.CreateScale(20000) *
+                                     Matrix.CreateRotationX(MathHelper.PiOver2);
+
+            quadDrawer.DrawQuad(checkerTexture, 32, groundTransform, view, projection);
+
+            // Draw the game entities.
+            cat.Draw(quadDrawer, cameraPosition, view, projection);
+            dog.Draw(quadDrawer, cameraPosition, view, projection);
+
+            base.Draw(gameTime);
+        }
+
+
+        #endregion
+
+        #region Handle Input
+
+
+        /// <summary>
+        /// Handles input for quitting the game.
+        /// </summary>
+        void HandleInput()
+        {
+            currentKeyboardState = Keyboard.GetState();
+            currentGamePadState = GamePad.GetState(PlayerIndex.One);
+
+            // Check for exit.
+            if (currentKeyboardState.IsKeyDown(Keys.Escape) ||
+                currentGamePadState.Buttons.Back == ButtonState.Pressed)
+            {
+                Exit();
+            }
+        }
+
+
+        /// <summary>
+        /// Handles input for moving the camera.
+        /// </summary>
+        void UpdateCamera()
+        {
+            const float turnSpeed = 0.05f;
+            const float accelerationSpeed = 4;
+            const float frictionAmount = 0.98f;
+
+            // Turn left or right.
+            float turn = -currentGamePadState.ThumbSticks.Left.X * turnSpeed;
+
+            if (currentKeyboardState.IsKeyDown(Keys.Left))
+                turn += turnSpeed;
+
+            if (currentKeyboardState.IsKeyDown(Keys.Right))
+                turn -= turnSpeed;
+
+            cameraForward = Vector3.TransformNormal(cameraForward,
+                                                    Matrix.CreateRotationY(turn));
+
+            // Accelerate forward or backward.
+            float accel = currentGamePadState.ThumbSticks.Left.Y * accelerationSpeed;
+
+            if (currentKeyboardState.IsKeyDown(Keys.Up))
+                accel += accelerationSpeed;
+
+            if (currentKeyboardState.IsKeyDown(Keys.Down))
+                accel -= accelerationSpeed;
+
+            cameraVelocity += cameraForward * accel;
+
+            // Add velocity to the current position.
+            cameraPosition += cameraVelocity;
+
+            // Apply the friction force.
+            cameraVelocity *= frictionAmount;
+        }
+
+
+        #endregion
+    }
+}

+ 27 - 0
Audio3D/IAudioEmitter.cs

@@ -0,0 +1,27 @@
+#region File Description
+//-----------------------------------------------------------------------------
+// IAudioEmitter.cs
+//
+// Microsoft XNA Community Game Platform
+// Copyright (C) Microsoft Corporation. All rights reserved.
+//-----------------------------------------------------------------------------
+#endregion
+
+#region Using Statements
+using Microsoft.Xna.Framework;
+#endregion 
+
+namespace Audio3D
+{
+    /// <summary>
+    /// Interface used by the AudioManager to look up the position
+    /// and velocity of entities that can emit 3D sounds.
+    /// </summary>
+    public interface IAudioEmitter
+    {
+        Vector3 Position { get; }
+        Vector3 Forward { get; }
+        Vector3 Up { get; }
+        Vector3 Velocity { get; }
+    }
+}

+ 16 - 0
Audio3D/Info.plist

@@ -0,0 +1,16 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+	<key>CFBundleIdentifier</key>
+	<string>com.yourcompany.Audio3D</string>
+	<key>CFBundleName</key>
+	<string>Audio3D</string>
+	<key>CFBundleVersion</key>
+	<string>1</string>
+	<key>LSMinimumSystemVersion</key>
+	<string>10.6</string>
+	<key>NSPrincipalClass</key>
+	<string>NSApplication</string>
+</dict>
+</plist>

+ 45 - 0
Audio3D/Main.cs

@@ -0,0 +1,45 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+
+using MonoMac.AppKit;
+using MonoMac.Foundation;
+
+namespace Audio3D
+{
+	static class Program
+	{
+		/// <summary>
+		/// The main entry point for the application.
+		/// </summary>
+		static void Main (string[] args)
+		{
+			NSApplication.Init ();
+			
+			using (var p = new NSAutoreleasePool ()) {
+				NSApplication.SharedApplication.Delegate = new AppDelegate ();
+				NSApplication.Main (args);
+			}
+
+
+		}
+	}
+
+	class AppDelegate : NSApplicationDelegate
+	{
+		Audio3DGame game;
+
+		public override void FinishedLaunching (MonoMac.Foundation.NSObject notification)
+		{
+			game = new Audio3DGame ();
+			game.Run ();
+		}
+		
+		public override bool ApplicationShouldTerminateAfterLastWindowClosed (NSApplication sender)
+		{
+			return true;
+		}
+	}  
+}
+
+

+ 36 - 0
Audio3D/Properties/AssemblyInfo.cs

@@ -0,0 +1,36 @@
+#region File Description
+//-----------------------------------------------------------------------------
+// AssemblyInfo.cs
+//
+// Microsoft XNA Community Game Platform
+// Copyright (C) Microsoft Corporation. All rights reserved.
+//-----------------------------------------------------------------------------
+#endregion
+
+#region Using Statements
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+#endregion
+
+// General Information about an assembly is controlled through the following 
+// set of attributes. Change these attribute values to modify the information
+// associated with an assembly.
+[assembly: AssemblyTitle("Audio 3D")]
+[assembly: AssemblyProduct("Audio 3D")]
+[assembly: AssemblyDescription("This sample shows how to position sounds in 3D space, implementing panning, Doppler, and distance attenuation effects.")]
+[assembly: AssemblyCompany("Microsoft")]
+
+[assembly: AssemblyCopyright("Copyright © Microsoft 2007")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+
+// Version information for an assembly consists of the following four values:
+//
+//      Major Version
+//      Minor Version 
+//      Build Number
+//      Revision
+//
+[assembly: AssemblyVersion("1.0.0.0")]

+ 79 - 0
Audio3D/QuadDrawer.cs

@@ -0,0 +1,79 @@
+#region File Description
+//-----------------------------------------------------------------------------
+// QuadDrawer.cs
+//
+// Microsoft XNA Community Game Platform
+// Copyright (C) Microsoft Corporation. All rights reserved.
+//-----------------------------------------------------------------------------
+#endregion
+
+#region Using Statements
+using Microsoft.Xna.Framework;
+using Microsoft.Xna.Framework.Graphics;
+#endregion
+
+namespace Audio3D
+{
+    /// <summary>
+    /// Helper for drawing 3D quadrilaterals. This is used to draw the cat
+    /// and dog billboard sprites, and also the checkered ground polygon.
+    /// </summary>
+    class QuadDrawer
+    {
+        #region Fields
+
+        GraphicsDevice graphicsDevice;
+        AlphaTestEffect effect;
+        VertexPositionTexture[] vertices;
+
+        #endregion
+
+
+        /// <summary>
+        /// Constructs a new quadrilateral drawing worker.
+        /// </summary>
+        public QuadDrawer(GraphicsDevice device)
+        {
+            graphicsDevice = device;
+
+            effect = new AlphaTestEffect(device);
+
+            effect.AlphaFunction = CompareFunction.Greater;
+            effect.ReferenceAlpha = 128;
+
+            // Preallocate an array of four vertices.
+            vertices = new VertexPositionTexture[4];
+
+            vertices[0].Position = new Vector3(1, 1, 0);
+            vertices[1].Position = new Vector3(-1, 1, 0);
+            vertices[2].Position = new Vector3(1, -1, 0);
+            vertices[3].Position = new Vector3(-1, -1, 0);
+        }
+
+
+        /// <summary>
+        /// Draws a quadrilateral as part of the 3D world.
+        /// </summary>
+        public void DrawQuad(Texture2D texture, float textureRepeats,
+                             Matrix world, Matrix view, Matrix projection)
+        {
+            // Set our effect to use the specified texture and camera matrices.
+            effect.Texture = texture;
+
+            effect.World = world;
+            effect.View = view;
+            effect.Projection = projection;
+
+            // Update our vertex array to use the specified number of texture repeats.
+            vertices[0].TextureCoordinate = new Vector2(0, 0);
+            vertices[1].TextureCoordinate = new Vector2(textureRepeats, 0);
+            vertices[2].TextureCoordinate = new Vector2(0, textureRepeats);
+            vertices[3].TextureCoordinate = new Vector2(textureRepeats, textureRepeats);
+
+            // Draw the quad.
+            effect.CurrentTechnique.Passes[0].Apply();
+
+            graphicsDevice.DrawUserPrimitives(PrimitiveType.TriangleStrip, vertices, 0, 2);
+        }
+    }
+}

+ 109 - 0
Audio3D/SpriteEntity.cs

@@ -0,0 +1,109 @@
+#region File Description
+//-----------------------------------------------------------------------------
+// SpriteEntity.cs
+//
+// Microsoft XNA Community Game Platform
+// Copyright (C) Microsoft Corporation. All rights reserved.
+//-----------------------------------------------------------------------------
+#endregion
+
+#region Using Statements
+using Microsoft.Xna.Framework;
+using Microsoft.Xna.Framework.Graphics;
+#endregion
+
+namespace Audio3D
+{
+    /// <summary>
+    /// Base class for game entities that are displayed as billboard sprites,
+    /// and which can emit 3D sounds. The Cat and Dog classes both derive from this.
+    /// </summary>
+    abstract class SpriteEntity : IAudioEmitter
+    {
+        #region Properties
+
+
+        /// <summary>
+        /// Gets or sets the 3D position of the entity.
+        /// </summary>
+        public Vector3 Position
+        {
+            get { return position; }
+            set { position = value; }
+        }
+
+        Vector3 position;
+
+
+        /// <summary>
+        /// Gets or sets which way the entity is facing.
+        /// </summary>
+        public Vector3 Forward
+        {
+            get { return forward; }
+            set { forward = value; }
+        }
+
+        Vector3 forward;
+
+
+        /// <summary>
+        /// Gets or sets the orientation of this entity.
+        /// </summary>
+        public Vector3 Up
+        {
+            get { return up; }
+            set { up = value; }
+        }
+
+        Vector3 up;
+
+        
+        /// <summary>
+        /// Gets or sets how fast this entity is moving.
+        /// </summary>
+        public Vector3 Velocity
+        {
+            get { return velocity; }
+            protected set { velocity = value; }
+        }
+
+        Vector3 velocity;
+
+
+        /// <summary>
+        /// Gets or sets the texture used to display this entity.
+        /// </summary>
+        public Texture2D Texture
+        {
+            get { return texture; }
+            set { texture = value; }
+        }
+
+        Texture2D texture;
+
+
+        #endregion
+
+
+        /// <summary>
+        /// Updates the position of the entity, and allows it to play sounds.
+        /// </summary>
+        public abstract void Update(GameTime gameTime, AudioManager audioManager);
+
+
+        /// <summary>
+        /// Draws the entity as a billboard sprite.
+        /// </summary>
+        public void Draw(QuadDrawer quadDrawer, Vector3 cameraPosition,
+                         Matrix view, Matrix projection)
+        {
+            Matrix world = Matrix.CreateTranslation(0, 1, 0) *
+                           Matrix.CreateScale(800) *
+                           Matrix.CreateConstrainedBillboard(Position, cameraPosition,
+                                                             Up, null, null);
+
+            quadDrawer.DrawQuad(Texture, 1, world, view, projection);
+        }
+    }
+}

+ 44 - 0
MonoGame.Samples.MacOS.sln

@@ -107,6 +107,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FarseerSamples.MacOS", "Far
 EndProject
 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BloomSample.MacOS", "BloomSample\BloomSample.MacOS.csproj", "{A93553D9-11E5-4B0B-9809-4E4765D5FD8F}"
 EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Audio3D.MacOS", "Audio3D\Audio3D.MacOS.csproj", "{D5C989FD-6AE3-417F-BCB9-7AE30F195A31}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ShadowMapping.MacOS", "ShadowMapping\ShadowMapping.MacOS.csproj", "{36473816-E068-4D38-84F3-F5564BA77FF8}"
+EndProject
 Global
 	GlobalSection(SolutionConfigurationPlatforms) = preSolution
 		Debug|Any CPU = Debug|Any CPU
@@ -321,6 +325,26 @@ Global
 		{3388FF68-6F15-4F36-B226-7823E5309E92}.Release|iPhoneSimulator.Build.0 = Release|Any CPU
 		{3388FF68-6F15-4F36-B226-7823E5309E92}.Release|x86.ActiveCfg = Release|Any CPU
 		{3388FF68-6F15-4F36-B226-7823E5309E92}.Release|x86.Build.0 = Release|Any CPU
+		{36473816-E068-4D38-84F3-F5564BA77FF8}.AppStore|Any CPU.ActiveCfg = AppStore|Any CPU
+		{36473816-E068-4D38-84F3-F5564BA77FF8}.AppStore|Any CPU.Build.0 = AppStore|Any CPU
+		{36473816-E068-4D38-84F3-F5564BA77FF8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{36473816-E068-4D38-84F3-F5564BA77FF8}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{36473816-E068-4D38-84F3-F5564BA77FF8}.Debug|iPhone.ActiveCfg = Debug|Any CPU
+		{36473816-E068-4D38-84F3-F5564BA77FF8}.Debug|iPhone.Build.0 = Debug|Any CPU
+		{36473816-E068-4D38-84F3-F5564BA77FF8}.Debug|iPhoneSimulator.ActiveCfg = Debug|Any CPU
+		{36473816-E068-4D38-84F3-F5564BA77FF8}.Debug|iPhoneSimulator.Build.0 = Debug|Any CPU
+		{36473816-E068-4D38-84F3-F5564BA77FF8}.Debug|x86.ActiveCfg = Debug|Any CPU
+		{36473816-E068-4D38-84F3-F5564BA77FF8}.Debug|x86.Build.0 = Debug|Any CPU
+		{36473816-E068-4D38-84F3-F5564BA77FF8}.Distribution|Any CPU.ActiveCfg = Debug|Any CPU
+		{36473816-E068-4D38-84F3-F5564BA77FF8}.Distribution|Any CPU.Build.0 = Debug|Any CPU
+		{36473816-E068-4D38-84F3-F5564BA77FF8}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{36473816-E068-4D38-84F3-F5564BA77FF8}.Release|Any CPU.Build.0 = Release|Any CPU
+		{36473816-E068-4D38-84F3-F5564BA77FF8}.Release|iPhone.ActiveCfg = Release|Any CPU
+		{36473816-E068-4D38-84F3-F5564BA77FF8}.Release|iPhone.Build.0 = Release|Any CPU
+		{36473816-E068-4D38-84F3-F5564BA77FF8}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU
+		{36473816-E068-4D38-84F3-F5564BA77FF8}.Release|iPhoneSimulator.Build.0 = Release|Any CPU
+		{36473816-E068-4D38-84F3-F5564BA77FF8}.Release|x86.ActiveCfg = Release|Any CPU
+		{36473816-E068-4D38-84F3-F5564BA77FF8}.Release|x86.Build.0 = Release|Any CPU
 		{36C538E6-C32A-4A8D-A39C-566173D7118E}.AppStore|Any CPU.ActiveCfg = Debug|Any CPU
 		{36C538E6-C32A-4A8D-A39C-566173D7118E}.AppStore|Any CPU.Build.0 = Debug|Any CPU
 		{36C538E6-C32A-4A8D-A39C-566173D7118E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
@@ -773,6 +797,26 @@ Global
 		{D03F3BAF-E4D0-4B6B-A567-9A0E2F882335}.Release|Any CPU.Build.0 = Release|Any CPU
 		{D03F3BAF-E4D0-4B6B-A567-9A0E2F882335}.Release|x86.ActiveCfg = Release|Any CPU
 		{D03F3BAF-E4D0-4B6B-A567-9A0E2F882335}.Release|x86.Build.0 = Release|Any CPU
+		{D5C989FD-6AE3-417F-BCB9-7AE30F195A31}.AppStore|Any CPU.ActiveCfg = AppStore|Any CPU
+		{D5C989FD-6AE3-417F-BCB9-7AE30F195A31}.AppStore|Any CPU.Build.0 = AppStore|Any CPU
+		{D5C989FD-6AE3-417F-BCB9-7AE30F195A31}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{D5C989FD-6AE3-417F-BCB9-7AE30F195A31}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{D5C989FD-6AE3-417F-BCB9-7AE30F195A31}.Debug|iPhone.ActiveCfg = Debug|Any CPU
+		{D5C989FD-6AE3-417F-BCB9-7AE30F195A31}.Debug|iPhone.Build.0 = Debug|Any CPU
+		{D5C989FD-6AE3-417F-BCB9-7AE30F195A31}.Debug|iPhoneSimulator.ActiveCfg = Debug|Any CPU
+		{D5C989FD-6AE3-417F-BCB9-7AE30F195A31}.Debug|iPhoneSimulator.Build.0 = Debug|Any CPU
+		{D5C989FD-6AE3-417F-BCB9-7AE30F195A31}.Debug|x86.ActiveCfg = Debug|Any CPU
+		{D5C989FD-6AE3-417F-BCB9-7AE30F195A31}.Debug|x86.Build.0 = Debug|Any CPU
+		{D5C989FD-6AE3-417F-BCB9-7AE30F195A31}.Distribution|Any CPU.ActiveCfg = Debug|Any CPU
+		{D5C989FD-6AE3-417F-BCB9-7AE30F195A31}.Distribution|Any CPU.Build.0 = Debug|Any CPU
+		{D5C989FD-6AE3-417F-BCB9-7AE30F195A31}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{D5C989FD-6AE3-417F-BCB9-7AE30F195A31}.Release|Any CPU.Build.0 = Release|Any CPU
+		{D5C989FD-6AE3-417F-BCB9-7AE30F195A31}.Release|iPhone.ActiveCfg = Release|Any CPU
+		{D5C989FD-6AE3-417F-BCB9-7AE30F195A31}.Release|iPhone.Build.0 = Release|Any CPU
+		{D5C989FD-6AE3-417F-BCB9-7AE30F195A31}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU
+		{D5C989FD-6AE3-417F-BCB9-7AE30F195A31}.Release|iPhoneSimulator.Build.0 = Release|Any CPU
+		{D5C989FD-6AE3-417F-BCB9-7AE30F195A31}.Release|x86.ActiveCfg = Release|Any CPU
+		{D5C989FD-6AE3-417F-BCB9-7AE30F195A31}.Release|x86.Build.0 = Release|Any CPU
 		{D6E4E5BC-8998-4718-8E84-80901E6739CC}.AppStore|Any CPU.ActiveCfg = Debug|Any CPU
 		{D6E4E5BC-8998-4718-8E84-80901E6739CC}.AppStore|Any CPU.Build.0 = Debug|Any CPU
 		{D6E4E5BC-8998-4718-8E84-80901E6739CC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU

BIN
ShadowMapping/Content/DrawModel_0.xnb


BIN
ShadowMapping/Content/Grid_0.xnb


BIN
ShadowMapping/Content/dude.xnb


BIN
ShadowMapping/Content/grid.xnb


BIN
ShadowMapping/Content/headN_0.xnb


BIN
ShadowMapping/Content/headS_0.xnb


BIN
ShadowMapping/Content/head_0.xnb


BIN
ShadowMapping/Content/jacketN_0.xnb


BIN
ShadowMapping/Content/jacketS_0.xnb


BIN
ShadowMapping/Content/jacket_0.xnb


BIN
ShadowMapping/Content/pantsN_0.xnb


BIN
ShadowMapping/Content/pantsS_0.xnb


BIN
ShadowMapping/Content/pants_0.xnb


BIN
ShadowMapping/Content/upBodyC_0.xnb


BIN
ShadowMapping/Content/upBodyS_0.xnb


BIN
ShadowMapping/Content/upbodyN_0.xnb


+ 16 - 0
ShadowMapping/Info.plist

@@ -0,0 +1,16 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+	<key>CFBundleIdentifier</key>
+	<string>com.yourcompany.ShadowMapping</string>
+	<key>CFBundleName</key>
+	<string>ShadowMapping</string>
+	<key>CFBundleVersion</key>
+	<string>1</string>
+	<key>LSMinimumSystemVersion</key>
+	<string>10.6</string>
+	<key>NSPrincipalClass</key>
+	<string>NSApplication</string>
+</dict>
+</plist>

+ 45 - 0
ShadowMapping/Main.cs

@@ -0,0 +1,45 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+
+using MonoMac.AppKit;
+using MonoMac.Foundation;
+
+namespace ShadowMapping
+{
+	static class Program
+	{
+		/// <summary>
+		/// The main entry point for the application.
+		/// </summary>
+		static void Main (string[] args)
+		{
+			NSApplication.Init ();
+			
+			using (var p = new NSAutoreleasePool ()) {
+				NSApplication.SharedApplication.Delegate = new AppDelegate ();
+				NSApplication.Main (args);
+			}
+
+
+		}
+	}
+
+	class AppDelegate : NSApplicationDelegate
+	{
+		ShadowMappingGame game;
+
+		public override void FinishedLaunching (MonoMac.Foundation.NSObject notification)
+		{
+			game = new ShadowMappingGame ();
+			game.Run ();
+		}
+		
+		public override bool ApplicationShouldTerminateAfterLastWindowClosed (NSApplication sender)
+		{
+			return true;
+		}
+	}  
+}
+
+

+ 25 - 0
ShadowMapping/Properties/AssemblyInfo.cs

@@ -0,0 +1,25 @@
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+
+// General Information about an assembly is controlled through the following 
+// set of attributes. Change these attribute values to modify the information
+// associated with an assembly.
+[assembly: AssemblyTitle("Shadow Mapping")]
+[assembly: AssemblyProduct("Shadow Mapping")]
+[assembly: AssemblyDescription("This sample shows you how to implement basic shadow mapping from a directional light")]
+[assembly: AssemblyCompany("Microsoft")]
+
+[assembly: AssemblyCopyright("Copyright © Microsoft 2008")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+
+// Version information for an assembly consists of the following four values:
+//
+//      Major Version
+//      Minor Version 
+//      Build Number
+//      Revision
+//
+[assembly: AssemblyVersion("1.0.0.0")]

+ 107 - 0
ShadowMapping/ShadowMapping.MacOS.csproj

@@ -0,0 +1,107 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <ProductVersion>10.0.0</ProductVersion>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{36473816-E068-4D38-84F3-F5564BA77FF8}</ProjectGuid>
+    <ProjectTypeGuids>{948B3504-5B70-4649-8FE4-BDE1FB46EC69};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <OutputType>Exe</OutputType>
+    <RootNamespace>ShadowMapping</RootNamespace>
+    <AssemblyName>ShadowMapping</AssemblyName>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+    <DebugSymbols>true</DebugSymbols>
+    <DebugType>full</DebugType>
+    <Optimize>false</Optimize>
+    <OutputPath>bin\Debug</OutputPath>
+    <DefineConstants>DEBUG;</DefineConstants>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+    <EnablePackageSigning>false</EnablePackageSigning>
+    <IncludeMonoRuntime>false</IncludeMonoRuntime>
+    <ConsolePause>false</ConsolePause>
+    <EnableCodeSigning>false</EnableCodeSigning>
+    <CreatePackage>false</CreatePackage>
+    <CodeSigningKey>Mac Developer</CodeSigningKey>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+    <DebugType>none</DebugType>
+    <Optimize>true</Optimize>
+    <OutputPath>bin\Release</OutputPath>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+    <EnablePackageSigning>false</EnablePackageSigning>
+    <IncludeMonoRuntime>false</IncludeMonoRuntime>
+    <LinkMode>Full</LinkMode>
+    <ConsolePause>false</ConsolePause>
+    <EnableCodeSigning>false</EnableCodeSigning>
+    <CreatePackage>false</CreatePackage>
+    <CodeSigningKey>Mac Developer</CodeSigningKey>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'AppStore|AnyCPU' ">
+    <DebugType>none</DebugType>
+    <Optimize>true</Optimize>
+    <OutputPath>bin\AppStore</OutputPath>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+    <PackageSigningKey>3rd Party Mac Developer Installer</PackageSigningKey>
+    <IncludeMonoRuntime>true</IncludeMonoRuntime>
+    <LinkMode>Full</LinkMode>
+    <EnablePackageSigning>true</EnablePackageSigning>
+    <ConsolePause>false</ConsolePause>
+    <EnableCodeSigning>true</EnableCodeSigning>
+    <CreatePackage>true</CreatePackage>
+    <CodeSigningKey>3rd Party Mac Developer Application</CodeSigningKey>
+  </PropertyGroup>
+  <ItemGroup>
+    <Reference Include="System" />
+    <Reference Include="System.Xml" />
+    <Reference Include="System.Core" />
+    <Reference Include="System.Xml.Linq" />
+    <Reference Include="System.Drawing" />
+    <Reference Include="MonoMac" />
+  </ItemGroup>
+  <ItemGroup>
+    <ProjectReference Include="..\..\MonoGame.Framework\MonoGame.Framework.MacOS.csproj">
+      <Project>{36C538E6-C32A-4A8D-A39C-566173D7118E}</Project>
+      <Name>MonoGame.Framework.MacOS</Name>
+    </ProjectReference>
+    <ProjectReference Include="..\..\ThirdParty\Lidgren.Network\Lidgren.Network.MacOS.csproj">
+      <Project>{AE483C29-042E-4226-BA52-D247CE7676DA}</Project>
+      <Name>Lidgren.Network.MacOS</Name>
+    </ProjectReference>
+  </ItemGroup>
+  <ItemGroup>
+    <Compile Include="Main.cs" />
+    <Compile Include="Properties\AssemblyInfo.cs" />
+    <Compile Include="ShadowMapping.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="Info.plist" />
+  </ItemGroup>
+  <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
+  <Import Project="$(MSBuildExtensionsPath)\Mono\MonoMac\v0.0\Mono.MonoMac.targets" />
+  <ItemGroup>
+    <Folder Include="Content\" />
+  </ItemGroup>
+  <ItemGroup>
+    <Content Include="Content\DrawModel_0.xnb" />
+    <Content Include="Content\Grid_0.xnb" />
+    <Content Include="Content\dude.xnb" />
+    <Content Include="Content\grid.xnb" />
+    <Content Include="Content\headN_0.xnb" />
+    <Content Include="Content\headS_0.xnb" />
+    <Content Include="Content\head_0.xnb" />
+    <Content Include="Content\jacketN_0.xnb" />
+    <Content Include="Content\jacketS_0.xnb" />
+    <Content Include="Content\jacket_0.xnb" />
+    <Content Include="Content\pantsN_0.xnb" />
+    <Content Include="Content\pantsS_0.xnb" />
+    <Content Include="Content\pants_0.xnb" />
+    <Content Include="Content\upBodyC_0.xnb" />
+    <Content Include="Content\upBodyS_0.xnb" />
+    <Content Include="Content\upbodyN_0.xnb" />
+  </ItemGroup>
+</Project>

+ 414 - 0
ShadowMapping/ShadowMapping.cs

@@ -0,0 +1,414 @@
+#region File Description
+//-----------------------------------------------------------------------------
+// ShadowMapping.cs
+//
+// Microsoft XNA Community Game Platform
+// Copyright (C) Microsoft Corporation. All rights reserved.
+//-----------------------------------------------------------------------------
+#endregion
+
+#region Using Statements
+using System;
+using System.Collections.Generic;
+using Microsoft.Xna.Framework;
+using Microsoft.Xna.Framework.Audio;
+using Microsoft.Xna.Framework.Content;
+using Microsoft.Xna.Framework.GamerServices;
+using Microsoft.Xna.Framework.Graphics;
+using Microsoft.Xna.Framework.Input;
+using Microsoft.Xna.Framework.Net;
+using Microsoft.Xna.Framework.Storage;
+#endregion
+
+namespace ShadowMapping
+{
+    /// <summary>
+    /// Sample showing how to implement a simple shadow mapping technique where
+    /// the shadow map always contains the contents of the viewing frustum
+    /// </summary>
+    public class ShadowMappingGame : Microsoft.Xna.Framework.Game
+    {
+        #region Constants
+
+        // The size of the shadow map
+        // The larger the size the more detail we will have for our entire scene
+        const int shadowMapWidthHeight = 2048;
+
+        const int windowWidth = 800;
+        const int windowHeight = 480;
+
+        #endregion
+
+        #region Fields
+
+        GraphicsDeviceManager graphics;
+        SpriteBatch spriteBatch;
+
+        // Starting position and direction of our camera
+        Vector3 cameraPosition = new Vector3(0, 70, 100);
+        Vector3 cameraForward = new Vector3(0, -0.4472136f, -0.8944272f);
+        BoundingFrustum cameraFrustum = new BoundingFrustum(Matrix.Identity);
+
+        // Light direction
+        Vector3 lightDir = new Vector3(-0.3333333f, 0.6666667f, 0.6666667f);
+
+        KeyboardState currentKeyboardState;
+        GamePadState currentGamePadState;
+
+        // Our two models in the scene
+        Model gridModel;
+        Model dudeModel;
+
+        float rotateDude = 0.0f;
+
+        // The shadow map render target
+        RenderTarget2D shadowRenderTarget;
+
+        // Transform matrices
+        Matrix world;
+        Matrix view;
+        Matrix projection;
+
+        // ViewProjection matrix from the lights perspective
+        Matrix lightViewProjection;
+
+        #endregion
+
+        #region Initialization
+
+        public ShadowMappingGame()
+        {
+            graphics = new GraphicsDeviceManager(this);
+
+            Content.RootDirectory = "Content";
+
+            graphics.PreferredBackBufferWidth = windowWidth;
+            graphics.PreferredBackBufferHeight = windowHeight;
+
+            float aspectRatio = (float)windowWidth / (float)windowHeight;
+  
+            projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.PiOver4, 
+                                                             aspectRatio, 
+                                                             1.0f, 1000.0f);
+        }
+
+
+        /// <summary>
+        /// LoadContent will be called once per game and is the place to load
+        /// all of your content.
+        /// </summary>
+        protected override void LoadContent()
+        {
+            spriteBatch = new SpriteBatch(GraphicsDevice);
+
+            // Load the two models we will be using in the sample
+            gridModel = Content.Load<Model>("grid");
+            dudeModel = Content.Load<Model>("dude");
+
+            // Create floating point render target
+            shadowRenderTarget = new RenderTarget2D(graphics.GraphicsDevice,
+                                                    shadowMapWidthHeight,
+                                                    shadowMapWidthHeight,
+                                                    false,
+                                                    SurfaceFormat.Single,
+                                                    DepthFormat.Depth24);
+        }
+
+        #endregion
+
+        #region Update and Draw
+
+        /// <summary>
+        /// Allows the game to run logic such as updating the world,
+        /// checking for collisions, gathering input, and playing audio.
+        /// </summary>
+        /// <param name="gameTime">Provides a snapshot of timing values.</param>
+        protected override void Update(GameTime gameTime)
+        {
+            HandleInput(gameTime);
+
+            UpdateCamera(gameTime);
+
+            base.Update(gameTime);
+        }
+
+        /// <summary>
+        /// This is called when the game should draw itself.
+        /// </summary>
+        /// <param name="gameTime">Provides a snapshot of timing values.</param>
+        protected override void Draw(GameTime gameTime)
+        {
+            // Update the lights ViewProjection matrix based on the 
+            // current camera frustum
+            lightViewProjection = CreateLightViewProjectionMatrix();
+
+            GraphicsDevice.BlendState = BlendState.Opaque;
+            GraphicsDevice.DepthStencilState = DepthStencilState.Default;
+
+            // Render the scene to the shadow map
+            CreateShadowMap();
+
+            // Draw the scene using the shadow map
+            DrawWithShadowMap();
+
+            // Display the shadow map to the screen
+            DrawShadowMapToScreen();
+
+            base.Draw(gameTime);
+        }
+
+        #endregion
+
+        #region Methods
+
+        /// <summary>
+        /// Creates the WorldViewProjection matrix from the perspective of the 
+        /// light using the cameras bounding frustum to determine what is visible 
+        /// in the scene.
+        /// </summary>
+        /// <returns>The WorldViewProjection for the light</returns>
+        Matrix CreateLightViewProjectionMatrix()
+        {
+            // Matrix with that will rotate in points the direction of the light
+            Matrix lightRotation = Matrix.CreateLookAt(Vector3.Zero, 
+                                                       -lightDir, 
+                                                       Vector3.Up);
+
+            // Get the corners of the frustum
+            Vector3[] frustumCorners = cameraFrustum.GetCorners();
+
+            // Transform the positions of the corners into the direction of the light
+            for (int i = 0; i < frustumCorners.Length; i++)
+            {
+                frustumCorners[i] = Vector3.Transform(frustumCorners[i], lightRotation);
+            }
+
+            // Find the smallest box around the points
+            BoundingBox lightBox = BoundingBox.CreateFromPoints(frustumCorners);
+
+            Vector3 boxSize = lightBox.Max - lightBox.Min;
+            Vector3 halfBoxSize = boxSize * 0.5f;
+
+            // The position of the light should be in the center of the back
+            // pannel of the box. 
+            Vector3 lightPosition = lightBox.Min + halfBoxSize;
+            lightPosition.Z = lightBox.Min.Z;
+
+            // We need the position back in world coordinates so we transform 
+            // the light position by the inverse of the lights rotation
+            lightPosition = Vector3.Transform(lightPosition, 
+                                              Matrix.Invert(lightRotation));
+
+            // Create the view matrix for the light
+            Matrix lightView = Matrix.CreateLookAt(lightPosition, 
+                                                   lightPosition - lightDir, 
+                                                   Vector3.Up);
+
+            // Create the projection matrix for the light
+            // The projection is orthographic since we are using a directional light
+            Matrix lightProjection = Matrix.CreateOrthographic(boxSize.X, boxSize.Y, 
+                                                               -boxSize.Z, boxSize.Z);
+
+            return lightView * lightProjection;
+        }
+
+        /// <summary>
+        /// Renders the scene to the floating point render target then 
+        /// sets the texture for use when drawing the scene.
+        /// </summary>
+        void CreateShadowMap()
+        {
+            // Set our render target to our floating point render target
+            GraphicsDevice.SetRenderTarget(shadowRenderTarget);
+
+            // Clear the render target to white or all 1's
+            // We set the clear to white since that represents the 
+            // furthest the object could be away
+            GraphicsDevice.Clear(Color.White);
+
+            // Draw any occluders in our case that is just the dude model
+
+            // Set the models world matrix so it will rotate
+            world = Matrix.CreateRotationY(MathHelper.ToRadians(rotateDude));
+            // Draw the dude model
+            DrawModel(dudeModel, true);
+
+            // Set render target back to the back buffer
+            GraphicsDevice.SetRenderTarget(null);
+        }
+
+        /// <summary>
+        /// Renders the scene using the shadow map to darken the shadow areas
+        /// </summary>
+        void DrawWithShadowMap()
+        {
+            graphics.GraphicsDevice.Clear(Color.CornflowerBlue);
+
+            GraphicsDevice.SamplerStates[1] = SamplerState.PointClamp;
+
+            // Draw the grid
+            world = Matrix.Identity;
+            DrawModel(gridModel, false);
+
+            // Draw the dude model
+            world = Matrix.CreateRotationY(MathHelper.ToRadians(rotateDude));
+            DrawModel(dudeModel, false);
+        }
+
+        /// <summary>
+        /// Helper function to draw a model
+        /// </summary>
+        /// <param name="model">The model to draw</param>
+        /// <param name="technique">The technique to use</param>
+        void DrawModel(Model model, bool createShadowMap)
+        {
+            string techniqueName = createShadowMap ? "CreateShadowMap" : "DrawWithShadowMap";
+
+            Matrix[] transforms = new Matrix[model.Bones.Count];
+            model.CopyAbsoluteBoneTransformsTo(transforms);
+
+            // Loop over meshs in the model
+            foreach (ModelMesh mesh in model.Meshes)
+            {
+                // Loop over effects in the mesh
+                foreach (Effect effect in mesh.Effects)
+                {
+                    // Set the currest values for the effect
+                    effect.CurrentTechnique = effect.Techniques[techniqueName];
+                    effect.Parameters["World"].SetValue(world);
+                    effect.Parameters["View"].SetValue(view);
+                    effect.Parameters["Projection"].SetValue(projection);
+                    effect.Parameters["LightDirection"].SetValue(lightDir);
+                    effect.Parameters["LightViewProj"].SetValue(lightViewProjection);
+
+                    if (!createShadowMap)
+                        effect.Parameters["ShadowMap"].SetValue(shadowRenderTarget);
+                }
+                // Draw the mesh
+                mesh.Draw();
+            }
+        }
+
+        /// <summary>
+        /// Render the shadow map texture to the screen
+        /// </summary>
+        void DrawShadowMapToScreen()
+        {
+            spriteBatch.Begin(0, BlendState.Opaque, SamplerState.PointClamp, null, null);
+            spriteBatch.Draw(shadowRenderTarget, new Rectangle(0, 0, 128, 128), Color.White);
+            spriteBatch.End();
+
+            GraphicsDevice.Textures[0] = null;
+            GraphicsDevice.SamplerStates[0] = SamplerState.LinearWrap;
+        }
+
+        #endregion
+
+        #region Handle Input
+
+        /// <summary>
+        /// Handles input for quitting the game.
+        /// </summary>
+        void HandleInput(GameTime gameTime)
+        {
+            float time = (float)gameTime.ElapsedGameTime.TotalMilliseconds;
+
+            currentKeyboardState = Keyboard.GetState();
+            currentGamePadState = GamePad.GetState(PlayerIndex.One);
+
+            // Rotate the dude model
+            rotateDude += currentGamePadState.Triggers.Right * time * 0.2f;
+            rotateDude -= currentGamePadState.Triggers.Left * time * 0.2f;
+            
+            if (currentKeyboardState.IsKeyDown(Keys.Q))
+                rotateDude -= time * 0.2f;
+            if (currentKeyboardState.IsKeyDown(Keys.E))
+                rotateDude += time * 0.2f;
+
+            // Check for exit.
+            if (currentKeyboardState.IsKeyDown(Keys.Escape) ||
+                currentGamePadState.Buttons.Back == ButtonState.Pressed)
+            {
+                Exit();
+            }
+        }
+
+
+        /// <summary>
+        /// Handles input for moving the camera.
+        /// </summary>
+        void UpdateCamera(GameTime gameTime)
+        {
+            float time = (float)gameTime.ElapsedGameTime.TotalMilliseconds;
+
+            // Check for input to rotate the camera.
+            float pitch = -currentGamePadState.ThumbSticks.Right.Y * time * 0.001f;
+            float turn = -currentGamePadState.ThumbSticks.Right.X * time * 0.001f;
+
+            if (currentKeyboardState.IsKeyDown(Keys.Up))
+                pitch += time * 0.001f;
+
+            if (currentKeyboardState.IsKeyDown(Keys.Down))
+                pitch -= time * 0.001f;
+
+            if (currentKeyboardState.IsKeyDown(Keys.Left))
+                turn += time * 0.001f;
+
+            if (currentKeyboardState.IsKeyDown(Keys.Right))
+                turn -= time * 0.001f;
+
+            Vector3 cameraRight = Vector3.Cross(Vector3.Up, cameraForward);
+            Vector3 flatFront = Vector3.Cross(cameraRight, Vector3.Up);
+
+            Matrix pitchMatrix = Matrix.CreateFromAxisAngle(cameraRight, pitch);
+            Matrix turnMatrix = Matrix.CreateFromAxisAngle(Vector3.Up, turn);
+
+            Vector3 tiltedFront = Vector3.TransformNormal(cameraForward, pitchMatrix *
+                                                          turnMatrix);
+
+            // Check angle so we cant flip over
+            if (Vector3.Dot(tiltedFront, flatFront) > 0.001f)
+            {
+                cameraForward = Vector3.Normalize(tiltedFront);
+            }
+
+            // Check for input to move the camera around.
+            if (currentKeyboardState.IsKeyDown(Keys.W))
+                cameraPosition += cameraForward * time * 0.1f;
+
+            if (currentKeyboardState.IsKeyDown(Keys.S))
+                cameraPosition -= cameraForward * time * 0.1f;
+
+            if (currentKeyboardState.IsKeyDown(Keys.A))
+                cameraPosition += cameraRight * time * 0.1f;
+
+            if (currentKeyboardState.IsKeyDown(Keys.D))
+                cameraPosition -= cameraRight * time * 0.1f;
+
+            cameraPosition += cameraForward *
+                              currentGamePadState.ThumbSticks.Left.Y * time * 0.1f;
+
+            cameraPosition -= cameraRight *
+                              currentGamePadState.ThumbSticks.Left.X * time * 0.1f;
+
+            if (currentGamePadState.Buttons.RightStick == ButtonState.Pressed ||
+                currentKeyboardState.IsKeyDown(Keys.R))
+            {
+                cameraPosition = new Vector3(0, 50, 50);
+                cameraForward = new Vector3(0, 0, -1);
+            }
+
+            cameraForward.Normalize();
+
+            // Create the new view matrix
+            view = Matrix.CreateLookAt(cameraPosition, 
+                                       cameraPosition + cameraForward, 
+                                       Vector3.Up);
+
+            // Set the new frustum value
+            cameraFrustum.Matrix = view * projection;
+        }
+
+        #endregion
+    }
+}