Hi, my question is sort of hard to explain but I'll try. I'm making a simple model viewer with direct3d 9, it loads mesh data from a .SMD file and stores the vertices in a vertex buffer. Here's how the data looks:
//<int|Parent bone> <float|PosX PosY PosZ> <normal|NormX NormY NormZ> <normal|U V>
axis.tga
0 -2.000000 -2.000000 40.000000 -1.000000 0.000000 0.000000 0.383350 0.578400
0 -2.000000 2.000000 -40.000000 -1.000000 0.000000 0.000000 0.300850 0.314400
0 -2.000000 -2.000000 -40.000000 -1.000000 0.000000 0.000000 0.383350 0.314400
axis.tga
0 -2.000000 -2.000000 40.000000 -1.000000 0.000000 0.000000 0.713350 0.578400
0 -2.000000 2.000000 40.000000 -1.000000 0.000000 0.000000 0.630850 0.578400
0 -2.000000 2.000000 -40.000000 -1.000000 0.000000 0.000000 0.630850 0.314400
axis.tga
0 -2.000000 2.000000 -40.000000 0.000000 0.000000 -1.000000 0.630850 0.314400
0 2.000000 -2.000000 -40.000000 0.000000 0.000000 -1.000000 0.465850 0.314400
0 -2.000000 -2.000000 -40.000000 0.000000 0.000000 -1.000000 0.383350 0.314400
...
The only values I need are PosX-Y-Z, NormX-Y-Z, and U-V. This is how I load them into the vertex buffer:
#define D3DFVF_MESHVERTEX (D3DFVF_XYZ|D3DFVF_NORMAL|D3DFVF_TEX1)
struct MESHVERTEX
{
D3DXVECTOR3 Position, Normal;
D3DXVECTOR2 UV;
};
vector<MESHVERTEX> vertices;
vector<WORD> indices;
WORD index = 0;
// Loop
vector<string> s = Split(line, " ");
MESHVERTEX vertex;
vertex.Position = D3DXVECTOR3(StringToFloat(s[1]), StringToFloat(s[2]), StringToFloat(s[3]));
vertex.Normal = D3DXVECTOR3(StringToFloat(s[4]), StringToFloat(s[5]), StringToFloat(s[6]));
vertex.UV = D3DXVECTOR2(StringToFloat(s[7]), StringToFloat(s[8]));
vertices.push_back(vertex);
indices.push_back(index);
index++;
// Loop
LPD3DXMESH mesh = NULL;
// Create the mesh
D3DXCreateMeshFVF((DWORD)vertices.size() / 3, (DWORD)vertices.size(), D3DXMESH_MANAGED, D3DFVF_MESHVERTEX, D3DDevice, &mesh)
// Fill the vertex buffer
VOID* pVertices;
mesh->LockVertexBuffer(D3DLOCK_DISCARD, (void**)&pVertices)
memcpy(pVertices, &(vertices[0]), vertices.size() * sizeof(MESHVERTEX));
mesh->UnlockVertexBuffer();
// Fill the index buffer
VOID* pIndices;
mesh->LockIndexBuffer(D3DLOCK_DISCARD, (void**)&pIndices)
memcpy(pIndices, &(indices[0]), indices.size() * sizeof(WORD));
mesh->UnlockIndexBuffer();
prop.Mesh = mesh;
It seems to work, but when I draw the mesh, the model and texture is flipped around wierd. This is how I draw them:
VOID DrawProp(PROP prop)
{
D3DXMATRIXA16 matScale;
D3DXMATRIXA16 matRotX, matRotY, matRotZ;
D3DXMATRIXA16 matTrans;
// Create the scale matrix
D3DXMatrixScaling(&matScale, prop.Scale.x, prop.Scale.y, prop.Scale.z);
// Create the rotation matrices
D3DXMatrixRotationX(&matRotX, DEGTORAD(prop.Rotation.x)); // Pitch
D3DXMatrixRotationY(&matRotY, DEGTORAD(prop.Rotation.y)); // Yaw
D3DXMatrixRotationZ(&matRotZ, DEGTORAD(prop.Rotation.z)); // Roll
// Create the translation/position matrix
D3DXMatrixTranslation(&matTrans, prop.Position.x, prop.Position.y, prop.Position.z);
// Create the world matrix (S * R * T)
D3DXMATRIXA16 matRot = (matRotX * matRotY * matRotZ);
D3DXMATRIX matWorld = matScale * matRot * matTrans;
// Set the world transform to the resulting world matrix
D3DDevice->SetTransform(D3DTS_WORLD, &matWorld);
D3DDevice->SetTexture(0, prop.Textures[0]);
prop.Mesh->DrawSubset(0);
}
I included a couple pics so you can see what I mean, the first one is how the mesh looks when I draw it, the second one is how it's supposed to look (in my modeling program). I've tried everything and I can't figure it out. Any help would be greatly appreciated, thanks!