# Inheritance problem

This topic is 4833 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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;
}
};



##### Share on other sites
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

##### Share on other sites
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);			}

##### Share on other sites
does anyone have any idea?

##### Share on other sites
I can't see anything directly wrong with it.....what piece of UVVERTS is wrong after those constructor calls?

##### Share on other sites
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.

##### Share on other sites
I can put the UVVERTEX for the function parameter and it works fine. I just dont want a function for every type of vertex.

• 11
• 20
• 12
• 9
• 34
• ### Forum Statistics

• Total Topics
631399
• Total Posts
2999846
×