/// <summary> /// Create box model physics. /// </summary> /// <param name="game">The game.</param> /// <param name="model">The visual model.</param> /// <param name="position">The position of the box entity.</param> /// <param name="mass">The physics mass.</param> public BoxModelPhysics(XiGame game, Model model, Vector3 position, float mass) { this.game = game; Vector3[] vertices; int[] indices; model.GetVerticesAndIndices(out vertices, out indices); BoundingBox boundingBox = BoundingBox.CreateFromPoints(vertices); body = new BEPUphysics.Entities.Box( position, Math.Max(Math.Abs(boundingBox.Max.X), Math.Abs(boundingBox.Min.X)) * 2, Math.Max(Math.Abs(boundingBox.Max.Y), Math.Abs(boundingBox.Min.Y)) * 2, Math.Max(Math.Abs(boundingBox.Max.Z), Math.Abs(boundingBox.Min.Z)) * 2, mass); /* this alternative method does not work and I don't know why - Box box = new Box( (boundingBox.Max + boundingBox.Min) * 0.5f, boundingBox.Max.X - boundingBox.Min.X, boundingBox.Max.Y - boundingBox.Min.Y, boundingBox.Max.Z - boundingBox.Min.Z, Mass); body = new CompoundBody(); body.addBody(box); */ }
/// <summary> /// Create sphere model physics. /// </summary> /// <param name="game">The game.</param> /// <param name="model">The visual model.</param> /// <param name="position">The position of the static mesh entity.</param> /// <param name="mass">The physics mass.</param> public StaticMeshModelPhysics(XiGame game, Model model, Vector3 position, float mass) { this.game = game; StaticTriangleGroup.StaticTriangleGroupVertex[] vertices; int[] indices; model.GetVerticesAndIndices(out vertices, out indices); TriangleMesh triangleMesh = new TriangleMesh(vertices, indices); staticTriangleGroup = new StaticTriangleGroup(triangleMesh); }
/// <summary> /// Create sphere model physics. /// </summary> /// <param name="game">The game.</param> /// <param name="model">The visual model.</param> /// <param name="position">The position of the sphere entity.</param> /// <param name="mass">The physics mass.</param> public SphereModelPhysics(XiGame game, Model model, Vector3 position, float mass) { this.game = game; Vector3[] vertices; int[] indices; model.GetVerticesAndIndices(out vertices, out indices); BoundingSphere boundingSphere = BoundingSphere.CreateFromPoints(vertices); body = new Sphere(position, boundingSphere.Radius, mass); }
/// <summary> /// Create capsule model physics. /// </summary> /// <param name="game">The game.</param> /// <param name="model">The visual model.</param> /// <param name="position">The position of the sphere entity.</param> /// <param name="mass">The physics mass.</param> public CapsuleModelPhysics(XiGame game, Model model, Vector3 position, float mass) { this.game = game; Vector3[] vertices; int[] indices; model.GetVerticesAndIndices(out vertices, out indices); BoundingSphere boundingSphere = BoundingSphere.CreateFromPoints(vertices); body = new Capsule(position, boundingSphere.Radius, boundingSphere.Radius * 0.5f, mass); game.SceneSpace.Add(body); }