Click Here!
home account info subscribe login search My ITKnowledge FAQ/help site map contact us


 
Brief Full
 Advanced
      Search
 Search Tips
To access the contents, click the chapter and section titles.

Cutting Edge Direct 3D Programming
(Publisher: The Coriolis Group)
Author(s): Stan Trujillo
ISBN: 1576100502
Publication Date: 11/01/96

Bookmark It

Search this book:
 
Previous Table of Contents Next


D3DRMVERTEX

Direct3D uses D3DRMVERTEX structure to describe the vertices in a mesh and is defined like this:

typedef struct _D3DRMVERTEX{
    D3DVECTOR position;
    D3DVECTOR normal;
    D3DVALUE  tu, tv;
    D3DCOLOR  color;
} D3DRMVERTEX;

The position vector structure describes the vertex location. The normal vector describes either a vertex normal (in Gouraud mode) or a face vector (in flat mode). The tu and tv values determine the coordinate within a texture that is to be mapped to the vertex. The color entry determines the vertex color.

The D3DRMVERTEX structure is accepted by the Direct3DRMMesh GetVertices() and SetVertices() member functions. GetVertices() fills an array of D3DRMVERTEX structures with the values used by specified vertices. These values can be modified and then passed to SetVertices(), thereby modifying the mesh characteristics. Animation techniques, such as vertex animation and texture animation, can be achieved in this way. Also, a program can override the default normals face or vertex normals with GetVertices() and SetVertices() functions.

D3DRMQUATERNION

Quaternions describe rotation. In Chapter 2 we used a vector and a rotation value to describe a rotation. The vector describes the axis of rotation, and the rotation value describes the amount of rotation. Quaternions encapsulate the vector and the rotation value into one structure:

typedef struct _D3DRMQUATERNION {
    D3DVALUE   s;
    D3DVECTOR  v;
}D3DRMQUATERNION;
typedef D3DRMQUATERNION, *LPD3DRMQUATERNION;

Quaternions can be initialized with the D3DRMQuaternionFromRotation() function. The function takes a vector and a rotation value and creates a quaternion.

Quaternions are useful for calculating intermediate rotation values. The D3DRMQuaternionSlerp() function, for example, accepts two quaternions and a slerp value as arguments. The function calculates an intermediate quaternion between two vectors. The slerp value determines where the new quaternion should be between the two input quaternions. Using a slerp value of 0.5, for example, creates a quaternion that is exactly between the two input quaternions.

HRESULT

The vast majority of DirectX member functions return the HRESULT type as an error code. HRESULT is a 32-bit value that indicates a function’s return status. Direct3D supplies a number of constants that should be used to evaluate these return values. Ideally, functions return the D3DRM_OK constant, indicating that the function call was successful. If the function fails, a value indicating the nature of the failure will be returned.

X Files

The X file format is Direct3D’s native file format. X files can store multiple meshes, frame hierarchies, and complete animations. Textures cannot be stored in X files.

In DirectX 2, Direct3D supports only text versions of X files. DirectX 3 and above supports both text and binary formats.

Text-based X files are typically larger and take longer to load than their binary counterparts, but they can be viewed and edited easily.

X files can be created either with the CONV3DS utility or with a Direct3D program via the Direct3DRMMeshbuilder Save() member function. The Save() function produces only X files that contain meshes.


Tip:  Meshbuilder limitations
If you add a frame hierarchy to a meshbuilder and call the Save() function, the resulting X file will contain all of the objects in the hierarchy, but they will all be part of a single mesh, and the hierarchy will not be present.

Conv3ds

Direct3D includes the CONV3DS utility for the creation of X files. CONV3DS converts 3D Studio files (.3DS) to X files. CONV3DS supplies a number of command-line options. Some of the more useful options are listed in Table 3.1.

Table 3.1 Options for the CONV3DS utility.

Option Explanation
m Produce single mesh instead of frame hierarchy.
t Produce text X files.
A Include animation data (if animation data is present).
f Don’t import frame translation data.

Conclusion

Now that you know what the Direct3D interfaces look like and what they do, we can get to the fun part—the code. In Chapter 4 we will discuss the code in a Direct3D application.


Previous Table of Contents Next


Products |  Contact Us |  About Us |  Privacy  |  Ad Info  |  Home

Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc.
All rights reserved. Reproduction whole or in part in any form or medium without express written permission of EarthWeb is prohibited.