Foosball Bar Simulation and Constraints

Discuss any questions about BEPUphysics or problems encountered.
Post Reply
DevanDanger
Posts: 6
Joined: Thu Dec 10, 2009 4:08 pm

Foosball Bar Simulation and Constraints

Post by DevanDanger »

I'm trying to simulate the bar of a foosball.

Currently I'm doing this as such.
1. Approximated the body with a compound body for the actual players and the bar.
2. Added two rotation axis constraints to lock the X-axis, Y-axis down.

I still need one more type of constraint which needs to constraint movement to only the Z-axis.
So basically any applied force from the XZ direction needs to be only apply the Z direction force. I've tried to accomplish this with a SingleBodyConstraint, I've tried various things such as taking the linearVelocity and removing the XY components of the velocity with some degree of achievement. None which make it seem realistic. Looking for some direction if possible on how these constraints would need to be implemented.

Thanks,
Evan
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Foosball Bar Simulation and Constraints

Post by Norbo »

I'll work on a little sample showing a single body linear axis constraint.

In the mean time, you may find it simpler (and faster, computationally) to change the inertia tensor of the bar to prevent rotation instead of using multiple constraints. To eliminate rotation around a given entity axis, you can set its inertia around that axis to infinity.

You can see examples of this in the character controller and vehicle. In the character controller, absolutely no rotation is wanted, so the localSpaceInertiaTensorInverse is set to the zero matrix. You can think about this in terms of mass; if you were to set an "inverseMass" property to zero, it would imply that the mass was essentially infinite (inverseMass = 1/huge mass = close to zero).

Code: Select all

body.localSpaceInertiaTensorInverse = Toolbox.zeroMatrix;
In the vehicle, the goal was to change the behavior around a specific local axis a little by scaling it. This makes the object feel a little 'heavier' around that axis.

Code: Select all

Matrix inertiaTensorInverse = vehicle.body.localSpaceInertiaTensorInverse;
            inertiaTensorInverse.M31 *= .5f;
            inertiaTensorInverse.M32 *= .5f;
            inertiaTensorInverse.M33 *= .5f;
            vehicle.body.localSpaceInertiaTensorInverse = inertiaTensorInverse;
The Z axis is the third row. Similarly, the X axis is the first row, and the Y axis is the second row. For your bar that can only rotate around the Z axis, you could set the X and Y rows to 0's.
DevanDanger
Posts: 6
Joined: Thu Dec 10, 2009 4:08 pm

Re: Foosball Bar Simulation and Constraints

Post by DevanDanger »

Cool thanks for the explanation on the alternate way for the Rotational constraint this seems to work fine.
And thanks for writing up a Single Body Linear Axis Constraint sample.

Evan
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Foosball Bar Simulation and Constraints

Post by Norbo »

Here's the SingleBodyLinearAxisConstraint. I tried to keep the functionality pretty simple, so all it does is try to keep the entity's center position aligned with an axis. Let me know if you have any questions!
Attachments
SingleBodyLinearAxisConstraint.zip
(2.14 KiB) Downloaded 235 times
DevanDanger
Posts: 6
Joined: Thu Dec 10, 2009 4:08 pm

Re: Foosball Bar Simulation and Constraints

Post by DevanDanger »

Excellent thanks Norbo, this works great.
Post Reply