1
Useful Tools for Making Video
Games
Part V
An overview of
2
Things you need to install
Visual Studio 2005 or Visual C#
Express Edition
Its service pack
XNA Game Studio
http://creators.xna.com/Education/
newtoxna.aspx
3
Displaying a 3D Model
Create a Windows Game project
4
Displaying a 3D Model
Add model to solution
5
Displaying a 3D Model
// Set the 3D model to draw.
Model myModel;
// The aspect ratio determines how to scale 3d to 2d projection.
float aspectRatio;
protected override void LoadGraphicsContent(bool loadAllContent)
{
if (loadAllContent) {
myModel = content.Load<Model>(“myModel");
}
aspectRatio = graphics.GraphicsDevice.Viewport.Width /
graphics.GraphicsDevice.Viewport.Height;
}
6
Displaying a 3D Model
// Set the position of the model in world space, and set the rotation.
Vector3 modelPosition = Vector3.Zero;
float modelRotation = 0.0f;
// Set the position of the camera in world space, for our view matrix.
Vector3 cameraPosition = new Vector3(0.0f, 50.0f, 5000.0f);
protected override void Draw(GameTime gameTime) {
graphics.GraphicsDevice.Clear(Color.CornflowerBlue);
// Copy any parent transforms.
Matrix[] transforms = new Matrix[myModel.Bones.Count];
myModel.CopyAbsoluteBoneTransformsTo(transforms);
// Draw the model. A model can have multiple meshes, so loop.
foreach (ModelMesh mesh in myModel.Meshes) {
// This is where the mesh orientation is set, as well as our camera and projection.
foreach (BasicEffect effect in mesh.Effects) {
effect.EnableDefaultLighting();
effect.World = transforms[mesh.ParentBone.Index] * Matrix.CreateRotationY(modelRotation)
* Matrix.CreateTranslation(modelPosition);
effect.View = Matrix.CreateLookAt(cameraPosition, Vector3.Zero, Vector3.Up);
effect.Projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(45.0f),
aspectRatio, 1.0f, 10000.0f);
}
// Draw the mesh, using the effects set above.
mesh.Draw();
}
}
7
Displaying a 3D Model
Transformation of model done through
modifying its world matrix
// update rotation angle
protected override void Update(GameTime gameTime)
{
if (GamePad.GetState(PlayerIndex.One).Buttons.Back ==
ButtonState.Pressed)
this.Exit();
modelRotation +=
(float)gameTime.ElapsedGameTime.TotalMilliseconds *
MathHelper.ToRadians(0.1f);
base.Update(gameTime);
}
Sample implementation can be found in
Loading_3D_Model.zip
8
Keyboard and Mouse input
In the Update() function check for input
KeyboardState keyboardState = Keyboard.GetState();
if (keyboardState.IsKeyDown( Keys.Left ) {…}
mouseState is pressed as long as you keep your
finger on the button, usually you want to detect
the event once
MouseState mouseState = Mouse.GetState();
if (mouseState.LeftButton == ButtonState.Released)
released = true; // this is a global boolean
if (mouseState.LeftButton == ButtonState.Pressed && released)
{
released = false;
System.Console.WriteLine("left mouse clickedn");
}
9
Camera
Determine the location and orientation
of the camera object.
Create a view matrix using the camera
position, orientation, and the world
space's up vector.
Create a perspective matrix that
determines the near and far clipping
planes and the aspect of the projection.
In the Draw method of game, initialize a
BasicEffect object with the
transformational matrices created earlier
(world, view projection) and then render
all existing 3D models.
10
Camera
Matrix view = Matrix.CreateLookAt(cameraPosition,
cameraLookat,
cameraUp);
Matrix proj = Matrix.CreatePerspectiveFieldOfView(viewAngle,
aspectRatio, nearClip, farClip);
foreach (ModelMesh mesh in model.Meshes)
{
foreach (BasicEffect be in mesh.Effects)
{
be.Projection = proj;
be.View = view;
be.World = world; // eg. Matrix.CreateTranslation(…)
}
mesh.Draw();
}
Sample implementation can be found in
Camera.zip
11
Skybox
apply a skybox-style TextureCube ("cube map") to
a sphere using shader
Effect SkySphereEffect = Content.Load<Effect>("SkySphere");
TextureCube SkyboxTexture = Content.Load<TextureCube>("uffizi_cross");
// Set the parameters of the effect
SkySphereEffect.Parameters["ViewMatrix"].SetValue(myCamera.ViewMatrix);
SkySphereEffect.Parameters["ProjectionMatrix"].SetValue(projectionMatrix);
SkySphereEffect.Parameters["SkyboxTexture"].SetValue(SkyboxTexture);
Since the Effect and the Model are loaded
separately, you need to apply the SkySphere effect
to each Effect property on the ModelMeshPart of the
SkySphere model.
Sample implementation can be found in
skysphere.zip
12
Animation
Curve’s allows a path to be defined by a
small number of control points with the
Curve’s calculating the points on the path
between the control points
Add Curve3D.cs (found under
cs134/lib/xna/content) to your project.
Create two instances of this class, one for
the position of the camera and the other
for the lookAt vector. Also add variable to
keep track of time:
13
Animation
Define a function called InitCurve() and
specify the points that the camera will
pass throught and the points that the
camera will be looking at.
The number of points on the position and
the lookAt curves don’t need to match,
but the first and the last points on the
curves should have the same time values
if the curves oscillate
calculate the camera’s current position
and orientation and update the view
matrix
Sample implementation can be found in
Animation.zip
14
References
http://msdn2.microsoft.com/en-
us/library/bb198548.aspx
http://creators.xna.com/Education/Tutorials.aspx
http://creators.xna.com/Education/Samples.aspx
http://creators.xna.com/Education/StarterKits.aspx
http://forums.xna.com/

More Related Content

PDF
The Ring programming language version 1.5.3 book - Part 76 of 184
PDF
The Ring programming language version 1.3 book - Part 49 of 88
PDF
The Ring programming language version 1.9 book - Part 71 of 210
PDF
The Ring programming language version 1.7 book - Part 63 of 196
PDF
PDF
The Ring programming language version 1.7 book - Part 66 of 196
PPTX
Game dev 101 part 3
PPTX
WP7 HUB_XNA overview
The Ring programming language version 1.5.3 book - Part 76 of 184
The Ring programming language version 1.3 book - Part 49 of 88
The Ring programming language version 1.9 book - Part 71 of 210
The Ring programming language version 1.7 book - Part 63 of 196
The Ring programming language version 1.7 book - Part 66 of 196
Game dev 101 part 3
WP7 HUB_XNA overview

What's hot (20)

PPTX
WP7 HUB_XNA
PDF
The Ring programming language version 1.5.3 book - Part 70 of 184
PDF
The Ring programming language version 1.6 book - Part 73 of 189
PPTX
Android Custom Views
PDF
Swift Map
PDF
Android custom views
PDF
The Ring programming language version 1.10 book - Part 65 of 212
DOCX
Coding matlab
PDF
Keeping Track of Moving Things: MapKit and CoreLocation in Depth
PPT
ARTDM 170, Week 11: User Interaction
PDF
The Ring programming language version 1.9 book - Part 60 of 210
PDF
Shootting Game
PDF
WebGL 3D player
PDF
Kivy Talk Python Meetup Innsbruck 2017.04.25
PDF
Teaching Python to 9 Year Old Girl - map mover
PDF
Async Testing giving you a sinking feeling
PDF
Introduction to three.js & Leap Motion
PDF
The Ring programming language version 1.6 book - Part 52 of 189
PDF
Model View Intent on Android
PDF
The Ring programming language version 1.10 book - Part 66 of 212
WP7 HUB_XNA
The Ring programming language version 1.5.3 book - Part 70 of 184
The Ring programming language version 1.6 book - Part 73 of 189
Android Custom Views
Swift Map
Android custom views
The Ring programming language version 1.10 book - Part 65 of 212
Coding matlab
Keeping Track of Moving Things: MapKit and CoreLocation in Depth
ARTDM 170, Week 11: User Interaction
The Ring programming language version 1.9 book - Part 60 of 210
Shootting Game
WebGL 3D player
Kivy Talk Python Meetup Innsbruck 2017.04.25
Teaching Python to 9 Year Old Girl - map mover
Async Testing giving you a sinking feeling
Introduction to three.js & Leap Motion
The Ring programming language version 1.6 book - Part 52 of 189
Model View Intent on Android
The Ring programming language version 1.10 book - Part 66 of 212
Ad

Similar to Useful Tools for Making Video Games - XNA (2008) (20)

KEY
Leaving Flatland: getting started with WebGL
PDF
XNA L07–Skybox and Terrain
PPTX
Tricks to Making a Realtime SurfaceView Actually Perform in Realtime - Maarte...
PDF
I wanted to change the cloudsrectangles into an actuall image it do.pdf
PDF
Google Fit, Android Wear & Xamarin
PPT
Graphical User Components Part 2
PDF
Qt Animation
PPTX
Java ME - 05 - Game API
PDF
Games 3 dl4-example
PDF
Begin three.js.key
PDF
Enhance your world with ARKit. UA Mobile 2017.
PPTX
Introduction to open gl in android droidcon - slides
PPTX
Developing AIR for Android with Flash Professional
PDF
303 TANSTAAFL: Using Open Source iPhone UI Code
PDF
HTML5 - Daha Flash bir web?
PPT
Advanced Game Development with the Mobile 3D Graphics API
PPTX
java_for_future_15-Multithreaded-Graphics.pptx
PPTX
Unity3 d devfest-2014
PDF
Webgl para JavaScripters
PDF
How to Create Custom Shaders in Flutter?
Leaving Flatland: getting started with WebGL
XNA L07–Skybox and Terrain
Tricks to Making a Realtime SurfaceView Actually Perform in Realtime - Maarte...
I wanted to change the cloudsrectangles into an actuall image it do.pdf
Google Fit, Android Wear & Xamarin
Graphical User Components Part 2
Qt Animation
Java ME - 05 - Game API
Games 3 dl4-example
Begin three.js.key
Enhance your world with ARKit. UA Mobile 2017.
Introduction to open gl in android droidcon - slides
Developing AIR for Android with Flash Professional
303 TANSTAAFL: Using Open Source iPhone UI Code
HTML5 - Daha Flash bir web?
Advanced Game Development with the Mobile 3D Graphics API
java_for_future_15-Multithreaded-Graphics.pptx
Unity3 d devfest-2014
Webgl para JavaScripters
How to Create Custom Shaders in Flutter?
Ad

More from Korhan Bircan (11)

PDF
Cross-Platform App Development with Flutter, Xamarin, React Native
PDF
Useful Tools for Making Video Games - fmod (2008)
PDF
Password Cracking with Rainbow Tables
PDF
Useful Tools for Making Video Games - Ogre (2008)
PDF
Next-Gen shaders (2008)
PDF
Useful Tools for Making Video Games - Newton (2008)
PDF
Useful Tools for Making Video Games - Irrlicht (2008)
PDF
Korhan bircan
PDF
Core Data with Swift 3.0
PPTX
ios_summit_2016_korhan
PDF
Background Audio Playback
Cross-Platform App Development with Flutter, Xamarin, React Native
Useful Tools for Making Video Games - fmod (2008)
Password Cracking with Rainbow Tables
Useful Tools for Making Video Games - Ogre (2008)
Next-Gen shaders (2008)
Useful Tools for Making Video Games - Newton (2008)
Useful Tools for Making Video Games - Irrlicht (2008)
Korhan bircan
Core Data with Swift 3.0
ios_summit_2016_korhan
Background Audio Playback

Recently uploaded (20)

PDF
BIO-INSPIRED HORMONAL MODULATION AND ADAPTIVE ORCHESTRATION IN S-AI-GPT
PDF
Accra-Kumasi Expressway - Prefeasibility Report Volume 1 of 7.11.2018.pdf
PDF
A SYSTEMATIC REVIEW OF APPLICATIONS IN FRAUD DETECTION
PDF
SMART SIGNAL TIMING FOR URBAN INTERSECTIONS USING REAL-TIME VEHICLE DETECTI...
PDF
Exploratory_Data_Analysis_Fundamentals.pdf
PPTX
Current and future trends in Computer Vision.pptx
PDF
737-MAX_SRG.pdf student reference guides
PDF
Categorization of Factors Affecting Classification Algorithms Selection
PDF
ChapteR012372321DFGDSFGDFGDFSGDFGDFGDFGSDFGDFGFD
PDF
Human-AI Collaboration: Balancing Agentic AI and Autonomy in Hybrid Systems
PDF
Improvement effect of pyrolyzed agro-food biochar on the properties of.pdf
PDF
Abrasive, erosive and cavitation wear.pdf
PPTX
Management Information system : MIS-e-Business Systems.pptx
PDF
III.4.1.2_The_Space_Environment.p pdffdf
PPTX
6ME3A-Unit-II-Sensors and Actuators_Handouts.pptx
PPT
INTRODUCTION -Data Warehousing and Mining-M.Tech- VTU.ppt
PPTX
CyberSecurity Mobile and Wireless Devices
PDF
Visual Aids for Exploratory Data Analysis.pdf
PPTX
Fundamentals of safety and accident prevention -final (1).pptx
PDF
Level 2 – IBM Data and AI Fundamentals (1)_v1.1.PDF
BIO-INSPIRED HORMONAL MODULATION AND ADAPTIVE ORCHESTRATION IN S-AI-GPT
Accra-Kumasi Expressway - Prefeasibility Report Volume 1 of 7.11.2018.pdf
A SYSTEMATIC REVIEW OF APPLICATIONS IN FRAUD DETECTION
SMART SIGNAL TIMING FOR URBAN INTERSECTIONS USING REAL-TIME VEHICLE DETECTI...
Exploratory_Data_Analysis_Fundamentals.pdf
Current and future trends in Computer Vision.pptx
737-MAX_SRG.pdf student reference guides
Categorization of Factors Affecting Classification Algorithms Selection
ChapteR012372321DFGDSFGDFGDFSGDFGDFGDFGSDFGDFGFD
Human-AI Collaboration: Balancing Agentic AI and Autonomy in Hybrid Systems
Improvement effect of pyrolyzed agro-food biochar on the properties of.pdf
Abrasive, erosive and cavitation wear.pdf
Management Information system : MIS-e-Business Systems.pptx
III.4.1.2_The_Space_Environment.p pdffdf
6ME3A-Unit-II-Sensors and Actuators_Handouts.pptx
INTRODUCTION -Data Warehousing and Mining-M.Tech- VTU.ppt
CyberSecurity Mobile and Wireless Devices
Visual Aids for Exploratory Data Analysis.pdf
Fundamentals of safety and accident prevention -final (1).pptx
Level 2 – IBM Data and AI Fundamentals (1)_v1.1.PDF

Useful Tools for Making Video Games - XNA (2008)

  • 1. 1 Useful Tools for Making Video Games Part V An overview of
  • 2. 2 Things you need to install Visual Studio 2005 or Visual C# Express Edition Its service pack XNA Game Studio http://creators.xna.com/Education/ newtoxna.aspx
  • 3. 3 Displaying a 3D Model Create a Windows Game project
  • 4. 4 Displaying a 3D Model Add model to solution
  • 5. 5 Displaying a 3D Model // Set the 3D model to draw. Model myModel; // The aspect ratio determines how to scale 3d to 2d projection. float aspectRatio; protected override void LoadGraphicsContent(bool loadAllContent) { if (loadAllContent) { myModel = content.Load<Model>(“myModel"); } aspectRatio = graphics.GraphicsDevice.Viewport.Width / graphics.GraphicsDevice.Viewport.Height; }
  • 6. 6 Displaying a 3D Model // Set the position of the model in world space, and set the rotation. Vector3 modelPosition = Vector3.Zero; float modelRotation = 0.0f; // Set the position of the camera in world space, for our view matrix. Vector3 cameraPosition = new Vector3(0.0f, 50.0f, 5000.0f); protected override void Draw(GameTime gameTime) { graphics.GraphicsDevice.Clear(Color.CornflowerBlue); // Copy any parent transforms. Matrix[] transforms = new Matrix[myModel.Bones.Count]; myModel.CopyAbsoluteBoneTransformsTo(transforms); // Draw the model. A model can have multiple meshes, so loop. foreach (ModelMesh mesh in myModel.Meshes) { // This is where the mesh orientation is set, as well as our camera and projection. foreach (BasicEffect effect in mesh.Effects) { effect.EnableDefaultLighting(); effect.World = transforms[mesh.ParentBone.Index] * Matrix.CreateRotationY(modelRotation) * Matrix.CreateTranslation(modelPosition); effect.View = Matrix.CreateLookAt(cameraPosition, Vector3.Zero, Vector3.Up); effect.Projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(45.0f), aspectRatio, 1.0f, 10000.0f); } // Draw the mesh, using the effects set above. mesh.Draw(); } }
  • 7. 7 Displaying a 3D Model Transformation of model done through modifying its world matrix // update rotation angle protected override void Update(GameTime gameTime) { if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed) this.Exit(); modelRotation += (float)gameTime.ElapsedGameTime.TotalMilliseconds * MathHelper.ToRadians(0.1f); base.Update(gameTime); } Sample implementation can be found in Loading_3D_Model.zip
  • 8. 8 Keyboard and Mouse input In the Update() function check for input KeyboardState keyboardState = Keyboard.GetState(); if (keyboardState.IsKeyDown( Keys.Left ) {…} mouseState is pressed as long as you keep your finger on the button, usually you want to detect the event once MouseState mouseState = Mouse.GetState(); if (mouseState.LeftButton == ButtonState.Released) released = true; // this is a global boolean if (mouseState.LeftButton == ButtonState.Pressed && released) { released = false; System.Console.WriteLine("left mouse clickedn"); }
  • 9. 9 Camera Determine the location and orientation of the camera object. Create a view matrix using the camera position, orientation, and the world space's up vector. Create a perspective matrix that determines the near and far clipping planes and the aspect of the projection. In the Draw method of game, initialize a BasicEffect object with the transformational matrices created earlier (world, view projection) and then render all existing 3D models.
  • 10. 10 Camera Matrix view = Matrix.CreateLookAt(cameraPosition, cameraLookat, cameraUp); Matrix proj = Matrix.CreatePerspectiveFieldOfView(viewAngle, aspectRatio, nearClip, farClip); foreach (ModelMesh mesh in model.Meshes) { foreach (BasicEffect be in mesh.Effects) { be.Projection = proj; be.View = view; be.World = world; // eg. Matrix.CreateTranslation(…) } mesh.Draw(); } Sample implementation can be found in Camera.zip
  • 11. 11 Skybox apply a skybox-style TextureCube ("cube map") to a sphere using shader Effect SkySphereEffect = Content.Load<Effect>("SkySphere"); TextureCube SkyboxTexture = Content.Load<TextureCube>("uffizi_cross"); // Set the parameters of the effect SkySphereEffect.Parameters["ViewMatrix"].SetValue(myCamera.ViewMatrix); SkySphereEffect.Parameters["ProjectionMatrix"].SetValue(projectionMatrix); SkySphereEffect.Parameters["SkyboxTexture"].SetValue(SkyboxTexture); Since the Effect and the Model are loaded separately, you need to apply the SkySphere effect to each Effect property on the ModelMeshPart of the SkySphere model. Sample implementation can be found in skysphere.zip
  • 12. 12 Animation Curve’s allows a path to be defined by a small number of control points with the Curve’s calculating the points on the path between the control points Add Curve3D.cs (found under cs134/lib/xna/content) to your project. Create two instances of this class, one for the position of the camera and the other for the lookAt vector. Also add variable to keep track of time:
  • 13. 13 Animation Define a function called InitCurve() and specify the points that the camera will pass throught and the points that the camera will be looking at. The number of points on the position and the lookAt curves don’t need to match, but the first and the last points on the curves should have the same time values if the curves oscillate calculate the camera’s current position and orientation and update the view matrix Sample implementation can be found in Animation.zip