How to implement drag and drop in Direct3D 9?

Started by
1 comment, last by lucky6969b 10 years, 3 months ago

Hello and Happy New Year everybody,

I wonder how I can implement drag and drop function in Direct3D because

I am interested in building a Game editor...

So there would be a toolbox of primitives on the left hand side of the application,

Then I drag them onto the scene,

Is there any good readings on the web that you would recommend?

Also, when I "pick" one of several objects in the scene that are overlapping,

Do I loop thru them to get the closest object that is facing toward me?

Thanks

Jack

Advertisement

Hi jack. happy.png

I've had this exact problem myself, though I can't say it's fully solved, but, it's close.

So, the first thing you have to consider is that once you click the screen, you have to make some kind of world space ray, which could be done like this:


// PS. I always use the transposed versions of my view and projection matrices.

//getting projection matrix
D3DXMATRIX projMat = *Camera->getProjection();

float vx = (+2.0f*mouseX/viewport.Width  - 1.0f)/projMat._11;
float vy = (-2.0f*mouseY/viewport.Height + 1.0f)/projMat._22;

CEVector3f Origin(0.0f, 0.0f, 0.0f);
CEVector3f Direction(vx, vy, 1.0f);

D3DXMATRIX viewMat = *Camera->getView();
D3DXMatrixTranspose(&viewMat, &viewMat); // Transposing the view matrix (To the original one)

D3DXMATRIX iviewMat;
D3DXMatrixInverse(&iviewMat, 0, &viewMat);
D3DXVec3TransformCoord(&Origin, &Origin, &iviewMat);
D3DXVec3TransformNormal(&Direction, &Direction, &iviewMat);

D3DXVec3Normalize(&Direction, &Direction);

Now the next step can be optimized in many ways, but I'll present a simple way:

  • Loop over all object
  • Does this objects bounding box/sphere collide with this ray?
  • Add it to my vector
  • Loop over all objects in vector
  • Loop over all triangles in this object
  • Does the ray collide with this triangle
  • Store the triangle and the distance (ray start to ray end)
  • Then find the triangle for which the ray had to travel the shortest distance, and we assume that that's our users preferred drop position.

Now this is only one way of accomplishing this, but, it should work. smile.png

Hope this can help you.

-MIGI0027

FastCall22: "I want to make the distinction that my laptop is a whore-box that connects to different network"

Blog about... stuff (GDNet, WordPress): www.gamedev.net/blog/1882-the-cuboid-zone/, cuboidzone.wordpress.com/

Just wondering, in case sometimes I need to stack an object on the top of another or or placing thru the others

For example, a box on top of a sphere. Because the box overlapping the sphere

and on top of it are both valid, wonder which one should prevail,

Should I make up an option for the user to select which method they are using?

Sometimes, when I look at 3ds max, both of these two operations are valid.

The method they use is to draw a base, and dragging upward.

Thanks

Jack

This topic is closed to new replies.

Advertisement