Archived

This topic is now archived and is closed to further replies.

How to select in a 3d world more characters with a click&drag rectangle?

This topic is 4944 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

Hi, using C++/DX9, i''m trying to find out how to select more characters on a 3d world with a mouse-click-and-drag rectangle; by now i select one character at a time, the code i use is this:

GetCursorPos(&point);
ScreenToClient(hWnd, &point);	
GetClientRect(hWnd, &rect); 

// get the inverse matrix of the view matrix

D3DXMATRIX i_matrix;
D3DXMatrixInverse(&i_matrix, NULL, &view_matrix);

// transfrom the click point in 3d space and get ray origin

// vector and ray dir vector

D3DXVECTOR3 v;
v.x = ( ( ( 2.0f * point.x ) / rect.right  ) - 1 ) /
       projection_matrix._11;
v.y = -( ( ( 2.0f * point.y ) / rect.bottom ) - 1 ) / 
       projection_matrix._22;
v.z =  1.0f;

D3DXVECTOR3 vdir, vorig, PointOnTheGround;
vdir.x = v.x * i_mat._11 + v.y * i_mat._21 + v.z * i_mat._31;
vdir.y = v.x * i_mat._12 + v.y * i_mat._22 + v.z * i_mat._32;
vdir.z = v.x * i_mat._13 + v.y * i_mat._23 + v.z * i_mat._33;
vorig.x = i_mat._41;
vorig.y = i_mat._42;
vorig.z = i_mat._43;

// calculate the point on the ground

d = vorig.y / (vdir.y * -1.0f);
PointOnTheGround = vorig + (vdir * d);

// then test if this point is inside a character

if(TestIfInside(&PointOnTheGround,&character))
    character.active = 1;

And now im trying to figure how to make a mouse-click-and-drag rectangle test to select more characters. How to calculate the rectangle done with mouse? How to transform the rectangle area in 3d area to test if some characters are inside there? Could someone help me? Thanks Kev

Share this post


Link to post
Share on other sites