• Advertisement

Archived

This topic is now archived and is closed to further replies.

Trying to make a mesh class which takes several FVFs

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

I’ve got a Mesh class with my vertexdata, indexdata and other things for positon, rotation. I was trying to rewrite my Mesh class to take more then one kind of FVF struct. For example one with position and color and one with position and normal. So I had a look at templates. This are two example FVF’s
// FVF struct

struct Vertex_T
{
	Vertex_T() {}
	Vertex_T(float X, float Y, float Z, D3DCOLOR c)
	{
		position.x = X;
		position.y = Y;
		position.z = Z;
		color = c;
	}

	D3DXVECTOR3 position;
      D3DCOLOR color;		
};

// FVF struct

struct Vertex_TNormal
{
	Vertex_TNormal() {}
	Vertex_TNormal(float X, float Y, float Z, D3DXVECTOR3 n)
	{
		position.x = X;
		position.y = Y;
		position.z = Z;
		normal = n;
	}

	Vertex_TNormal(D3DXVECTOR3 p, D3DXVECTOR3 n)
	{
		position = p;
		normal = n;
	}

	D3DXVECTOR3 position;
      D3DXVECTOR3 normal;  
};
And this is a part of my Mesh class.
 
template <class T>
class CMesh
{
public:
	…
void Setup(int NumVertices, int NumPrimitives, DWORD FVF, T *VertexData, int NumIndices = 0, WORD *IndicesData = NULL);

	T * m_Vertices;
	WORD *m_Indices;
	…
}; 
Then I declare a Cube with the following line: CMesh < Vertex_T > * Cube1; (without spaces.. the forum removes the line with spaces??) I fill it with vertex and index data and then call the setup function. But VC++.NET 2003 gives me the following errors: I have no idea what the problem is. Could someone pleace help me out? RazorApp.obj : error LNK2019: unresolved external symbol "public: __thiscall CMesh::~CMesh(void)" (??1?$CMesh@UVertex_T@@@@QAE@XZ) referenced in function "public: void * __thiscall CMesh::`scalar deleting destructor'(unsigned int)" (??_G?$CMesh@UVertex_T@@@@QAEPAXI@Z) RazorApp.obj : error LNK2019: unresolved external symbol "public: void __thiscall CMesh::Setup(int,int,unsigned long,struct Vertex_T *,int,unsigned short *)" (?Setup@?$CMesh@UVertex_T@@@@QAEXHHKPAUVertex_T@@HPAG@Z) referenced in function "public: virtual bool __thiscall cApp::LoadData(void)" (?LoadData@cApp@@UAE_NXZ) [edited by - Scheermesje on April 14, 2004 4:37:19 AM] [edited by - Scheermesje on April 14, 2004 4:37:48 AM]

Share this post


Link to post
Share on other sites
Advertisement
I''m assuming (since all you gave are snippets) that it''s because you didn''t provide a body for CMesh::Setup in the header file. For templates, it needs to be there.

Try this after the template class declaration

template <class T>
inline void CMesh<T>::Setup (int NumVertices, int NumPrimitives, DWORD FVF, T *VertexData, int NumIndices, WORD *IndicesData)
{
// function body

}

Share this post


Link to post
Share on other sites
By the way, I think templates are the wrong way to deal with FVF. First, you don't know the FVF of a mesh until you've loaded it, so you're not going to avoid the switch statement. This also forces you to have a global LoadMesh function to contain the switch statement, since you can't instantiate a CMesh object of the right type and call Load on it before you know the FVF you're dealing with. Second, it'll make it a lot harder for you to pass mesh ptr/refs as arguments to functions, as two meshes with different FVF will need different functions to deal with them (although you could use templated functions - but this locks you into one mesh type per function). Third, from a logical standpoint, a FVF does not define a mesh so completely that meshes with different FVF should be different data types altogether. Tuck away the FVF differences inside the CMesh class, and try to hide it from the outside. If possible, pick a FVF that your app/game is comfortable with, and convert all meshes to it at load time. Look up ID3DXMesh::CloneMeshFVF.

[edited by - foofightr on April 14, 2004 5:45:12 AM]

Share this post


Link to post
Share on other sites
I have declared the setup function in my CPP file and if I change the T to some vertex type everything is working perfect.

quote:

This also forces you to have a global LoadMesh function to contain the switch statement, since you can''t instantiate a CMesh object of the right type and call Load on it before you know the FVF you''re dealing with



Thnx for the tip.. to be hones I haven''t thougt of that one.

I was doing this because I didn''t like the idea of having different mesh classes for each type of object.. Say some objects have multiple texture coordinates or some have a vertex color and some lightning(I don''t now if this is realistic btw.. maybe all my objects in my ''next game'' will have the same FVF) then I need to write an Mesh class for all different FVF''s I''ve got..

quote:

Third, from a logical standpoint, a FVF does not define a mesh so completely that meshes with different FVF should be different data types altogether. Tuck away the FVF differences inside the CMesh class, and try to hide it from the outside. If possible, pick a FVF that your app/game is comfortable with, and convert all meshes to it at load time. Look up ID3DXMesh::CloneMeshFVF.
[/qoute]

Could you pleace explain this a little bit more?

How to hide the differences from the outside? What if I have one object that uses vertex color and another lightning? Should I define a vertex structure which takes both lightning and color data and in my render class check which one is used or something?

Thnx for your help

Share this post


Link to post
Share on other sites
quote:
Original post by Scheermesje
I have declared the setup function in my CPP file and if I change the T to some vertex type everything is working perfect.



That is exactly what I thought. Because of the mechanics involved in the compiler creating datatypes from the template, template classes need to be completely defined where they are declared, so it''s no good to use CPP files. It all must go in the header, or the header must include whichever file(s) that contain the required definitions (but don''t even think about including the .cpp file!). If you changed T to a specific vertex type and it worked, it''s probably because your class is not templated anymore...

Share this post


Link to post
Share on other sites

  • Advertisement