0

I am working on drop & drop in 3D. I have created 3D spaces (rooms) with walls (cubes) which act as place holders for objects (assume a smaller cubes) being dropped.

How do I go about figuring out :

if the user drops the object at edges of the room then could the room completely contain that object?

Meaning, I do not want the objects to be partially in the room and partially outside. Ideally I would cancel the drop operation / move it to a point so that room safely contains that object.

I have the bounds of the room & the object (ModelVisual3D.Content.Bounds) and the point at which the object was dropped.

I am thinking I would have to do some math to figure out if the object is placed at that point then it will completely within the bounding room.

ideas/thoughts/pointer appreciated.

CF_Maintainer
  • 973
  • 2
  • 12
  • 30

3 Answers3

0

1. Pick Point A. ( point can be a corner of inner cube CubeIn)

Pick one point from one cube. (I am assuming we are to test one cube is completely inside other one. Mean no intersection).

2. Check A inside CubeOut (Outercube)

3. if A inside CubeOut than CubeIn completely inside CubeOut

if point is inside second cube that mean first cube is inside second.(Why ? because if a cube is inside other cube. So every point on inner cube will be inside the outer cube)

4. Else CubeIn is not inside CubeOut

This will work with all kind of solid entity ( sphere, cone ... ).

Community
  • 1
  • 1
Jai
  • 1,292
  • 4
  • 21
  • 41
0

For any box that is axis aligned, which seems to be the case since you are using bounds, a simple test can tell if an axis aligned box is included in another.

Given the following Box class:

class Box 
{
  Vector3 minEdge;
  Vector3 maxEdge;
}

You can easily have a method inside Box that tests for inclusion:

bool IsInside(Box other)
{
  return maxEdge.X <= other.maxEdge.X &&
         maxEdge.Y <= other.maxEdge.Y &&
         maxEdge.Z <= other.maxEdge.Z &&
         minEdge.X >= other.minEdge.X &&
         minEdge.Y >= other.minEdge.Y &&
         minEdge.Z >= other.minEdge.Z;
}

Please note that this will not work on arbitrarily oriented boxes, only on axis aligned.

Coincoin
  • 27,880
  • 7
  • 55
  • 76
  • not clear on what you mean by axis aligned. The rooms are in the XZ plane with some Y for height of the walls. I have the ModelVisual3D elements corresponding to the 2 boxes. Object being dragged is definetly smaller than then room, problem is user could drag it to the edge of the room where it could overlaps the walls and be partially outside the room. so the point of drop is also important to the calculation. – CF_Maintainer Feb 09 '11 at 21:50
  • Axis aligned means the box sides are aligned with the three world axis. This kind of box is usualy represented with a min edge and a max edge, that is, two points with min and max coordinates of the box. You can easily generate an axis aligned bounding box from any arbitrary model. Just be aware that they are not precise if arbitrary rotation are involved. – Coincoin Feb 16 '11 at 22:26
0

To make drag and dropping in 3D easier you might implement an (optional) snapping system.

To check whether or not a box contains another box simply check all corners of a box. Test each corner to see if it is on the 'inside' (or outside) of the faces of the other box. If all corners are inside, the box is inside.

This will work for all boxes, not just axis aligned boxes.

Emond
  • 50,210
  • 11
  • 84
  • 115