XNA_Slides - 3D User Interfaces for Games 3D and Virtual...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 3D User Interfaces for Games 3D and Virtual Reality Lecture #4: XNA & Bespoke 3DUI Spring 2009 Joseph J. LaViola Jr. Special thanks to Paul Varcholik for developing Bespoke 3DUI and these slides. Spring 2009 Spring CAP6938 – 3D User Interfaces for Games and Virtual Reality ©Joseph J. LaViola Jr. Introductions Introductions Paul Varcholik: [email protected] Paul Technology Blog: Technology www.bespokesoftware.org Spring 2009 CAP6938 – 3D User Interfaces for Games and Virtual Reality ©Joseph J. LaViola Jr. Software Visual Studio 2008 (Standard or Visual Professional) or Visual C# Express 2008 Visual Windows Vista Service Pack 1; Windows Windows XP Service Pack 3 XNA Game Studio 3.0 XNA Spring 2009 CAP6938 – 3D User Interfaces for Games and Virtual Reality CAP6938 ©Joseph J. LaViola Jr. Online Resources Online XNA Developer Center XNA http://msdn.microsoft.com/xna XNA Team Blog XNA http://blogs.msdn.com/xna/ XNA Creators Club XNA http://creators.xna.com/ Spring 2009 CAP6938 – 3D User Interfaces for Games and Virtual Reality ©Joseph J. LaViola Jr. What is XNA? What Graphics and Game Development Framework Graphics Announced: Aug 2006 Announced: 1.0: Dec 2006 1.0: 1.0 Refresh: April 2007 1.0 2.0: Dec 2007 2.0: 3.0: Oct 2008 3.0: 2D and 3D 2D Managed DirectX Managed Windows and Xbox 360 Windows Content Pipeline Content XNA’s Not Acronymed NA’ Spring 2009 CAP6938 – 3D User Interfaces for Games and Virtual Reality CAP6938 ©Joseph J. LaViola Jr. Why Use XNA? Why Extremely Comprehensive Extremely Free Free Easy to Use (though game programming is, in Easy general, quite challenging) Development and Real-time Debugging on a Development Retail Xbox 360 Casual Games Casual Game Prototyping Game Access to the .NET Framework Class Libraries Access Spring 2009 CAP6938 – 3D User Interfaces for Games and Virtual Reality ©Joseph J. LaViola Jr. XNA XNA Microsoft.Xna Microsoft.Xna .Framework .Framework .Graphics .Graphics .Content .Content .Input .Input .Audio .Audio Microsoft.Xna.Framework Classes/Structs Microsoft.Xna.Framework Game Game ContentManager ContentManager GraphicsDeviceManager GraphicsDeviceManager GameComponent GameComponent DrawableGameComponent DrawableGameComponent Spring 2009 CAP6938 – 3D User Interfaces for Games and Virtual Reality CAP6938 ©Joseph J. LaViola Jr. XNA (cont.) XNA Microsoft.Xna.Framework Classes/Structs Microsoft.Xna.Framework Vector2 Vector2 Vector3 Vector3 Point Point Matrix Matrix BoundingBox BoundingBox BoundingSphere BoundingSphere Texture2D Texture2D SpriteFont SpriteFont Spring 2009 CAP6938 – 3D User Interfaces for Games and Virtual Reality ©Joseph J. LaViola Jr. XNA (cont.) XNA Game Class Game Initialize() Initialize() LoadContent() LoadContent UnloadContent() UnloadContent Update() Update() Draw() Draw() Components Components Separate out a generic/reusable class library Separate Spring 2009 CAP6938 – 3D User Interfaces for Games and Virtual Reality CAP6938 ©Joseph J. LaViola Jr. Bespoke 3D UI Framework Bespoke Organization: Organization: Source Code Source Framework Framework Samples Samples StereoscopicRendering StereoscopicRendering TrackIRTestbed TrackIRTestbed WiimoteTestbed WiimoteTestbed Executables Executables Documentation Documentation Spring 2009 CAP6938 – 3D User Interfaces for Games and Virtual Reality ©Joseph J. LaViola Jr. Bespoke 3D UI Framework Bespoke Namespaces: Namespaces: Bespoke.Common Bespoke.Common General Utilities (not game/XNA specific) Bespoke.Games.Framework Bespoke.Games.Framework XNA utility libraries Bespoke.Games.Framework.Content Bespoke.Games.Framework.Content Custom XNA Content Processors Spring 2009 CAP6938 – 3D User Interfaces for Games and Virtual Reality CAP6938 ©Joseph J. LaViola Jr. Bespoke.Commom Bespoke.Commom Assert (static) Assert CommandLineParser CommandLineParser Library (static) Library LogManager LogManager Node<T> / NodeCollection <T> Node<T> ProgressIndicator ProgressIndicator XmlHelper XmlHelper Spring 2009 CAP6938 – 3D User Interfaces for Games and Virtual Reality ©Joseph J. LaViola Jr. Bespoke.Common Bespoke.Common .Data .Data .LinearAlgebra .TrackIR – Requires OptiTrack software .Video – Uses DirectShow.NET (wrapper .Video for unmanaged DirectShow) .Wiimote – Brian Peek’s Wiimote Library from Coding4Fun.com Spring 2009 CAP6938 – 3D User Interfaces for Games and Virtual Reality CAP6938 ©Joseph J. LaViola Jr. Bespoke.Games.Framework.Content Bespoke.Games.Framework.Content TerrainContentImporter TerrainContentImporter TerrainContentProcessor TerrainContentProcessor TerrainDataWriter TerrainDataWriter These classes provide a content pipeline for using a heightmap for terrain. This is used in conjunction with the TerrainComponent. Spring 2009 CAP6938 – 3D User Interfaces for Games and Virtual Reality ©Joseph J. LaViola Jr. Bespoke.Games.Framework Bespoke.Games.Framework Actor/ActorList Actor/ActorList DynamicActor DynamicActor DynamicActorGroup DynamicActorGroup FontManager FontManager FpsComponent FpsComponent GridComponent GridComponent PostProcessor PostProcessor ScreenCapture ScreenCapture Spring 2009 CameraComponent CameraComponent ChaseCameraComponent ChaseCameraComponent StereoscopicChaseCameraComp StereoscopicChaseCameraComp onent Sprite Sprite SpriteManager SpriteManager SkyBoxComponent SkyBoxComponent SoundManager SoundManager TerrainComponent TerrainComponent CAP6938 – 3D User Interfaces for Games and Virtual Reality CAP6938 ©Joseph J. LaViola Jr. Bespoke.Games.Framework Bespoke.Games.Framework ScreenManager ScreenManager GameScreen GameScreen MenuScreen MenuScreen ScreenInputManager ScreenInputManager .UI .UI .Input .Input KeyboardComponent KeyboardComponent MouseComponent MouseComponent GamepadComponent GamepadComponent TrackIRComponent TrackIRComponent WiimoteComponent WiimoteComponent UIManager UIManager UIControl UIControl Button Button XML Configuration XML Spring 2009 CAP6938 – 3D User Interfaces for Games and Virtual Reality ©Joseph J. LaViola Jr. How To: How Render a 2D Texture Render Draw Text Draw View the Game’s Framerate View Game’ Collect Input Collect Keyboard Keyboard Mouse Mouse Gamepad Gamepad Spring 2009 Initialize a 3D camera Initialize Draw a Reference Grid Draw Render a 3D Model Render Play Sound Play Render a SkyBox Render Render Terrain Render CAP6938 – 3D User Interfaces for Games and Virtual Reality CAP6938 ©Joseph J. LaViola Jr. How To: How Render a 2D Texture 1. Include the texture in the Content project. Supported formats: bmp, .dds, .dib, .hdr, .jpg, .pfm, .png, .ppm, and .tga bmp, .dds, .hdr, .pfm, .png, .ppm, .tga 2. Initialize the SpriteManager class within the LoadContent() or LoadContent() Initialize() method: SpriteManager.Initialize(this); SpriteManager.Initialize(this); 3. Create data member to store texture: private Texture2D mTexture; mTexture; 4. Load the texture in the LoadContent() method: LoadContent() mTexture = Content.Load<Texture2D>(@"Content\Textures\Skybox\back"); Content.Load<Texture2D>(@"Content\Textures\ Skybox\ 5. Render the texture in the Draw() method: SpriteManager.DrawTexture2D(mTexture, Vector2.Zero, Color.White); Color.White); Spring 2009 CAP6938 – 3D User Interfaces for Games and Virtual Reality ©Joseph J. LaViola Jr. How To: How Draw Text 1. 2. Initialize the SpriteManager class as required before any calls can be made to the SpriteManager. SpriteManager. Add a call to SpriteManager.DrawString in the Draw() method: SpriteManager.DrawString("Hello World", 40.0f, 40.0f, Color.White); Color.White); Variety of overloads to the DrawString method: Variety Change the font Change The blend color The Rotation Rotation Sorting Sorting Spring 2009 CAP6938 – 3D User Interfaces for Games and Virtual Reality CAP6938 ©Joseph J. LaViola Jr. How To: How View the Game’s Framerate 1. Add the following statements to the Game-derived Gameconstructor, LoadContent(), or Initialize() method: LoadContent(), FpsComponent fps = new FpsComponent(this); FpsComponent(this); fps.Location = FpsComponent.ScreenLocation.TitleBar; FpsComponent.ScreenLocation.TitleBar; Components.Add(fps); Components.Add(fps); FpsComponent display locations: FpsComponent Titlebar Titlebar UpperLeft UpperLeft UpperRight UpperRight LowerLeft LowerLeft LowerRight LowerRight Spring 2009 CAP6938 – 3D User Interfaces for Games and Virtual Reality ©Joseph J. LaViola Jr. How To: How Collect Keyboard Input 1. 2. Add a using statement for the Bespoke.Games.Framework.Input namespace; (Optional) Create a data member to store the keyboard component: private KeyboardComponent mKeyboardComponent; mKeyboardComponent; 3. Add the following statements to the Game-derived constructor, GameLoadConent(), or Initialize() method: LoadConent(), mKeyboardComponent = new KeyboardComponent(this); KeyboardComponent(this); Components.Add(mKeyboardComponent); Components.Add(mKeyboardComponent); 4. Add keyboard queries to the Update() method: if (mKeyboardComponent.WasKeyPressedThisFrame(Keys.Escape)) (mKeyboardComponent.WasKeyPressedThisFrame(Keys.Escape)) { Exit(); } Spring 2009 CAP6938 – 3D User Interfaces for Games and Virtual Reality CAP6938 ©Joseph J. LaViola Jr. How To: How Initialize a 3D Camera 1. Add the following statements to the Game-derived Gameconstructor, LoadContent(), or Initialize() method: LoadContent(), mCamera = new CameraComponent(this); CameraComponent(this); Services.AddService(typeof(ICamera), mCamera); Services.AddService(typeof(ICamera), mCamera); Components.Add(mCamera); Components.Add(mCamera); mCamera.KeyboardComponent = mKeyboardComponent; mKeyboardComponent; mCamera.GamePadComponent = mGamePadComponent; mGamePadComponent; mCamera.Position = new Vector3(0.0f, 20.0f, 200.0f); mCamera.Orientation = Vector3.Up; mCamera.Direction = Vector3.Forward; mCamera.LookAtOffset = Vector3.Forward; mCamera.NearPlaneDistance = 1.0f; mCamera.FarPlaneDistance = 100000.0f; mCamera.FieldOfView = MathHelper.PiOver4; mCamera.AspectRatio = (float)GraphicsDevice.PresentationParameters.BackBufferWidth / (float)GraphicsDevice.PresentationParameters.BackBufferWidth GraphicsDevice.PresentationParameters.BackBufferHeight; GraphicsDevice.PresentationParameters.BackBufferHeight; mCamera.UpdateProjectionMatrix(); mCamera.UpdateProjectionMatrix(); Spring 2009 CAP6938 – 3D User Interfaces for Games and Virtual Reality ©Joseph J. LaViola Jr. How To: How Draw a Reference Grid 1. 2. Initialize a camera Add the following statements to the Game-derived Gameconstructor, LoadContent(), or Initialize() method: (), LoadContent GridComponent grid = new GridComponent(this); GridComponent(this); Components.Add(grid); Components.Add(grid); You can modify the size (number of cells), scale (spacing You between each line) and the color of the grid Spring 2009 CAP6938 – 3D User Interfaces for Games and Virtual Reality CAP6938 ©Joseph J. LaViola Jr. How To: How Render a 3D Model 1. Include the model in your Content project (this is typically a subsubproject within your Game project) Supported Formats: Supported .fbx (Autodesk) .x (DirectX Surface) .x Be certain that associated textures reside in the proper locations. Be locations. 2. Add the following statements to the Game-derived LoadContent(), GameLoadContent(), or Initialize() method: Model tankModel = Content.Load<Model>(@"Content\Models\Tank"); Content.Load<Model>(@"Content\Models\ Actor tankActor = new DynamicActor(this, "Tank", Vector3.Zero, Vector3.Up, 0.05f, 1.0f, DynamicActor(this, tankModel, mCamera); tankModel, mCamera); tankActor.Initialize(); tankActor.Initialize(); 3. Spring 2009 Add tankActor.Update() and tankActor.Draw() calls to the corresponding tankActor.Update() tankActor.Draw() Game-derived Update() and Draw() methods. Game- CAP6938 – 3D User Interfaces for Games and Virtual Reality ©Joseph J. LaViola Jr. How To: How Play Sound 1. 2. 3. Build your sound project using XACT. Include your sound project (.xap) into your Content project. (.xap) Initialize the SoundManager static class in the LoadContent() or Initialize() LoadContent() method: SoundManager.Initialize(@"Content\Audio\SoundProject.xgs", @"Content\Audio\Wave SoundManager.Initialize(@"Content\ Audio\ SoundProject.xgs", @"Content\ Audio\ Bank.xwb", @"Content\Audio\Sound Bank.xsb"); Bank.xwb", @"Content\ Audio\ Bank.xsb"); 4. Play sounds with SoundManager.Play(): SoundManager.Play(): 5. Call SoundManager.Update() within the main Update() loop. SoundManager.Update() Spring 2009 CAP6938 – 3D User Interfaces for Games and Virtual Reality CAP6938 ©Joseph J. LaViola Jr. How To: How Render a Skybox 2. Create your skybox textures (Terragen) and import them into your Content (Terragen project (front, back, left, right, top) Create a SkyBoxComponent data member. 3. Add the following code to your Initialize() or LoadContent() method: LoadContent() 1. private SkyBoxComponent mSkyBox; mSkyBox; Texture2D front = Content.Load<Texture2D>(@"Content\Textures\SkyBox\front"); Content.Load<Texture2D>(@"Content\Textures\ SkyBox\ Texture2D back = Content.Load<Texture2D>(@"Content\Textures\SkyBox\back"); Content.Load<Texture2D>(@"Content\Textures\ SkyBox\ Texture2D left = Content.Load<Texture2D>(@"Content\Textures\SkyBox\left"); Content.Load<Texture2D>(@"Content\Textures\SkyBox\ Texture2D right = Content.Load<Texture2D>(@"Content\Textures\SkyBox\right"); Content.Load<Texture2D>(@"Content\Textures\ SkyBox\ Texture2D top = Content.Load<Texture2D>(@"Content\Textures\SkyBox\top"); Content.Load<Texture2D>(@"Content\Textures\SkyBox\ mSkyBox = new SkyBoxComponent(this, "SkyBox", front, back, left, right, top, 1000.0f, SkyBoxComponent(this, "SkyBox", mCamera); mCamera); mSkyBox.Initialize(); mSkyBox.Initialize(); 4. Spring 2009 Call mSkyBox.Draw() from the main draw loop. Call this as the first object to be mSkyBox.Draw() rendered. CAP6938 – 3D User Interfaces for Games and Virtual Reality ©Joseph J. LaViola Jr. How To: How Render Terrain 1. 2. 3. Spring 2009 Reference Bespoke.Games.Framework.Content.dll from your Content project. Import the heightmap (.raw) into your Content project and choose the Bespoke Software – Terrain Content Importer/Processor Import the associated texture into your Content project. CAP6938 – 3D User Interfaces for Games and Virtual Reality CAP6938 ©Joseph J. LaViola Jr. How To: How Render Terrain (cont.) 4. Create a TerrainComponent data member. private TerrainComponent mTerrain; mTerrain; 5. Add the following code to your Initialize() or LoadContent() LoadContent() method: TerrainData terrainData = Content.Load<TerrainData>(@"Content\Other\TerrainHeightMap"); Content.Load< TerrainData>(@"Content\Other\ TerrainHeightMap"); Texture2D terrainTexture = Content.Load<Texture2D>(@"Content\Textures\Terrain"); Content.Load<Texture2D>(@"Content\Textures\ mTerrain = new TerrainComponent(this, terrainData, terrainTexture, 513, 513, 4.0f, 6000.0f, TerrainComponent(this, terrainData, terrainTexture, Color.White, -1000.0f, mCamera); Color.White, mCamera); mTerrain.Initialize(); mTerrain.Initialize(); 5. Spring 2009 Call mTerrain.Draw() from the main draw loop. mTerrain.Draw() CAP6938 – 3D User Interfaces for Games and Virtual Reality ©Joseph J. LaViola Jr. How To: How Collect Wiimote Input From Brian Peek’s Wiimote.NET Article Peek’ Getting Connected This will likely be the biggest sticking point. The Wiimote will not pair and communicate successfully with every Bluetooth device and stack on the planet. There's little I can do to help get you connected if the following following steps do not work. Either it's going to work, or it isn't. Cross your fingers... Start up your Bluetooth software and have it search for a device. 1. device. Hold down the 1 and 2 buttons on the Wiimote. You should see the LEDs at the bottom start flashing. Do 2. 2. Wiimote. not let go of these buttons until this procedure is complete. 3. The device should show up in the list of devices found as Nintendo RVL-CNT-01. If it's not there, start Nintendo RVL- CNTover and try again. 4. Click Next to move your way through the wizard. If at any point you are asked to enter a security code or 4. Next PIN, leave the number blank or click Skip. Do not enter a number. Skip 5. You may be asked which service to use from the Wiimote. Select the keyboard/mouse/HID service if 5. Wiimote. prompted (you should only see one service available). 6. Finish the wizard. 6. That's it. The LEDs at the bottom should continue to flash and you should see the device listed in your list of device connected Bluetooth devices. If you run the test application included with the source code and you see the and numbers change, you are all set. If you don't see them change or you get an error, try the above again. If it continues to not function, you are likely stuck with an incompatible device or stack. incompatible Spring 2009 CAP6938 – 3D User Interfaces for Games and Virtual Reality CAP6938 ©Joseph J. LaViola Jr. How To: How Collect Wiimote Input (cont.) 1. (Optional) Create a data member to store the Wiimote component: private WiimoteComponent mWiimoteComponent; mWiimoteComponent; 2. Add the following statements to the Game-derived constructor, GameLoadConent(), or Initialize() method: LoadConent(), mWiimoteComponent = new WiimoteComponent(this); WiimoteComponent(this); Components.Add(mWiimoteComponent); Components.Add(mWiimoteComponent); 3. Add Wiimote queries to the Update() method: if (mWiimoteComponent.CurrentState.ButtonState.B) (mWiimoteComponent.CurrentState.ButtonState.B) { rotationAmount.X = mWiimoteComponent.Y; mWiimoteComponent.Y; rotationAmount.Y = -mWiimoteComponent.Z; mWiimoteComponent.Z; } Spring 2009 CAP6938 – 3D User Interfaces for Games and Virtual Reality ©Joseph J. LaViola Jr. Controls: Controls: CameraComponent Keyboard Keyboard WASD (forward, turn left, backward, turn WASD right) Up Arrow (turn up), Down Arrow (turn down) Up GamePad GamePad Left Thumbstick (turn up, down, left, right) Left Right Trigger (forward) Right Left Trigger (reverse) Left Spring 2009 CAP6938 – 3D User Interfaces for Games and Virtual Reality CAP6938 ©Joseph J. LaViola Jr. Controls: Controls: StereoScopicChaseCameraComponent Keyboard Keyboard PageUp/PageDown (increase/descrease IPD) PageUp/PageDown (increase/descrease End (toggle stereoscopic rendering) End Spring 2009 CAP6938 – 3D User Interfaces for Games and Virtual Reality ©Joseph J. LaViola Jr. Controls: Controls: StereoScopicChaseCameraComponent Keyboard Keyboard PageUp/PageDown (increase/descrease IPD) PageUp/PageDown (increase/descrease End (toggle stereoscopic rendering) End Spring 2009 CAP6938 – 3D User Interfaces for Games and Virtual Reality CAP6938 ©Joseph J. LaViola Jr. ...
View Full Document

This note was uploaded on 06/13/2011 for the course CAP 6938 taught by Professor Staff during the Spring '08 term at University of Central Florida.

Ask a homework question - tutors are online