Jump to content
  • Advertisement
Sign in to follow this  
thedodgeruk

when you load a .x file how do you assoiciate it with a matrix

This topic is 3002 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts


load a .file into a mesh via


MyMesh *tigerMesh;
tigerMesh = myEngine->LoadMesh("tiger.x");




and

MyMesh *MyEngine::LoadMesh(LPCSTR Name)
{
MyMesh *Temp = new MyMesh;// = new MyMesh();
Temp->D3DXMtrlBuffer = NULL;
Temp->NumMaterials = 0;
Temp->Mesh = NULL;


/////////////////////////////////////////////////////
///// LOAD MESH
//////////////////////////////////////////////////////
if (FAILED(D3DXLoadMeshFromX(Name,D3DXMESH_SYSTEMMEM,
gd3dDevice,NULL,&Temp->D3DXMtrlBuffer,NULL,&Temp->NumMaterials,&Temp->Mesh)))
{
MessageBox(0,Name,"Error could not find",0);
}


//////////////////////////////////////////////////////////////
/// FILL IN MESH MATERIALS AND TEXTURES#
////////////////////////////////////////////////////////////////
D3DXMATERIAL* d3dxMaterials = (D3DXMATERIAL*)Temp->D3DXMtrlBuffer->GetBufferPointer();
Temp->MeshMaterials = new D3DMATERIAL9[Temp->NumMaterials];
Temp->MeshTextures = new LPDIRECT3DTEXTURE9[Temp->NumMaterials];

for( DWORD i=0; i<Temp->NumMaterials; i++ )
{
// Copy the material
Temp->MeshMaterials = d3dxMaterials.MatD3D;

// Set the ambient color for the material (D3DX does not do this)
Temp->MeshMaterials.Ambient = Temp->MeshMaterials.Diffuse;

Temp->MeshTextures = NULL;
if( d3dxMaterials.pTextureFilename != NULL &&
lstrlen(d3dxMaterials.pTextureFilename) > 0 )
{
// Create the texture
if( FAILED( D3DXCreateTextureFromFile( gd3dDevice,
d3dxMaterials.pTextureFilename,
&Temp->MeshTextures ) ) )
{
MessageBox(NULL, "Could not find texture map", "Meshes.exe", MB_OK);
}
}
}
return Temp;
}




and display it with this , not sure on this.. but where do you assiocate it with a matrix so you can rotate and move the mesh/model and what code would you use ??

for (DWORD i=0 ; i <tigerMesh->NumMaterials ; i++)
{
gd3dDevice->SetMaterial(&tigerMesh->MeshMaterials);
gd3dDevice->SetTexture(0, tigerMesh->MeshTextures);
tigerMesh->Mesh->DrawSubset(i);
}

Share this post


Link to post
Share on other sites
Advertisement
Before you render the mesh, you can set the "world" matrix, the matrix that describes the scale/rotation/translation of your mesh (with respect to the origin of the world):

dev->SetTransform(D3DTS_WORLD, &meshMatrix);

It would not be uncommon to put the calculation of the matrix (if it changes each frame) and the above statement just before (or in the same function call as) your statement:

for (DWORD i=0 ; i <tigerMesh->NumMaterials ; i++)


If you have other objects, you need to set the world matrix for the device appropriately for each object prior to rendering the object.

Share this post


Link to post
Share on other sites
Quote:
Original post by owiley
you could just rotate the object space if you wanted too.


that dosent make sense , objectspace is the inverse of world , and 0.0 is the center of the object/mesh , what do you mean rotate objectspace?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!