# Practical DX Transforms.

## Recommended Posts

luke2    100
Hello, I have two questions: A: How should I organize my DirectX transformation code for optimal useability and speed? I currently have a rather messy Object3D class which deals with translations and it needs to be inherited by anything that wants to 'move' around. Also, I presume that the camera should stay still (at the origin pointing down an axis); so how would I make it so that I could efficiently make things move opposite to the camera's 'movement'? B: Secondly, I wrote an X file mesh wrapper and although it takes practically all of the code for loading and rendering the mesh from the DirectX doc tutorial #6, it loads the mesh fine, but no texture shows; even though it looks like the code should support it. (The DX mesh veiwer shows the same mesh with a texture, and it also appears that the X files also hold their own textures, is this true?) and just for reference, here is my X file loading source:
DXGeomBuffer::DXGeomBuffer(char* file, IDirect3DDevice9* dxDevice, IDirect3D9* dxObject)
{
if(dxDevice != NULL)
dx3DDevice = dxDevice;
if(dxObject != NULL)
dx3DObject = dxObject;

ID3DXBuffer* pMatBuffer;
// Load the mesh from the specified file
dxDevice, NULL, &pMatBuffer, NULL,
&numMaterials, &pMesh ) ) )
{
return;
}
//Get Material buffer pointer.
D3DXMATERIAL*		d3dxMaterials = (D3DXMATERIAL*)pMatBuffer->GetBufferPointer();

//Create arrays for material and texture information.
D3DMATERIAL9*		g_pMeshMaterials = new D3DMATERIAL9[numMaterials];
LPDIRECT3DTEXTURE9*	g_pMeshTextures  = new LPDIRECT3DTEXTURE9[numMaterials];

//Load the data into those arrays.
for(unsigned int i = 0; i < numMaterials; i++)
{
g_pMeshMaterials[i] = d3dxMaterials[i].MatD3D;
g_pMeshMaterials[i].Ambient = g_pMeshMaterials[i].Diffuse;
if( FAILED( D3DXCreateTextureFromFile( dx3DDevice, d3dxMaterials[i].pTextureFilename, &g_pMeshTextures[i] ) ) )
g_pMeshTextures[i] = NULL;
}

It borrows quite heavily from the DX tutorial #6.

##### Share on other sites
blaze02    100
One) You should work with each matrix individually.
Your projection matrix defines what type of camera you are using.
Your view matrix determines where the camera is.

Adjust each separately and they shouldn't interfere with each other.

Two) Open up the .x file with a text editor. Search for one of the file names (or just .png or .bmp) and find where in the file, the texture filenames are. I'm guessing that the full path of the texture is in the file. Its probably easiest to put the .x file and textures in the same directory, and in the model file, leave only the "texture.bmp" filename without the directory structure.

Hope that helps.