Skip to main content
GameDev.net gamedev.net
🔒 Locked

D3DXVec3TransformCoord() Problem [SOLVED]

Started by Multiverse Sep 20, 2005 at 8:04 AM 4 replies 1.3k views
Original Post
Multiverse
Multiverse
Hi everyone. I'm having a problem with the aformentioned function giving me strange results. I have a function: (by the way, i got the d3d::BoundingBox type from Frank Luna's 'Introduction to 3D Game Programming with DirectX 9.0'. Some of you may be familiar.)

bool Powerup::GetBoundingVolume(d3d::BoundingBox* box)
{
	d3d::BoundingBox tempbox;
	D3DXMATRIX	 mat;

	D3DXMatrixTranslation(&mat, m_Position.x,// create matrix for
                                    m_Position.y,// this blocks
				    m_Position.z);// position

	D3DXVec3TransformCoord( &tempbox.min, &m_BBox.min, &mat); 
	D3DXVec3TransformCoord( &tempbox.max, &m_BBox.max, &mat); 

	*box = tempbox;
	return true;

}






The function works perfectly except for the y value of the bounding box's min and max vectors. the X and Z values are fine, but the Y value is way off. So much so that my collision detections don't work because of it. :( Can anyone tell whats going wrong? Heres a picture of my debug session to confirm that the Y value is insane. [Edited by - Multiverse on September 20, 2005 8:59:21 AM]
Illco
Illco
You have probably already checked this but what are the values of m_BBox.min (resp. max) before the call? The function seems fine thus I'd suspect the input is incorrect.

Note that the first call asks the system to translate whatever is in m_BBox.min by the position of the object and then store the result in m_BBox.min. I'm not sure if that is your intent, because it invalidates a distinct interpretation of m_BBox -- it can be either in world space or in object space; no one can tell...

Illco
Multiverse
Multiverse
Quote:

Note that the first call asks the system to translate whatever is in m_BBox.min by the position of the object and then store the result in m_BBox.min. I'm not sure if that is your intent, because it invalidates a distinct interpretation of m_BBox -- it can be either in world space or in object space; no one can tell...


My understanding of the function is that the values in 'm_BBox' would be transformed by the matrix 'mat' and the result of this would be 'entered' into the tempbox.min/max.

I'll have to look at the documentation...


I have checked the values of m_BBox before the call to ComputeBoundingVolume and they were fine. I'm pretty sure because i was stepping through the code trying to find out exactly what caused the Y values to become so wrong. It turned out to be the ComputeBoundingVolume function.

But, i can't figure out why it doesnt work for the Y and does for the X and Z. The only thing that differentiates the Y position from the X and Z is that the Y position changes, so i would assume that is causing the problem somehow?
Illco
Illco
Quote:

My understanding of the function is that the values in 'm_BBox' would be transformed by the matrix 'mat' and the result of this would be 'entered' into the tempbox.min/max.

That is correct. However at the end of the function tempbox (as the name denotes it was only temporary) is copied to the supplied box:
*box = tempbox;

Your call provides m_BBox as the target for this pointer:
GetBoundingVolume(&m_BBox);

Hence each time this is called the bounding box will be translated once more. If the position (m_Position) has only a non-zero Y-component this will explain the high value of the resulting Y.

Quote:

I have checked the values of m_BBox before the call to ComputeBoundingVolume and they were fine. I'm pretty sure because i was stepping through the code trying to find out exactly what caused the Y values to become so wrong. It turned out to be the ComputeBoundingVolume function.

Have you tried stepping into this function a second time during the same run? The problem may arise when it is called repeatedly. Also check the values of m_Position as they also contribute to the result. The matrix should be fine, as well as the transformation call and its results.

Illco
Multiverse
Multiverse
AHA!

Your right Illco! Thanks a million. I had a nasty hack to get around the problem, but now i can sort it for good!

Thanks again for spotting what i couldnt!
Illco
Illco
Great! Always feels good to be appreciated...

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.