Inheritance problem

Started by
5 comments, last by cptrnet 19 years ago
Hello, I have a base structure and two sub structures that inherit from it. Then I have a function that takes a BASEVERTEX parameter. When I pass in DIFFUSEVERTEX it converts just fine to a BASEVERTEX, but when I pass in UVVERTEX I get weird number that werent in the original UVVERTEX.

struct BASEVERTEX
{
	D3DXVECTOR3 Position;

	BASEVERTEX(float fx = 0.0f, float fy = 0.0f, float fz = 0.0f)
	{
		Position = D3DXVECTOR3(fx,fy,fz);
	}
};

struct DIFFUSEVERTEX : public BASEVERTEX
{
	D3DCOLOR Color;
	static const DWORD Format = D3DFVF_XYZ | D3DFVF_DIFFUSE;

	DIFFUSEVERTEX(float fx = 0.0f, float fy = 0.0f, float fz = 0.0f, 
				  D3DCOLOR color = BLACK) : BASEVERTEX(fx,fy,fz)
	{
		Color = color;
	}
};

struct UVVERTEX : public BASEVERTEX
{
	float u, v;
	static const DWORD Format = D3DFVF_XYZ | D3DFVF_TEX1;

	UVVERTEX(float fx = 0.0f, float fy = 0.0f, float fz = 0.0f, 
			 float fu = 0.0f, float fv = 0.0f) : BASEVERTEX(fx,fy,fz)
	{
		u = fu;
		v = fv;
	}
};

If you insist on saying "DUH", try to make a post that makes a little more sense
Advertisement
You get a wierd number for the u and v coordinates or a wierd number for the positioN?

The inheritance structure looks OK. At least, you're not doing anything obviously wrong. Post the function that takes BASEVERTEX and I'll see what I can do.

Matt
VSEDebug Visual Studio.NET Add-In. Enhances debugging in ways never thought possible.
Here is the function
void CalculateBoundingBox(BASEVERTEX *vertices, long numOfVerts){	for(int i = 0; i < numOfVerts; i++)	{		//Calculate the X min and max		if (vertices.Position.x < boundingBox.min.x)		{				boundingBox.min.x = vertices.Position.x;		}		if (vertices.Position.x > boundingBox.max.x)		{				boundingBox.max.x = vertices.Position.x;		}		//Calculate the Y min and max		if (vertices.Position.y < boundingBox.min.y)		{				boundingBox.min.y = vertices.Position.y;		}		if (vertices.Position.y > boundingBox.max.y)		{				boundingBox.max.y= vertices.Position.y;		}		//Calculate the Z min and max		if (vertices.Position.z < boundingBox.min.z)		{				boundingBox.min.z = vertices.Position.z;		}		if (vertices.Position.z > boundingBox.max.z)		{				boundingBox.max.z = vertices.Position.z;		}	}}


And this is where I call it

//This constructor worksQuadrilateral(D3DDevice *pD3DDevice, 	DIFFUSEVERTEX vertex1 = DIFFUSEVERTEX( 0.0f,  0.0f, 0.0f, BLACK), 	DIFFUSEVERTEX vertex2 = DIFFUSEVERTEX(50.0f,  0.0f, 0.0f, BLACK),	DIFFUSEVERTEX vertex3 = DIFFUSEVERTEX( 0.0f, 50.0f, 0.0f, BLACK), 	DIFFUSEVERTEX vertex4 = DIFFUSEVERTEX(50.0f, 50.0f, 0.0f, BLACK)	){	texture		= NULL;	diffuseVerts[0] = vertex1;	diffuseVerts[1] = vertex2;	diffuseVerts[2] = vertex3;	diffuseVerts[3] = vertex4;	CalculateBoundingBox(diffuseVerts, 4);}//This constructor get incorrect resultsQuadrilateral(D3DDevice *pD3DDevice, Texture *pTexture,	UVVERTEX vertex1 = UVVERTEX( 0.0f,  0.0f, 0.0f, 0.0f, 0.0f), 	UVVERTEX vertex2 = UVVERTEX(50.0f,  0.0f, 0.0f, 1.0f, 0.0f),	UVVERTEX vertex3 = UVVERTEX( 0.0f, 50.0f, 0.0f, 0.0f, 1.0f), 	UVVERTEX vertex4 = UVVERTEX(50.0f, 50.0f, 0.0f, 1.0f, 1.0f)	){	texture	   = pTexture;	uvVerts[0] = vertex1;	uvVerts[1] = vertex2;	uvVerts[2] = vertex3;	uvVerts[3] = vertex4;	CalculateBoundingBox(uvVerts, 4);			}
If you insist on saying "DUH", try to make a post that makes a little more sense
does anyone have any idea?
If you insist on saying "DUH", try to make a post that makes a little more sense
I can't see anything directly wrong with it.....what piece of UVVERTS is wrong after those constructor calls?
VSEDebug Visual Studio.NET Add-In. Enhances debugging in ways never thought possible.
The numbers are screwed up such as Z for the second vert is 50, and X and Y for the 3rd and 4th vert are -1.58795 or something. I put a break point on the function call, and its fine before, but then when it gets to the function the data is a screwed up.
If you insist on saying "DUH", try to make a post that makes a little more sense
I can put the UVVERTEX for the function parameter and it works fine. I just dont want a function for every type of vertex.
If you insist on saying "DUH", try to make a post that makes a little more sense

This topic is closed to new replies.

Advertisement