I'm trying to use the Plane primitive (dropping a box on a plane), but it doesn't work right for me.
I'm adding a box primitive to a skin, and creating a body with that skin. I add the body to the physics system, which adds the collisions to the collision system.
I'm additionally adding a plane primitive to the collision system of the physics system, without adding a body for it.
The box is size 2,1,1 and starts out at 1, 3, -2 in world coordinates.
The plane has Vector3.Up as normal, and 0 as distance, so it starts at the origin.
What I would expect to see would be that the box falls a little bit and gets caught by the plane. However, what I see is that the box jitters a little, and then immediately rests in its starting position. It doesn't matter how I change the plane D or the box starting position; the same thing happens.
Here's how I create the box and plane:
physicsScene_.AddObject(new BoxObject(new Vector3(1, 3, -2), 1.0f, 0.5f, 0.5f, "models/box-2-1-1"));
physicsScene_.AddObject(new PlaneObject(Vector3.Zero, Vector3.Up, "models/plane-20-20"));
Creating a BoxObject (I'm not using JigLibGame, but I'm reading it for reference):
public BoxObject(Vector3 pos, float dx, float dy, float dz, string model)
: base(Loader.Global.ModelAssetByName(model))
{
body_ = new Body();
collision_ = new CollisionSkin(body_);
collision_.AddPrimitive(new Box(Vector3.Zero, Matrix.Identity, new Vector3(dx*2, dy*2, dz*2)),
DefaultMaterialID, DefaultMaterialProperties);
body_.CollisionSkin = collision_;
Vector3 com = SetMass(1.0f);
collision_.ApplyLocalTransform(new Transform(-com, Matrix.Identity));
body_.EnableBody();
body_.Transform = new Transform(pos, Matrix.Identity);
}
Finally, creating the plane:
public PlaneObject(Vector3 pos, Vector3 normal, string model)
: base(Loader.Global.ModelAssetByName(model))
{
if (Math.Abs(normal.LengthSquared() - 1) > 0.001f) {
throw new System.ArgumentException("PlaneObject was passed a non-unit normal.", "normal");
}
body_ = new Body();
collision_ = new CollisionSkin(null);
collision_.AddPrimitive(new Plane(Vector3.Up, 0),
DefaultMaterialID, DefaultMaterialProperties);
Vector3 right = new Vector3(1, 0, 0);
Vector3 back;
if (Math.Abs(Vector3.Dot(right, normal)) < 0.01f) {
right = new Vector3(0, 1, 0);
}
Vector3.Cross(ref right, ref normal, out back);
back.Normalize();
Matrix ori = Matrix.CreateWorld(Vector3.Zero, -back, normal);
body_.Transform = new Transform(pos, ori);
collision_.ApplyLocalTransform(body_.Transform);
body_.SetInactive();
}
In fact, even inverting the plane direction (Vector3.Down) causes the same effect.