Skip to main content
gamedev.net
🔒 Locked 🎮 Unity

Bounding Boxes

Started by dehseth 1 reply 1k views
Original Post
dehseth
dehseth
Hey guys, I got a new question regarding this topic: http://www.gamedev.net/community/forums/topic.asp?topic_id=336374 I use DirectX 9.0c and MS VC++ (non-managed). I have created lots of boxes using D3DXCreateBox and I place them using D3DXMatrixTranslation. So when I draw them I use translation first. There are no collision in boxes. And I would like to color the box when mouse is over it. So I use a picking ray. My problem is how to get min and max using D3DXBoxBoundProbe. First I tried to give this parameter to D3DXBoxBoundProbe function cause boxes do not change place. But this method did not work out cause it can select the near box. Maybe I need to calculate bounding box by using D3DXComputeBoundingBox but I dunno how to get "CONST D3DXVECTOR3 * pFirstPosition" since I do not create FVF for it. One more thing is it enough to calculate bounding box only once when I initializing application or should I need to calculate it each time on mouse move? this is how I calculate picking ray: float px = 0.0f; float py = 0.0f; D3DVIEWPORT9 vp; d3ddev->GetViewport(&vp); D3DXMATRIX proj; d3ddev->GetTransform(D3DTS_PROJECTION, &proj); px = ((( 2.0f*x) / vp.Width) - 1.0f) / proj(0, 0); py = (((-2.0f*y) / vp.Height) + 1.0f) / proj(1, 1); origin = D3DXVECTOR3(0.0f, 0.0f, 0.0f); direction = D3DXVECTOR3(px, py, 1.0f); // transform the ray to world space D3DXMATRIX view; d3ddev->GetTransform(D3DTS_VIEW, &view); D3DXMATRIX viewInverse; D3DXMatrixInverse(&viewInverse, 0, &view); // transform the ray's origin, w = 1. D3DXVec3TransformCoord(&origin, &origin, T); // transform the ray's direction, w = 0. D3DXVec3TransformNormal(&direction, &direction, T); // normalize the direction D3DXVec3Normalize(&direction, &direction); Thank you all guys...
MCA
K1nG Gr4H4m
K1nG Gr4H4m
The min and max parameters are outputs from the D3DXComputeBoundingBox() function. You don't have to create a vertex and index buffer, so you can just sent position data in it. Something like this:

SimpleVertex vertices[] =    {        { D3DXVECTOR3( -1.0f,  1.0f, -1.0f ), D3DXVECTOR4( 0.0f, 0.0f, 1.0f, 1.0f ) },        { D3DXVECTOR3(  1.0f,  1.0f, -1.0f ), D3DXVECTOR4( 0.0f, 1.0f, 0.0f, 1.0f ) },        { D3DXVECTOR3(  1.0f,  1.0f,  1.0f ), D3DXVECTOR4( 0.0f, 1.0f, 1.0f, 1.0f ) },        { D3DXVECTOR3( -1.0f,  1.0f,  1.0f ), D3DXVECTOR4( 1.0f, 0.0f, 0.0f, 1.0f ) },        { D3DXVECTOR3( -1.0f, -1.0f, -1.0f ), D3DXVECTOR4( 1.0f, 0.0f, 1.0f, 1.0f ) },        { D3DXVECTOR3(  1.0f, -1.0f, -1.0f ), D3DXVECTOR4( 1.0f, 1.0f, 0.0f, 1.0f ) },        { D3DXVECTOR3(  1.0f, -1.0f,  1.0f ), D3DXVECTOR4( 1.0f, 1.0f, 1.0f, 1.0f ) },        { D3DXVECTOR3( -1.0f, -1.0f,  1.0f ), D3DXVECTOR4( 0.0f, 0.0f, 0.0f, 1.0f ) },    };// Create index buffer    DWORD indices[] =    {        3,1,0,        2,1,3,        0,5,4,        1,5,0,        3,4,7,        0,4,3,        1,6,5,        2,6,1,        2,7,6,        3,7,2,        6,4,5,        7,4,6,    };


I copy pasted the stuff from (SDK root)\Samples\C++\Direct3D10\Tutorials\Tutorial04. You'll have to multiply the vectors by your transform, because IIRC the functions use the world coordinates for each vertex to compute the box.
dehseth
dehseth
Seems like you are missing the point. I know what to give as an input to the function. My problem is I need to compute these values...

So as I said I do not create vertex/index buffer by myself I have used Direct3D function to create it for me. And I move it by using transform matrix. It's better to read the first message..
MCA

Topic Locked

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

Sign in to reply to this topic.