Programming with DirectX : World Transformations

1/12/2011 11:45:39 AM
In modern video games many different 3D objects can be found throughout a scene. Some of these objects are dynamic, such as character models and vehicles, while others are static. Dynamic objects are objects that move either by player control, game physics, or artificial control. Static objects cannot move at all. A static object can be a building, the terrain, or some other object that the designer does not mean to be dynamic.

When objects are created in 3D modeling and animation applications, they are saved out and imported by the game. The vertex positions of these objects are not necessarily the positions they need to be in the game. For example, if a box is created around the origin (0, 0, 0) and that box needs to be in the second story of a virtual building, unless that position just happens to be around the origin, the data needs to be altered. If complex models are created and need to be rendered more than once—for example, having the same box appear 50 times in a level—then it would be inefficient to create the exact same geometry but at different positions again and again so that the boxes load in the correct spots in a game. To further complicate things, dynamic objects need to be moved on the fly. When it comes to character models, how and where these objects move are unpredictable.

The purpose of a world matrix transformation is to position and rotate objects in a 3D scene. This allows characters to move through the world, allows objects to be rendered at multiple locations, and so on. The world matrix represents an object’s position in the game world. This means objects can be created in a modeling package such as 3D Studio Max and moved, rotated, and scaled as necessary so that they appear how the designer requires in a game. This is often done in a level editor, where objects can be positioned, rotated, and scaled. A visual of using world positions to place objects is shown in Figure 1.

Figure 1. Different world positions for the same object.

Scaling refers to changing an object’s size from its original size. To scale a matrix you call the function D3DXMatrixScaling(), which has the following prototype.

D3DXMATRIX * D3DXMatrixScaling(

The D3DXMatrixScaling() function parameters are the matrix that is being scaled and the X, Y, and Z axis factors. To set the position, also known as translation, of a matrix, you use the function D3DXMatrixTranslation(). The function takes the matrix and the positions X, Y, and Z value of the scaling factors. The function prototype for the D3DXMatrixTranslation() can be seen as follows.

D3DXMATRIX* D3DXMatrixTranslation(

  •  Programming with DirectX : Projection Transformations
  •  iPhone 3D Programming : Adding Depth and Realism - Lighting Up (part 2)
  •  iPhone 3D Programming : Adding Depth and Realism - Lighting Up (part 1)
  •  iPhone 3D Programming : Adding Depth and Realism - Surface Normals (part 2)
  •  iPhone 3D Programming : Adding Depth and Realism - Surface Normals (part 1)
  •  iPhone 3D Programming : Adding Depth and Realism - Filling the Wireframe with Triangles
  •  iPhone 3D Programming : Adding Depth and Realism - Creating and Using the Depth Buffer
  •  iPhone 3D Programming : Adding Depth and Realism - Examining the Depth Buffer
  •  iPhone 3D Programming : HelloCone with Fixed Function
  •  iPhone 3D Programming : Vector Beautification with C++
  •  jQuery 1.3 : An image carousel
  •  jQuery 1.3 : Headline rotator
  •  Silverlight : Print a Document
  •  Silverlight : Capture a Webcam
  •  Silverlight : Make Your Application Run out of the Browser
  •  Silverlight : Put Content into a 3D Perspective
  •  Silverlight : Response to Timer Events on the UI Thread
  •  Silverlight : Build a Download and Playback Progress Bar
  •  Silverlight : Play a Video
  •  C# 4.0 : Add a Static Constructor and Initialization
    Top 10
    Windows Vista : Installing and Running Applications - Launching Applications
    Windows Vista : Installing and Running Applications - Applications and the Registry, Understanding Application Compatibility
    Windows Vista : Installing and Running Applications - Practicing Safe Setups
    Windows Server 2003 : Domain Name System - Command-Line Utilities
    Microsoft .NET : Design Principles and Patterns - From Principles to Patterns (part 2)
    Microsoft .NET : Design Principles and Patterns - From Principles to Patterns (part 1)
    Brother MFC-J4510DW - An Innovative All-In-One A3 Printer
    Computer Planet I7 Extreme Gaming PC
    All We Need To Know About Green Computing (Part 4)
    All We Need To Know About Green Computing (Part 3)
    Most View
    Managing Xen : Xen Domain Configuration Files
    Programming WCF Services : Queued Services - Transactions
    Alienware M17X - Best In Class Gaming Performance
    We Help You Find Your Ideal Smartphone (Part 4)
    Choosing The Right Parts For Your Build (Part 3) - Picking the right video card
    Homeplug Problems In A Factory Setting (Part 2)
    Guide To Upgrades With The Greatest Effects (Part 2)
    Microsoft ASP.NET 4 : Profiles - Understanding Profiles
    VMware Fusion 5 - Your Mac is Virtually a PC
    Running Windows 8 (part 2) - Power Plans, Sleep Modes, and Shutdown
    The Ultimate PC Security Toolbox (Part 1)
    The big test … Inter Core Power (Part 1) - Acer Aspire Ethos 8951G
    Windows Vista : Build Your Network (part 4) - Troubleshoot Wireless Networks
    Mac - That Syncing Feeling
    Macbook Air vs. Ultrabook Platform (Part 2)
    Find Yourself With Geolocation Technology (Part 3)
    The Complete Guide To Garageband (Part 1)
    Generation I (For Insecure)?
    Kingston SSDNow mS100 64GB - One Of The Cheapest SSDs Around
    You Can Master RAW (Part 4)