Game Development Reference
In-Depth Information
info of a mesh. Since adjacency info is stored as a DWORD array, we have
to cast the buffer to a DWORD array when we wish to use the adjacency
info from the buffer.
Examples :
DWORD* info =(DWORD*)adjacencyInfo->GetBufferPointer();
D3DXMATERIAL* mtrls = (D3DXMATERIAL*)mtrlBuffer->GetBufferPointer();
Since an ID3DXBuffer is a COM object, it must be released when you
are done with it to avoid a memory leak:
adjacencyInfo->Release();
mtrlBuffer->Release();
We can create an empty ID3DXBuffer using the following function:
HRESULT D3DXCreateBuffer(
DWORD NumBytes, // Size of the buffer, in bytes.
LPD3DXBUFFER *ppBuffer // Returns the created buffer.
);
The following example creates a buffer that can hold four integers:
ID3DXBuffer* buffer = 0;
D3DXCreateBuffer( 4 * sizeof(int), &buffer );
11.2 XFiles
Thus far, we have worked with simple geometric objects, such as
spheres, cylinders, cubes, etc., using the D3DXCreate* functions. If
you have attempted to construct your own 3D object by manually speci-
fying the vertices, you have, no doubt, found it quite tedious. To
alleviate this tiresome task of constructing the data of 3D objects, spe-
cial applications called 3D modelers have been developed. These
modelers allow the user to build complex and realistic meshes in a
visual and interactive environment with a rich tool set, making the
entire modeling process much easier. Examples of popular modelers
used for game development are 3DS Max (www.discreet.com),
LightWave 3D (www.newtek.com), and Maya (www.aliaswave-
front.com).
These modelers, of course, can export the created mesh data
(geometry, materials, animations, and other possible useful data) to a
file. Thus, we could write a file reader to extract the mesh data and use
it in our 3D applications. This is certainly a viable solution. However,
an even more convenient solution exists. There is a particular mesh file
format called the XFile format (with the extension .X). Many 3D model-
ers can export to this format and there exist converters that can
Search WWH ::




Custom Search