Jump to content
  • Advertisement
Sign in to follow this  
VanillaSnake21

Drawing Lines

This topic is 4233 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

Advertisement
I have not tested this but it should work. Basically it loads an X file, computes the normals, the runs through each vertex and puts it's normal into the vector.


D3DVERTEXELEMENT9 decl[]=
{
{0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
{0, 12, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0},
{0, 20, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_NORMAL, 0},
D3DDECL_END()
};

//This will hold all the vertices
std::vector<D3DXVECTOR3> Vertices;

ID3DXMesh* Mesh;
ID3DXMesh* TempMesh;

D3DXLoadMeshFromX("somefile.X", D3DXMESH_MANAGED, D3DDevice, NULL, NULL, NULL, NULL, &TempMesh);

TempMesh->CloneMesh(D3DXMESH_MANAGED, decl, D3DDevice, &Mesh);

D3DXComputeNormals(Mesh, NULL);

TempMesh->Release();

typedef struct {
D3DXVECTOR3 VertexPos;
D3DXVECTOR2 TexCoord;
D3DXVECTOR3 Normal;
} Mesh_FVF;

int NumVerticies = Mesh->GetNumVertices();
int NumTris = Mesh->GetNumFaces();
DWORD FVFSize = D3DXGetFVFVertexSize(Mesh->GetFVF());

char *MeshPtr;
Mesh->LockVertexBuffer(D3DLOCK_READONLY, (void**)&MeshPtr);
for(int NumVerts = 0; NumVerts < NumVerticies; NumVerts++)
{
Mesh_FVF *MeshFVF = (Mesh_FVF*)MeshPtr;

MeshFVF->VertexPos;
MeshFVF->TexCoord;
Vertices.push_back(MeshFVF->Normal);

MeshPtr += FVFSize;
}
Mesh->UnlockVertexBuffer();



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!