Note: I render boxes for each of the joints, so you can see them in the gif. But they don't move which is intentional as I don't move the render boxes. They are just to show the starting location. Also the white spheres are lights.
I'm been looking at the Ragdoll sample but the joints code confuses me. Also In my code I only have a parent bone and child bone each time, so I can't distinguish between hip to leg or arm to forearm etc. So I was hoping there was some universal joint I could use?
My code as it generally is executed at the moment:
Code: Select all
var parallelLooper = new ParallelLooper();
//This section lets the engine know that it can make use of multithreaded systems
//by adding threads to its thread pool.
if (Environment.ProcessorCount > 1)
{
for (int i = 0; i < Environment.ProcessorCount; i++)
{
parallelLooper.AddThread();
}
}
World = new Space(parallelLooper);
Code: Select all
World.ForceUpdater.Gravity = new Vector3(0, -9.81f, 0);
Code: Select all
public void AddGround()
{
float width = 10000;
float height = 20;
float depth = 10000;
ground = new Box(Vector3.Zero, width, height, depth);
World.Add(ground);
}
Code: Select all
private void DxSurface_Update(object sender, UpdateEventArgs e)
{
World.Update(Atom.ElapsedSecs*10);
}
Code: Select all
for (int i = 0; i < rigidBodies.Length; i++)
{
var boxInfo = RagdollType.Info.RigidBodies[i];
var physicsBody = new Box(
RagdollType.boneCenters[i],
boxInfo.Depth / 2,
boxInfo.Height,
boxInfo.Width / 2,
boxInfo.Height*boxInfo.Width*boxInfo.Depth);
World.Add(physicsBody);
}
Code: Select all
for (int i = 0; i < RagdollType.rigidbodyJointDefaultWorlds.Length; i++)
{
var parentBody = ...;
var childBody = ...;
var pos = childBone.head;
var torsoTopToLeftArmBallSocketJoint = new BallSocketJoint(parentBody, childBody, pos);
var torsoTopToLeftArmEllipseLimit = new EllipseSwingLimit(parentBody, childBody, Vector3.Left,
MathHelper.Pi * .75f, MathHelper.PiOver2);
var torsoTopToLeftArmTwistLimit = new TwistLimit(parentBody, childBody, Vector3.Left, Vector3.Left,
-MathHelper.PiOver2, MathHelper.PiOver2);
var torsoTopToLeftArmMotor = new AngularMotor(parentBody, childBody);
torsoTopToLeftArmMotor.Settings.VelocityMotor.Softness = .2f;
World.Add(torsoTopToLeftArmBallSocketJoint);
World.Add(torsoTopToLeftArmEllipseLimit);
World.Add(torsoTopToLeftArmTwistLimit);
World.Add(torsoTopToLeftArmMotor);
var leftUpperArmToLeftForearmSwivelHingeJoint = new SwivelHingeJoint(parentBody, childBody, pos, Vector3.Up);
leftUpperArmToLeftForearmSwivelHingeJoint.HingeLimit.IsActive = true;
leftUpperArmToLeftForearmSwivelHingeJoint.TwistLimit.IsActive = true;
leftUpperArmToLeftForearmSwivelHingeJoint.TwistLimit.MinimumAngle = -MathHelper.Pi / 8;
leftUpperArmToLeftForearmSwivelHingeJoint.TwistLimit.MaximumAngle = MathHelper.Pi / 8;
leftUpperArmToLeftForearmSwivelHingeJoint.HingeLimit.MinimumAngle = -MathHelper.Pi * .8f;
leftUpperArmToLeftForearmSwivelHingeJoint.HingeLimit.MaximumAngle = 0;
//The SwivelHingeJoint has motors, but they are separately defined for twist/bending.
//The AngularMotor covers all degrees of freedom.
var leftUpperArmToLeftForearmMotor = new AngularMotor(parentBody, childBody);
leftUpperArmToLeftForearmMotor.Settings.VelocityMotor.Softness = .3f;
World.Add(leftUpperArmToLeftForearmSwivelHingeJoint);
World.Add(leftUpperArmToLeftForearmMotor);
}
Code: Select all
public void ToggleIsActive()
{
for (int i = 0; i < rigidBodies.Length; i++)
rigidBodies[i].ActivityInformation.Activate();
}
- The arms bounce around and actually elongate. I really want them to not elongate at all. Docs say use ball socket joint for that but mine doesn't seem to work?
- I update at 60 fps, but found I need to pass Elapsed*10 into Update() to get good results, otherwise things move really slowly. Am I doing this right?
- I calc mass as box width*height*depth. Is this a good way to do it?
- I don't really need a perfect ragdoll, just something that looks right, where the joints stay together and don't intersect other parts of the body. At the moment it kinda becomes a heap on the floor (I think because there is no limit on joint rotation).
- I like what Blender has which is a joint where you can specify the min and max angles for XYZ axis. Is it possible to have something like that in Bepu? Then I can add a config option to set the angle limits so can have some variation for different bones.