/// <summary> /// Calculate the tightest bounding-shape with the given <paramref name="type"/> /// </summary> /// <param name="type">Type of the bounding-shape</param> protected virtual void CalculateShape(ShapeType type) { Model model = gameObject.Model; BoundingBox bb = BoundingBoxHelper.Calculate(model); JVector bbSize = Conversion.ToJitterVector(bb.Max - bb.Min); bbSize = new JVector( bbSize.X * Size.X * gameObject.transform.scale.X, bbSize.Y * Size.Y * gameObject.transform.scale.Y, bbSize.Z * Size.Z * gameObject.transform.scale.Z ); JVector com = 0.5f * Conversion.ToJitterVector(bb.Max + bb.Min); CenterOfMass = new JVector(com.X * gameObject.transform.scale.X, com.Y * gameObject.transform.scale.Y, com.Z * gameObject.transform.scale.Z); float maxDimension = MathHelper.Max(bbSize.X, MathHelper.Max(bbSize.Y, bbSize.Z)); switch (type) { case ShapeType.Sphere: CollisionShape = new SphereShape(maxDimension); break; case ShapeType.BoxUniform: CollisionShape = new BoxShape(maxDimension, maxDimension, maxDimension); break; case ShapeType.Box: case ShapeType.BoxInvisible: CollisionShape = new BoxShape(bbSize); break; } }