Jump to content

  • Log In with Google      Sign In   
  • Create Account


#ActualNicholas1991

Posted 15 April 2013 - 04:10 PM

Here is some more code to show what is frustrating me. I'm copy&past-ing a lot which is exactly what I want to avoid :/. (I have not yet compiled it (I'm in the middle of rewriting parts of my code :/), so there might be some minor errors.)

 

First the VertexTypes: 

        struct VERTEX1MAP
	{
			DirectX::XMFLOAT3 position;
			DirectX::XMFLOAT3 normal;
			DirectX::XMFLOAT2 mapcoord[1];
	};

	struct VERTEX2MAP
	{
			DirectX::XMFLOAT3 position;
			DirectX::XMFLOAT3 normal;
			DirectX::XMFLOAT2 mapcoord[2];
	};

	struct VERTEX3MAP
	{
			DirectX::XMFLOAT3 position;
			DirectX::XMFLOAT3 normal;
			DirectX::XMFLOAT2 mapcoord[3];
	};


... and so on

 

 

And here are the methods used to fill the VertexArrays:

VERTEX1MAP BinaryMeshExporter::getFilledVertexType1(const Point3& position, const Point3& normal, const UVVert* uv, const pair<int,int>& uvAccess)
{
	VERTEX1MAP out;
	out.position = Point3ToXMFLOAT3(position);
	out.normal = Point3ToXMFLOAT3(normal);
	out.mapcoord[0] = XMFLOAT2(uv[0][uvAccess.first], -uv[0][uvAccess.second]);
	return out;	
}

VERTEX2MAP BinaryMeshExporter::getFilledVertexType2(const Point3& position, const Point3& normal, const UVVert* uv, const pair<int,int>& uvAccess)
{
	VERTEX2MAP out;
	out.position = Point3ToXMFLOAT3(position);
	out.normal = Point3ToXMFLOAT3(normal);
	for ( int i=0; i<2; i++ )
		out.mapcoord[i] = XMFLOAT2(uv[i][uvAccess.first], -uv[i][uvAccess.second]);
	return out;
}

VERTEX3MAP BinaryMeshExporter::getFilledVertexType3(const Point3& position, const Point3& normal, const UVVert* uv, const pair<int,int>& uvAccess)
{
	VERTEX3MAP out;
	out.position = Point3ToXMFLOAT3(position);
	out.normal = Point3ToXMFLOAT3(normal);
	for ( int i=0; i<2; i++ )
		out.mapcoord[i] = XMFLOAT2(uv[i][uvAccess.first], -uv[i][uvAccess.second]);
	return out;
}


... And so on

 

Now as you can see, they are basically identical except for the array size of mapcoord. And also the fillmethods are identical except for the VertexType they use.

Is there any kind of polymorphic concept for structs (without changing the structs size)?

 

I'm really desperate to change the code above (for the better), but I do not see how :/.


#1Nicholas1991

Posted 15 April 2013 - 04:09 PM

Here is some more code to show what is frustrating me. I'm copy&past-ing a lot which is exactly what I want to avoid :/. (I have not yet compiled it (I'm in the middle of rewriting parts of my code :/), so there might be some minor errors.)

 

First the VertexTypes: 

        struct VERTEX1MAP
	{
			DirectX::XMFLOAT3 position;
			DirectX::XMFLOAT3 normal;
			DirectX::XMFLOAT2 mapcoord[1];
	};

	struct VERTEX2MAP
	{
			DirectX::XMFLOAT3 position;
			DirectX::XMFLOAT3 normal;
			DirectX::XMFLOAT2 mapcoord[2];
	};

	struct VERTEX3MAP
	{
			DirectX::XMFLOAT3 position;
			DirectX::XMFLOAT3 normal;
			DirectX::XMFLOAT2 mapcoord[3];
	};


... and so on

 

 

And here are the methods used to fill the VertexArrays:

VERTEX1MAP& BinaryMeshExporter::getFilledVertexType1(const Point3& position, const Point3& normal, const UVVert* uv, const pair<int,int>& uvAccess)
{
	VERTEX1MAP out;
	out.position = Point3ToXMFLOAT3(position);
	out.normal = Point3ToXMFLOAT3(normal);
	out.mapcoord[0] = XMFLOAT2(uv[0][uvAccess.first], -uv[0][uvAccess.second]);
	return out;	
}

VERTEX2MAP& BinaryMeshExporter::getFilledVertexType2(const Point3& position, const Point3& normal, const UVVert* uv, const pair<int,int>& uvAccess)
{
	VERTEX2MAP out;
	out.position = Point3ToXMFLOAT3(position);
	out.normal = Point3ToXMFLOAT3(normal);
	for ( int i=0; i<2; i++ )
		out.mapcoord[i] = XMFLOAT2(uv[i][uvAccess.first], -uv[i][uvAccess.second]);
	return out;
}

VERTEX3MAP& BinaryMeshExporter::getFilledVertexType3(const Point3& position, const Point3& normal, const UVVert* uv, const pair<int,int>& uvAccess)
{
	VERTEX3MAP out;
	out.position = Point3ToXMFLOAT3(position);
	out.normal = Point3ToXMFLOAT3(normal);
	for ( int i=0; i<2; i++ )
		out.mapcoord[i] = XMFLOAT2(uv[i][uvAccess.first], -uv[i][uvAccess.second]);
	return out;
}


... And so on

 

Now as you can see, they are basically identical except for the array size of mapcoord. And also the fillmethods are identical except for the VertexType they use.

Is there any kind of polymorphic concept for structs (without changing the structs size)?

 

I'm really desperate to change the code above (for the better), but I do not see how :/.

 

 

 


PARTNERS