本文整理汇总了C#中JigLibX.Physics.Body.SetBodyInertia方法的典型用法代码示例。如果您正苦于以下问题:C# Body.SetBodyInertia方法的具体用法?C# Body.SetBodyInertia怎么用?C# Body.SetBodyInertia使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JigLibX.Physics.Body
的用法示例。
在下文中一共展示了Body.SetBodyInertia方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CylinderObject
public CylinderObject(Game game, float radius, float length, Vector3 position, Model model)
: base(game, model)
{
body = new Body();
collision = new CollisionSkin(body);
if (length - 2.0f * radius < 0.0f)
throw new ArgumentException("Radius must be at least half length");
Capsule middle = new Capsule(Vector3.Zero, Matrix.Identity, radius, length - 2.0f * radius);
float sideLength = 2.0f * radius / (float) Math.Sqrt(2.0d);
Vector3 sides = new Vector3(-0.5f * sideLength, -0.5f * sideLength, -radius);
Box supply0 = new Box(sides, Matrix.Identity,
new Vector3(sideLength, sideLength, length));
Box supply1 = new Box(Vector3.Transform(sides,Matrix.CreateRotationZ(MathHelper.PiOver4)),
Matrix.CreateRotationZ(MathHelper.PiOver4), new Vector3(sideLength, sideLength, length));
collision.AddPrimitive(middle, new MaterialProperties(0.8f, 0.8f, 0.7f));
collision.AddPrimitive(supply0, new MaterialProperties(0.8f, 0.8f, 0.7f));
collision.AddPrimitive(supply1, new MaterialProperties(0.8f, 0.8f, 0.7f));
body.CollisionSkin = this.collision;
Vector3 com = SetMass(1.0f);
collision.ApplyLocalTransform(new Transform(-com, Matrix.Identity));
#region Manually set body inertia
float cylinderMass = body.Mass;
float comOffs = (length - 2.0f * radius) * 0.5f; ;
float Ixx = 0.5f * cylinderMass * radius * radius + cylinderMass * comOffs * comOffs;
float Iyy = 0.25f * cylinderMass * radius * radius + (1.0f / 12.0f) * cylinderMass * length * length + cylinderMass * comOffs * comOffs;
float Izz = Iyy;
body.SetBodyInertia(Ixx, Iyy, Izz);
#endregion
body.MoveTo(position, Matrix.CreateRotationX(MathHelper.PiOver2));
body.EnableBody();
this.scale = new Vector3(radius, radius, length * 0.5f);
}
示例2: Initialize
public override void Initialize()
{
Body = new Body();
Skin = new CollisionSkin(Body);
Body.CollisionSkin = Skin;
radius = 12;
float length = 3;
//Capsule middle = new Capsule(Vector3.Zero, Matrix.Identity, radius, length - 2.0f * radius);
float sideLength = 2.0f * radius / (float)Math.Sqrt(2.0d);
Vector3 sides = new Vector3(-0.5f * sideLength, -0.5f * sideLength, -radius);
Box supply0 = new Box(sides, Matrix.Identity,
new Vector3(sideLength, sideLength, length));
Box supply1 = new Box(Vector3.Transform(sides, Matrix.CreateRotationZ(MathHelper.PiOver4)),
Matrix.CreateRotationZ(MathHelper.PiOver4), new Vector3(sideLength, sideLength, length));
Box supply2 = new Box(Vector3.Transform(sides, Matrix.CreateRotationZ( (MathHelper.PiOver4 * 0.5f) )),
Matrix.CreateRotationZ( (MathHelper.PiOver4 * 0.5f) ), new Vector3(sideLength, sideLength, length));
Box supply3 = new Box(Vector3.Transform(sides, Matrix.CreateRotationZ((MathHelper.PiOver4 * 1.5f))),
Matrix.CreateRotationZ((MathHelper.PiOver4 * 1.5f)), new Vector3(sideLength, sideLength, length));
//Skin.AddPrimitive(middle, new MaterialProperties(0.8f, 0.8f, 0.7f));
Skin.AddPrimitive(supply0, new MaterialProperties(0.8f, 0.8f, 0.7f));
Skin.AddPrimitive(supply1, new MaterialProperties(0.8f, 0.8f, 0.7f));
Skin.AddPrimitive(supply2, new MaterialProperties(0.8f, 0.8f, 0.7f));
Skin.AddPrimitive(supply3, new MaterialProperties(0.8f, 0.8f, 0.7f));
Vector3 com = SetMass(1.0f);
Body.MoveTo(position, Matrix.Identity);
Skin.ApplyLocalTransform(new Transform(-com, Matrix.Identity));
#region Manually set body inertia
float cylinderMass = Body.Mass;
float comOffs = (length - 2.0f * radius) * 0.5f; ;
float Ixx = 0.5f * cylinderMass * radius * radius + cylinderMass * comOffs * comOffs;
float Iyy = 0.25f * cylinderMass * radius * radius + (1.0f / 12.0f) * cylinderMass * length * length + cylinderMass * comOffs * comOffs;
float Izz = Iyy;
Body.SetBodyInertia(Ixx, Iyy, Izz);
#endregion
Body.EnableBody();
Body.ExternalData = this;
SetBody(rotation);
}