Jump to content
  • Advertisement


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

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

v.x = ( ( ( 2.0f * point.x ) / rect.right  ) - 1 ) /
v.y = -( ( ( 2.0f * point.y ) / rect.bottom ) - 1 ) / 
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

    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

  • Advertisement

Important Information

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

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!