Sign in to follow this  
cptrnet

Inheritance problem

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 this post


Link to post
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 this post


Link to post
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[i].Position.x < boundingBox.min.x)
{
boundingBox.min.x = vertices[i].Position.x;
}
if (vertices[i].Position.x > boundingBox.max.x)
{
boundingBox.max.x = vertices[i].Position.x;
}

//Calculate the Y min and max
if (vertices[i].Position.y < boundingBox.min.y)
{
boundingBox.min.y = vertices[i].Position.y;
}
if (vertices[i].Position.y > boundingBox.max.y)
{
boundingBox.max.y= vertices[i].Position.y;
}

//Calculate the Z min and max
if (vertices[i].Position.z < boundingBox.min.z)
{
boundingBox.min.z = vertices[i].Position.z;
}
if (vertices[i].Position.z > boundingBox.max.z)
{
boundingBox.max.z = vertices[i].Position.z;
}
}
}



And this is where I call it



//This constructor works

Quadrilateral(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 results

Quadrilateral(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 this post


Link to post
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 this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this