gravitational areas (turbo field)

Discuss any questions about BEPUphysics or problems encountered.
Post Reply
fredlllll
Posts: 19
Joined: Fri Mar 02, 2012 7:20 pm

gravitational areas (turbo field)

Post by fredlllll »

for my game i want an area which applies a certain force to objects which enter it, but i want the force not just been applied to the object, it should be like, when a long pipe touches the are, just the touching side is applied force to. like there is wind going in that direction. how do i achieve that?
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: gravitational areas (turbo field)

Post by Norbo »

A simplified model of wind could rely on computing the cross-sectional area of the object exposed to the wind. This is very difficult to compute analytically for completely arbitrary shapes, but it can be approximated. Here are a few possible approximations:

1) Sample the shape with ray casts. Any hits contribute to the area. With the right sampling strategy and sufficient samples, it will converge to the analytical solution.

The FluidVolume does something similar. It samples a grid of rays from the bottom up and, for any hits, performs another set of rays from the top down. The result is a numerical approximation of the submerged volume which is then used to compute the buoyancy force and the center of submerged volume at which to apply the force.

You might be able to make the force model more interesting through the normals these ray cast samples return as well.

2) Project the shape onto the plane whose normal is the direction of wind/force. Intersect the projected 2d shape with the volume of wind/force. (This is made much easier if the wind/force volume is some easy known shape whose projection is invariant with the location of intersection.) Use the intersected area as the cross sectional area. Find a point on the shape which is roughly in the middle, probably with a ray cast from the center of the intersected projected volume in the direction of the wind/force to the shape. Apply the force computed from the area to the intersection.

To compute the projection of a shape:
-If the shape is something simple like a Box or ConvexHull, the vertices can be projected to the plane directly. The 2d convex hull of the projected vertices is the cross sectional area.
-If the shape is just some arbitrary convex object, then you could use the shape's extreme point methods to sample a good projected 2d hull.
-If it's a compound shape, decompose it into its constituent pieces and project each of them.

Intersecting the two volumes requires some potentially nontrivial 2d polygon intersection algorithms as well. If you wanted, you could sample a grid of points for containment to get a rough idea of the intersection area.

3) Don't bother explicitly computing the area or center of force. Just send a bunch of ray or convex casts in the wind volume. Convex casts would ensure that you detect thin objects that might otherwise slip through adjacent infinitely narrow ray casts.

For each cast hit, apply a force at the impact point. This is similar to #1, but instead of summing area first, it takes out the middle man and sums the force contributions of individual 'wind chunks.'

You may find that you don't need many convex casts at all to make this behave acceptably, especially if the wind volume is fairly simple. A narrow 'wind tube' could probably get away with one disk (a cylinder with zero height) casted along the wind direction.

#3 will be the easiest to implement of the bunch. #2 would be quite painful. #1 is somewhere in between depending on the sampling strategies used.
fredlllll
Posts: 19
Joined: Fri Mar 02, 2012 7:20 pm

Re: gravitational areas (turbo field)

Post by fredlllll »

O_o
o_O
o_o
°_°
._.
what if you just make a cube shaped (rotateable) gravitational area in your next release? X3
like the ones in crysis
well i stick to #3, as my solution now is just a trigger and when an object begins touching force is applied XD so well hello #3
but would it also work to just apply force to the point where the detection volume and my shape collide?
and the volume is basically just a box (and will stay one) so what would be the recommended way for a box? do i have to/should/could i do something different?

"2 would be quite painful" well you made the physics engine XD i think this was more painful
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: gravitational areas (turbo field)

Post by Norbo »

what if you just make a cube shaped (rotateable) gravitational area in your next release? X3
like the ones in crysis
Force fields like the ones in crysis do exist- check out the TornadoDemo and PlanetDemo for an example. However, they act upon the centers of objects. It's an all-or-nothing effect. Applying a force proportional to the exposed area or volume is what makes it trickier :) FluidVolumes do this at a cost much greater than that of a simple bounding comparison.
well i stick to #3, as my solution now is just a trigger and when an object begins touching force is applied XD so well hello #3
but would it also work to just apply force to the point where the detection volume and my shape collide?
and the volume is basically just a box (and will stay one) so what would be the recommended way for a box? do i have to/should/could i do something different?
Applying force at contact points could be a valid approach. It won't give you the fidelity of a bunch of separate convex casts or something, but if you don't need that fidelity, it really does not matter. Do the simplest thing that actually accomplishes your goals, whatever those goals may be :)

For a box under the #3 approach, cast a grid of however many box shapes from one side of the box volume to the other along the direction of force. But again, if all you want is an extremely approximate 'push somewhere on this general area, in this volume' then you don't really need to go through as much work.
Post Reply