[Solved] Finding out how deep spatial a is in spatial b


#1

I am building a drag and drop space ship builder. You build ships with ship parts. I am using collision shapes and bullet to detect physics collisions so that I know if the parts are attached or not. My problem is that when they are colliding and part a (shown in green in the picture) is moved into part b, I need to know how deep part a is in part b because I want to restrict how much they can overlap.

Anyone know how I can get this information to restrict transform movement?

EDIT: The answer must be shape and rotation accurate. I am using a HullCollisionShape


#2

You mean “moved into B” in the sense that it is no longer attaching to the surface but is just ‘free form’ in space.

It sounds like you want to know how much two arbitrary volumes intersect… which I think is a really non-trivial problem.


#3

Yes and yes … BUT what I really want to know … since the result has to be shape and rotation acurate is … based in the picture … for example, is the cockpit deepest spot in the hull more than 10 percent of the cockpit’s volume … but accurate volume. It might be trivial but my noob brain can’t get my head around the math.


#4

No, it is NOT trivial.

Probably your best bet will be to voxelize the volumes and even that is going to be hard for arbitrary non-convex shapes.

Edit: but here you can think about how hard the problem is. Given just a point in space, how would you tell if it was inside or outside the volume?

Solve that and you can voxelize both shapes on some grid and see how much they overlap.


#5

I think I figured it out by just staring at my picture. Please shoot this theory to hell is it will not work.

Basically I do have the ORIGINAL collision point saved with the direction of object b from the physics engine so … for each axis, I send a ray down both directions of the axis and each ray will collide with the exterior of object A since the collision point will be inside object A. I then can divide the distance of the collision point from ray 1 and ray 2 with the distance of the ray pointing towards object b and presto magico I now know how deep each axis is inside object B … if I have the distance of each axis I can derive at least a basic cube volume.

It’s not super actuate but should be accurate enough so that I can configure the cockpit part to prevent the user from sticking the cockpit so far up the hull the you can’t even see the windows.


#6

I got a much easier suggestion for you…
What about using 2 collision shapes?
The first one: bigger one - is used just to detect stuff and can overlap
The second one: smaller one - is used just to ensure things dont pass thru.


#7

Holly crapnutz batman!!! Why did I not think of that??
Never did that before though … Can we add two rigid body controls to a single spatial??


#8

Probably best avoided… but you could add whatever ghost objects you want to.


#9

Ghost objects are AABB so they are of no use to me


#10

? Weird, I use spheres and capsules for them all the time. Not sure why you think they are limited to a bounding box.

…but anyway, you can make fake ghosts if you want by having rigid bodies that aren’t controls and just position them where you like.

Nothing requires you to use controls and spatials.


#11

As the javadoc for PhysicsObjectControl says, the ghost object collision detection uses AABB (Axis-aligned bounding box) collision only, regardless of the collision shape it has been assigned.


#12

Hm. Maybe it was because I was using jbullet.

Anyway, you can have whatever physics objects you want to without any visuals at all.


#13

Yes I believe it’s a native bullet limitation


#14

Ghost objects can use any collision shape, not just AABB. I’m very sure of this for native Bullet and reasonably sure for jBullet.

Bullet uses AABB for broadphase collision detection, to find candidate pairs of objects for collisions. However, there’s a 2nd phase in the collision-detection process, one that uses the actual collision shapes. The exact algorithm that’s dispatched depends on the shapes involved. All this is documented in Chapter 4 of the Bullet manual:
https://github.com/bulletphysics/bullet3/blob/master/docs/Bullet_User_Manual.pdf

When Bullet detects a collision, it calculates the depth of penetration. Unfortunately, this information doesn’t seem to be accessible through the current jme3-bullet API.


#15

So out of curiosity, if I reduce a volume by x% what’s the reduced surface area % ? I’ve never come across a need for that but my brain wants to know. Sounds exponential.


#16

Are you actually reducing the volume by x% or the dimensions (ie: scale)?


#17

Surface area is proportional to the 2/3 power of the volume. Reducing the volume x% gives you

 newVolume = (1f-x/100f)*originalVolume;
 newArea = Math.pow(1f-x/100f, 2/3f)*originalArea;

#18

Reason being that change in surface area is the square of the change in ‘size’… and change in volume is the cube of the change in size.

…which is why I asked what the original x% was. Usually people think “I want to make this half the size”… which is a function of size and not volume.

In graphics, anyway… it’s super weird to change something’s size based on its volume.


#19

Yes, you can add 2 rigid-body controls to a single Spatial. To access them, you’d need to keep references (since Spatial.getControl() will only find one of them). And of course, if both RBCs were in dynamic mode, they’d interfere with each other, so I recommend that at least one of the controls be setKinematic(true).

In this case, however, I think a GhostControl for the outer envelope makes more sense than an RBC.


#20

I was thinking if I altered the scale. So a 10% reduction in size would result in a volume reduction % of x

It’s more of a brain excercise than anything else, but I guess if the OP decreased the size by 10% or whatever then that would result in 10% wiggle room they desire.