Jump to content
  • Advertisement
Sign in to follow this  
cptrnet

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.

If you intended to correct an error in the post then please contact us.

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

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.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 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
I can't see anything directly wrong with it.....what piece of UVVERTS is wrong after those constructor calls?

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
I can put the UVVERTEX for the function parameter and it works fine. I just dont want a function for every type of vertex.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!