本文整理汇总了C#中State.Simulate方法的典型用法代码示例。如果您正苦于以下问题:C# State.Simulate方法的具体用法?C# State.Simulate怎么用?C# State.Simulate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类State
的用法示例。
在下文中一共展示了State.Simulate方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TwoBodysWithDamperPullTogether
public void TwoBodysWithDamperPullTogether()
{
World w = new World ();
Rigid r1 = new Rigid (30, new Matrix (70, 70, 70));
r1.StartCenterOfMass = new Vector ();
w.AddRigid (r1);
w.AddEffect (new Force (new Vector (30, 0, 0), r1));
Rigid r2 = new Rigid (30, new Matrix (70, 70, 70));
r2.StartCenterOfMass = new Vector (10, 0, 0);
w.AddRigid (r2);
w.AddEffect (new Force (new Vector (-30, 0, 0), r2));
Vector v = new Vector ();
Damper damper = new Damper (r1, v, r2, v, 30);
w.AddEffect (damper);
State s1 = new State (w);
s1.Simulate (5);
Assert.AreEqual (2.25, s1.RigidStates [r1].CenterOfMass.X, 0.001);
Assert.AreEqual (0.5, s1.RigidStates [r1].LinearVelocity.X, 0.001);
Assert.AreEqual (0.0, s1.RigidStates [r1].LinearAcceleration.X, 0.001);
Assert.AreEqual (7.75, s1.RigidStates [r2].CenterOfMass.X, 0.001);
Assert.AreEqual (-0.5, s1.RigidStates [r2].LinearVelocity.X, 0.001);
Assert.AreEqual (0.0, s1.RigidStates [r2].LinearAcceleration.X, 0.001);
}
示例2: TwoBodysWithSpringPushAway
public void TwoBodysWithSpringPushAway()
{
World w = new World ();
Rigid r1 = new Rigid (30, new Matrix (70, 70, 70));
r1.StartCenterOfMass = new Vector ();
w.AddRigid (r1);
w.AddEffect (new Force (new Vector (-30, 0, 0), r1));
Rigid r2 = new Rigid (30, new Matrix (70, 70, 70));
r2.StartCenterOfMass = new Vector (10, 0, 0);
w.AddRigid (r2);
w.AddEffect (new Force (new Vector (30, 0, 0), r2));
Vector v = new Vector ();
Spring spring = new Spring (r1, v, r2, v, 300, 0);
w.AddEffect (spring);
State s1 = new State (w);
s1.Simulate (5);
Assert.AreEqual (-0.0966, s1.RigidStates [r1].CenterOfMass.X, 0.001);
Assert.AreEqual (0.0808, s1.RigidStates [r1].LinearVelocity.X, 0.001);
Assert.AreEqual (0.9324, s1.RigidStates [r1].LinearAcceleration.X, 0.001);
Assert.AreEqual (10.0966, s1.RigidStates [r2].CenterOfMass.X, 0.001);
Assert.AreEqual (-0.0808, s1.RigidStates [r2].LinearVelocity.X, 0.001);
Assert.AreEqual (-0.9324, s1.RigidStates [r2].LinearAcceleration.X, 0.001);
}
示例3: LinearBasicTest
public void LinearBasicTest()
{
World w = new World ();
Rigid r = new Rigid (10, new Matrix (1, 1, 1));
w.AddRigid (r);
w.AddEffect (new Force (new Vector (1, 0, 0), r));
State s = new State (w, 0.001);
s.Simulate (2);
Assert.AreEqual (0.1, s.RigidStates [r].LinearAcceleration.X, 0.001);
Assert.AreEqual (0.2, s.RigidStates [r].LinearVelocity.X, 0.001);
Assert.AreEqual (0.2, s.RigidStates [r].CenterOfMass.X, 0.001);
}
示例4: LinearThreeBodyBasicTest
public void LinearThreeBodyBasicTest()
{
World w = new World ();
Rigid r1 = new Rigid (10, new Matrix (1, 1, 1));
w.AddRigid (r1);
w.AddEffect (new Force (new Vector (1, 0, 0), r1));
Rigid r2 = new Rigid (20, new Matrix (1, 1, 1));
w.AddRigid (r2);
Rigid r3 = new Rigid (20, new Matrix (1, 1, 1));
w.AddRigid (r3);
w.AddEffect (new Force (new Vector (1, 0, 0), r3));
State s = new State (w, 0.001);
s.Simulate (2);
Assert.AreEqual (0.1, s.RigidStates [r1].LinearAcceleration.X, 0.001);
Assert.AreEqual (0.2, s.RigidStates [r1].LinearVelocity.X, 0.001);
Assert.AreEqual (0.2, s.RigidStates [r1].CenterOfMass.X, 0.001);
Assert.AreEqual (0, s.RigidStates [r2].LinearAcceleration.Norm, 0.001);
Assert.AreEqual (0, s.RigidStates [r2].LinearVelocity.Norm, 0.001);
Assert.AreEqual (0, s.RigidStates [r2].CenterOfMass.Norm, 0.001);
Assert.AreEqual (0.05, s.RigidStates [r3].LinearAcceleration.X, 0.001);
Assert.AreEqual (0.1, s.RigidStates [r3].LinearVelocity.X, 0.001);
Assert.AreEqual (0.1, s.RigidStates [r3].CenterOfMass.X, 0.001);
}
示例5: OneWorldTwoStatesTest
public void OneWorldTwoStatesTest()
{
World w = new World ();
Rigid r1 = new Rigid (30, new Matrix (70, 70, 70));
w.AddRigid (r1);
w.AddEffect (new Force (new Vector (30, 0, 0), r1, new Vector (5, 0, 0)));
w.AddEffect (new Moment (new Vector (0, 0, 50), r1));
Rigid r2 = new Rigid (5, new Matrix (200, 200, 200));
r2.StartCenterOfMass = new Vector (10, 10, 10);
w.AddRigid (r2);
w.AddEffect (new Force (new Vector (10, 0, 0), r2, new Vector (0, -100, 0)));
State s1 = new State (w, 0.0001);
State s2 = new State (w, 0.001);
s1.Simulate (1);
s2.Simulate (2);
s1.ForwardStep ();
Assert.AreEqual (0, s1.RigidStates [r1].LinearAcceleration.Y, 0.1);
Assert.AreEqual (0, s1.RigidStates [r1].LinearVelocity.Y, 0.1);
Assert.AreEqual (0, s1.RigidStates [r1].CenterOfMass.Y, 0.1);
Assert.AreEqual (1, s1.RigidStates [r1].LinearAcceleration.X, 0.1);
Assert.AreEqual (1, s1.RigidStates [r1].LinearVelocity.X, 0.1);
Assert.AreEqual (0.5, s1.RigidStates [r1].CenterOfMass.X, 0.1);
Assert.AreEqual (0.71, s1.RigidStates [r1].AngularAcceleration.Z, 0.1);
Assert.AreEqual (0.71, s1.RigidStates [r1].AngularVelocity.Z, 0.1);
Assert.AreEqual (0.36, s1.RigidStates [r1].AnglesOfRotation.Z, 0.1);
Assert.AreEqual (0, s1.RigidStates [r2].LinearAcceleration.Y, 0.1);
Assert.AreEqual (0, s1.RigidStates [r2].LinearVelocity.Y, 0.1);
Assert.AreEqual (10, s1.RigidStates [r2].CenterOfMass.Y, 0.1);
Assert.AreEqual (2, s1.RigidStates [r2].LinearAcceleration.X, 0.1);
Assert.AreEqual (2, s1.RigidStates [r2].LinearVelocity.X, 0.1);
Assert.AreEqual (11, s1.RigidStates [r2].CenterOfMass.X, 0.1);
Assert.AreEqual (10, s1.RigidStates [r2].CenterOfMass.Z, 0.1);
Assert.AreEqual (5, s1.RigidStates [r2].AngularAcceleration.Z, 0.1);
Assert.AreEqual (5, s1.RigidStates [r2].AngularVelocity.Z, 0.1);
Assert.AreEqual (2.5, s1.RigidStates [r2].AnglesOfRotation.Z, 0.1);
Assert.AreEqual (0, s2.RigidStates [r1].LinearAcceleration.Y, 0.1);
Assert.AreEqual (0, s2.RigidStates [r1].LinearVelocity.Y, 0.1);
Assert.AreEqual (0, s2.RigidStates [r1].CenterOfMass.Y, 0.1);
Assert.AreEqual (1, s2.RigidStates [r1].LinearAcceleration.X, 0.1);
Assert.AreEqual (2, s2.RigidStates [r1].LinearVelocity.X, 0.1);
Assert.AreEqual (2, s2.RigidStates [r1].CenterOfMass.X, 0.1);
Assert.AreEqual (0.71, s2.RigidStates [r1].AngularAcceleration.Z, 0.1);
Assert.AreEqual (1.43, s2.RigidStates [r1].AngularVelocity.Z, 0.1);
Assert.AreEqual (1.43, s2.RigidStates [r1].AnglesOfRotation.Z, 0.1);
Assert.AreEqual (0, s2.RigidStates [r2].LinearAcceleration.Y, 0.1);
Assert.AreEqual (0, s2.RigidStates [r2].LinearVelocity.Y, 0.1);
Assert.AreEqual (10, s2.RigidStates [r2].CenterOfMass.Y, 0.1);
Assert.AreEqual (2, s2.RigidStates [r2].LinearAcceleration.X, 0.1);
Assert.AreEqual (4, s2.RigidStates [r2].LinearVelocity.X, 0.1);
Assert.AreEqual (14, s2.RigidStates [r2].CenterOfMass.X, 0.1);
Assert.AreEqual (10, s2.RigidStates [r2].CenterOfMass.Z, 0.1);
Assert.AreEqual (5, s2.RigidStates [r2].AngularAcceleration.Z, 0.1);
Assert.AreEqual (10, s2.RigidStates [r2].AngularVelocity.Z, 0.1);
Assert.AreEqual (10, s2.RigidStates [r2].AnglesOfRotation.Z, 0.1);
}
示例6: NonCentricMomentTest
public void NonCentricMomentTest()
{
World w = new World ();
Rigid r = new Rigid (5, new Matrix (5, 5, 5));
w.AddRigid (r);
w.AddEffect (new Moment (new Vector (0, 0, 10), r, new Vector (0.5, 0, 0)));
State s = new State (w, 0.001);
s.Simulate (3);
Assert.AreEqual (4, s.RigidStates [r].LinearAcceleration.Y, 0.1);
Assert.AreEqual (12, s.RigidStates [r].LinearVelocity.Y, 0.1);
Assert.AreEqual (18, s.RigidStates [r].CenterOfMass.Y, 0.1);
Assert.AreEqual (2, s.RigidStates [r].AngularAcceleration.Z, 0.1);
Assert.AreEqual (6, s.RigidStates [r].AngularVelocity.Z, 0.1);
Assert.AreEqual (9, s.RigidStates [r].AnglesOfRotation.Z, 0.1);
}
示例7: AngularBasicTest
public void AngularBasicTest()
{
World w = new World ();
Rigid r = new Rigid (23, new Matrix (5, 5, 5));
w.AddRigid (r);
w.AddEffect (new Moment (new Vector (2, 0, 0), r));
State s = new State (w, 0.001);
s.Simulate (2);
Assert.AreEqual (0.4, s.RigidStates [r].AngularAcceleration.X, 0.001);
Assert.AreEqual (0.8, s.RigidStates [r].AngularVelocity.X, 0.001);
Assert.AreEqual (0.8, s.RigidStates [r].AnglesOfRotation.X, 0.01);
}
示例8: TwoBodyGravityTest
public void TwoBodyGravityTest()
{
World w = new World ();
w.AddEffect (new Gravity ());
Rigid r1 = new Rigid (10, new Matrix (1, 1, 1));
w.AddRigid (r1);
Rigid r2 = new Rigid (20, new Matrix (1, 1, 1));
w.AddRigid (r2);
State s = new State (w, 0.001);
s.Simulate (2.5);
Assert.AreEqual (-9.81, s.RigidStates [r1].LinearAcceleration.Y, 0.01);
Assert.AreEqual (-24.52, s.RigidStates [r1].LinearVelocity.Y, 0.02);
Assert.AreEqual (-30.65, s.RigidStates [r1].CenterOfMass.Y, 0.1);
Assert.AreEqual (-9.81, s.RigidStates [r2].LinearAcceleration.Y, 0.01);
Assert.AreEqual (-24.52, s.RigidStates [r2].LinearVelocity.Y, 0.02);
Assert.AreEqual (-30.65, s.RigidStates [r2].CenterOfMass.Y, 0.1);
}