MULTIMEDIA

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(
D3DXMATRIX *pOut,
FLOAT sx,
FLOAT sy,
FLOAT sz
);

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(
D3DXMATRIX *pOut,
FLOAT x,
FLOAT y,
FLOAT z
);

Other  
  •  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
  •  
    Most View
    Windows Azure : Messaging with the queue - Working with basic queue operations
    OTL – a new direction of electric tube amplifier
    Rosewill RNX-N600UBE
    Advanced Compacts - Pocket Power House (Part 1) : Canon Powershot G15, Fujifilm XF1
    The Truth About Android Security (Part 1)
    Windows Server 2008 : Create Virtual Hard Drives and Machines
    iPhone 3D Programming : Textures and Image Capture - Generating and Transforming OpenGL Textures with Quartz
    Plantronics Gamecom 780
    IIS 7.0 : Troubleshooting - Using Tools and Utilities
    Learn How To... Organize Your Photographs
    Top 10
    Zalman CNPS9900DF Cooling Device Review (Part 3)
    Zalman CNPS9900DF Cooling Device Review (Part 2)
    Zalman CNPS9900DF Cooling Device Review (Part 1)
    Nexus 10 - Ultra-High Resolution (Part 4)
    Nexus 10 - Ultra-High Resolution (Part 3)
    Nexus 10 - Ultra-High Resolution (Part 2)
    Nexus 10 - Ultra-High Resolution (Part 1)
    Nokia Lumia 920 - Windows Phone 8 And Magic Camera (Part 4)
    Nokia Lumia 920 - Windows Phone 8 And Magic Camera (Part 3)
    Nokia Lumia 920 - Windows Phone 8 And Magic Camera (Part 2)