public PhysicsObject AddDynamicObject(float mass, Matrix4 transform, Collider col, Vector3?inertia = null) { if (mass < float.Epsilon) { throw new Exception("Mass must be non-zero"); } BM.Vector3 localInertia; if (inertia != null) { localInertia = inertia.Value.Cast(); } else { col.BtShape.CalculateLocalInertia(mass, out localInertia); } using (var rbInfo = new RigidBodyConstructionInfo(mass, new DefaultMotionState(transform.Cast()), col.BtShape, localInertia)) { var body = new RigidBody(rbInfo); body.SetDamping(0, 0); body.Restitution = 1f; var phys = new PhysicsObject(body, col) { Static = false }; phys.UpdateProperties(); body.UserObject = phys; btWorld.AddRigidBody(body); objects.Add(phys); dynamicObjects.Add(phys); return(phys); } }
public IEnumerable <BoundingBox> GetBoxes(Matrix4 transform) { foreach (var shape in btCompound.ChildList) { BM.Vector3 min, max; shape.ChildShape.GetAabb(shape.Transform * transform.Cast(), out min, out max); yield return(new BoundingBox(min.Cast(), max.Cast())); } }
public void UpdatePart(object tag, Matrix4 localTransform) { var tr = localTransform.Cast(); foreach (var part in children) { if (part.Tag == tag) { for (int i = part.Index; i < (part.Index + part.Count); i++) { btCompound.UpdateChildTransform(i, tr); } break; } } btCompound.RecalculateLocalAabb(); }
public PhysicsObject AddStaticObject(Matrix4 transform, Collider col) { using (var rbInfo = new RigidBodyConstructionInfo(0, new DefaultMotionState(transform.Cast()), col.BtShape, BM.Vector3.Zero)) { var body = new RigidBody(rbInfo); body.Restitution = 1; var phys = new PhysicsObject(body, col) { Static = true }; phys.UpdateProperties(); body.UserObject = phys; btWorld.AddRigidBody(body); objects.Add(phys); return(phys); } }
public void UpdatePart(object tag, Matrix4 localTransform) { var tr = localTransform.Cast(); foreach (var part in children) { if (part.Tag == tag) { if (part.CurrentTransform == localTransform) { return; } part.CurrentTransform = localTransform; for (int i = part.Index; i < (part.Index + part.Count); i++) { btCompound.UpdateChildTransform(i, tr, false); } break; } } }
public void AddPart(uint meshId, Matrix4 localTransform, object tag, int suridx = 0) { var sur = surs[suridx]; if (!sur.HasShape(meshId)) { return; } var hulls = sur.GetShape(meshId); var pt = new CollisionPart() { Tag = tag, Index = currentIndex, Count = hulls.Length }; var tr = localTransform.Cast(); foreach (var h in hulls) { btCompound.AddChildShape(tr, h); } currentIndex += hulls.Length; }
public void SetTransform(Matrix4 transform) { RigidBody.WorldTransform = transform.Cast(); Position = VectorMath.Transform(Vector3.Zero, Transform); }