本文整理汇总了C#中World.CollisionUpdate方法的典型用法代码示例。如果您正苦于以下问题:C# World.CollisionUpdate方法的具体用法?C# World.CollisionUpdate怎么用?C# World.CollisionUpdate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类World
的用法示例。
在下文中一共展示了World.CollisionUpdate方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Test_Overlaps
public void Test_Overlaps()
{
var node1 = new Node ("Node1");
var col1 = new CollisionObject ();
col1.Shape = new BoxShape (1, 1, 1);
node1.Attach (col1);
var node2 = new Node ("Node2");
var col2 = new CollisionObject ();
col2.Shape = new BoxShape (1, 1, 1);
node2.Attach (col2);
var wld = new World ();
wld.AddChild (node1);
wld.AddChild (node2);
// コリジョン発生
wld.CollisionUpdate ();
Assert.AreEqual (1, col1.OverlappingObjectCount);
Assert.AreEqual (1, col2.OverlappingObjectCount);
// コリジョン消失
node2.Translate (10, 0, 0);
wld.CollisionUpdate ();
Assert.AreEqual (0, col1.OverlappingObjectCount);
Assert.AreEqual (0, col2.OverlappingObjectCount);
}
示例2: Test_BoxShape
public void Test_BoxShape()
{
var node = new Node ();
var col = new CollisionObject ();
col.Shape = new BoxShape (1, 1, 1);
col.SetOffset (1, 0, 0);
node.Attach (col);
node.Translate (1, 0, 0);
node.Rotate (45, 0, 0, 1);
var wld = new World ();
wld.AddChild (node);
wld.CollisionUpdate ();
// (1+1) - 1*√2
var result = wld.RayCast (new Vector3 (-10, 0, 0), new Vector3 (10, 0, 0)).First ();
Assert.AreEqual (true, result.Hit);
Assert.AreEqual (new Vector3 (0.5858f, 0, 0), result.Point);
Assert.AreEqual (new Vector3 (-1, 0, 0), result.Normal);
Assert.AreEqual (10.58579f, result.Distance, 0.01f);
Assert.AreEqual (0.5245f, result.Fraction, 0.01f);
// (1+1) + 1*√2
result = wld.RayCast (new Vector3 (10, 0, 0), new Vector3 (-10, 0, 0)).First ();
Assert.AreEqual (true, result.Hit);
Assert.AreEqual (new Vector3 (3.4142f, 0, 0), result.Point);
Assert.AreEqual (new Vector3 (1, 0, 0), result.Normal);
Assert.AreEqual (6.585786f, result.Distance, 0.01f);
Assert.AreEqual (0.3225f, result.Fraction, 0.01f);
wld.Destroy ();
}
示例3: Test_Distance_Box_to_Box
public void Test_Distance_Box_to_Box()
{
var node1 = new Node ("Node1");
var col1 = new CollisionObject ();
col1.Shape = new BoxShape (1, 1, 1);
col1.SetOffset (0, 0, 0);
node1.Attach (col1);
var node2 = new Node ("Node2");
var col2 = new CollisionObject ();
col2.Shape = new BoxShape (1,1,1);
col2.SetOffset (0, 10, 0);
node2.Attach (col2);
node1.Translate (0, 0, 0);
node2.Translate (10, 0, 0);
// 10*√2
var wld = new World ();
wld.AddChild (node1);
wld.AddChild (node2);
wld.CollisionUpdate ();
Assert.AreEqual(10*1.4142f - 2*1.4142f, wld.Distance (node1, node2), 0.05f);
wld.Destroy ();
}
示例4: Main
public static void Main(string[] args)
{
var g2d = DD.Graphics2D.GetInstance ();
g2d.CreateWindow (800, 600, "こんにちは、世界");
// ----------------------------------------
var wld = new World ();
var node1 = MySender.Create ("Recver1", new Vector3 (100, 250, 0));
var node2 = MyRecver.Create ("Recver1", new Vector3 (600, 150, 0));
var node3 = MyRecver.Create ("Recver2", new Vector3 (600, 250, 0));
var node4 = MyRecver.Create ("Recver3", new Vector3 (600, 350, 0));
var node5 = MyRecver.Create ("All", new Vector3 (600, 500, 0));
var node6 = MyButton.Create ("1", "Recver1", new Vector3 (50, 350, 0));
var node7 = MyButton.Create ("2", "Recver2", new Vector3 (100, 350, 0));
var node8 = MyButton.Create ("3", "Recver3", new Vector3 (150, 350, 0));
var node9 = MyButton.Create ("All", "All", new Vector3 (200, 350, 0));
wld.AddChild (node1);
wld.AddChild (node2);
wld.AddChild (node3);
wld.AddChild (node4);
wld.AddChild (node5);
wld.AddChild (node6);
wld.AddChild (node7);
wld.AddChild (node8);
wld.AddChild (node9);
// ----------------------------------------
var active = true;
g2d.OnClosed += delegate (object sender, EventArgs eventArgs) {
active = false;
};
Console.WriteLine ("Start of Main Loop");
g2d.SetFrameRateLimit (60);
var watch = new Stopwatch ();
watch.Start ();
while (active) {
var msec = watch.ElapsedMilliseconds;
g2d.Dispatch (wld);
wld.Animate (msec, 33);
wld.CollisionUpdate ();
wld.Update (msec);
wld.Deliver ();
g2d.Draw (wld);
}
Console.WriteLine ("End of Game");
}
示例5: Test_BoxShape
public void Test_BoxShape()
{
var node1 = new Node ("Sweeper");
var col1 = new CollisionObject ();
col1.Shape = new BoxShape (1, 1, 1);
col1.SetOffset (0, 1, 0);
node1.Attach (col1);
var node2 = new Node ("Target1");
var col2 = new CollisionObject ();
col2.Shape = new SphereShape (1);
col2.SetOffset (0, 1, 0);
node2.Attach (col2);
var node3 = new Node ("Target2");
var col3 = new CollisionObject ();
col3.Shape = new SphereShape (1);
col3.SetOffset (0, 1, 0);
node1.Translate (0, 0, 0);
node2.Translate (10, 0, 0);
node3.Translate (20, 0, 0);
var wld = new World ();
wld.AddChild (node1);
wld.AddChild (node2);
wld.AddChild (node3);
wld.CollisionUpdate ();
var result = wld.Sweep (node1, new Vector3 (100, 0, 0));
Assert.AreEqual (true, result.Hit);
Assert.AreEqual (new Vector3 (9, 1, 0), result.Point);
Assert.AreEqual (new Vector3 (-1, 0, 0), result.Normal);
Assert.AreEqual (8, result.Distance, 0.01f);
Assert.AreEqual (0.08f, result.Fraction, 0.01f);
result = wld.Sweep (node1, new Vector3 (0, 100, 0));
Assert.AreEqual (false, result.Hit);
result = wld.Sweep (node1, new Vector3 (-100, 100, 0));
Assert.AreEqual (false, result.Hit);
wld.Destroy ();
}
示例6: Test_Distance_Invalid_Objects
public void Test_Distance_Invalid_Objects()
{
var node1 = new Node ("Node1");
var node2 = new Node ("Node2");
var wld = new World ();
wld.AddChild (node1);
wld.AddChild (node2);
wld.CollisionUpdate ();
var d = wld.Distance (node1, node2);
Assert.AreEqual (Single.NaN, d);
wld.Destroy ();
}
示例7: Main
public static void Main(string[] args)
{
var g2d = DD.Graphics2D.GetInstance ();
g2d.CreateWindow (800, 600, "こんにちは、世界");
Resource.SetTextureDirectory ("DatabaseSample/Textures/");
// ----------------------------------------
var node1 = MyCharacterHolder.Create ();
var node2 = MyCharacterViewer.Create (new Vector3 (0, 0, 0));
var node3 = MyCharacterSelector.Create (new Vector3 (0,0,0));
var wld = new World ();
wld.AddChild (node1);
wld.AddChild (node2);
wld.AddChild (node3);
// ----------------------------------------
var active = true;
g2d.OnClosed += delegate (object sender, EventArgs eventArgs) {
active = false;
};
Console.WriteLine ("Start of Main Loop");
g2d.SetFrameRateLimit (60);
var watch = new Stopwatch ();
watch.Start ();
while (active) {
var msec = watch.ElapsedMilliseconds;
g2d.Dispatch (wld);
wld.Animate (msec, 33);
wld.Deliver ();
wld.CollisionUpdate ();
wld.Update (msec);
wld.Purge ();
g2d.Draw (wld);
}
Console.WriteLine ("End of Game");
wld.Destroy ();
}
示例8: Test_AllNodes
public void Test_AllNodes()
{
var wld = new World ();
for (var i = 0; i < 10; i++) {
var node = new Node ("" + i);
var col = new CollisionObject ();
col.Shape = new SphereShape (1);
node.Attach (col);
node.Translate (i, 0, 0);
wld.AddChild (node);
}
wld.CollisionUpdate ();
var results = wld.RayCast (new Vector3 (-10, 10, 0), new Vector3 (10, 10, 0));
Assert.AreEqual (0, results.Count ());
results = wld.RayCast (new Vector3 (-10, 0, 0), new Vector3 (10, 0, 0));
Assert.AreEqual (10, results.Count ());
Assert.AreEqual ("0", results.ElementAt (0).Node.Name);
Assert.AreEqual ("1", results.ElementAt (1).Node.Name);
Assert.AreEqual ("2", results.ElementAt (2).Node.Name);
Assert.AreEqual ("3", results.ElementAt (3).Node.Name);
Assert.AreEqual ("4", results.ElementAt (4).Node.Name);
Assert.AreEqual ("5", results.ElementAt (5).Node.Name);
Assert.AreEqual ("6", results.ElementAt (6).Node.Name);
Assert.AreEqual ("7", results.ElementAt (7).Node.Name);
Assert.AreEqual ("8", results.ElementAt (8).Node.Name);
Assert.AreEqual ("9", results.ElementAt (9).Node.Name);
wld.Destroy ();
}
示例9: Test_Pick
public void Test_Pick()
{
var node1 = new Node ("Node1");
var col1 = new CollisionObject ();
col1.Shape = new BoxShape (1, 1, 1);
node1.Attach (col1);
var node2 = new Node ("Node2");
var col2 = new CollisionObject ();
col2.Shape = new BoxShape (1, 1, 1);
node2.Attach (col2);
var wld = new World ();
wld.AddChild (node1);
wld.AddChild (node2);
node1.Translate (1, 0, 0);
node2.Translate (-1, 0, 0);
wld.CollisionUpdate ();
Assert.AreEqual (null, wld.Pick (new Vector3 (3, -10, 0), new Vector3 (3, 10, 0)));
Assert.AreEqual (node1, wld.Pick (new Vector3 (2, -10, 0), new Vector3 (2, 10, 0)));
Assert.AreEqual (node1, wld.Pick (new Vector3 (1, -10, 0), new Vector3 (1, 10, 0)));
Assert.AreEqual (node1, wld.Pick (new Vector3 (0, -10, 0), new Vector3 (0, 10, 0)));
Assert.AreEqual (node2, wld.Pick (new Vector3 (-1, -10, 0), new Vector3 (-1, 10, 0)));
Assert.AreEqual (node2, wld.Pick (new Vector3 (-2, -10, 0), new Vector3 (-2, 10, 0)));
Assert.AreEqual (null, wld.Pick (new Vector3 (-3, -10, 0), new Vector3 (-3, 10, 0)));
}
示例10: Test_OnColisionEnter
public void Test_OnColisionEnter()
{
var node1 = new Node ("Node1");
var cmp1 = new MyComponent ();
var col1 = new CollisionObject ();
col1.Shape = new BoxShape (1, 1, 1);
node1.Attach (cmp1);
node1.Attach (col1);
var node2 = new Node ("Node2");
var cmp2 = new MyComponent ();
var col2 = new CollisionObject ();
col2.Shape = new BoxShape (1, 1, 1);
node2.Attach (cmp2);
node2.Attach (col2);
var wld = new World ();
wld.AddChild (node1);
wld.AddChild (node2);
node1.Translate (1, 0, 0);
// ここでコリジョン発生
wld.CollisionUpdate ();
Assert.AreEqual (true, cmp1.IsCollisionEnterCalled);
Assert.AreEqual (true, cmp2.IsCollisionEnterCalled);
// 離れる
node2.Translate (10, 0, 0);
// ここでコリジョン消失
wld.CollisionUpdate ();
Assert.AreEqual (true, cmp1.IsCollisionExitCalled);
Assert.AreEqual (true, cmp2.IsCollisionExitCalled);
}
示例11: Test_SyncWithCollisionWorld
public void Test_SyncWithCollisionWorld()
{
var node1 = new Node ("Node1");
node1.Attach (new CollisionObject ());
node1.CollisionObject.Shape = new BoxShape (1, 1, 1);
node1.CollisionObject.Offset = new Vector3 (1, 2, 3);
var node2 = new Node ("Node2");
node2.Attach (new CollisionObject ());
node2.CollisionObject.Shape = new BoxShape (1, 1, 1);
node2.Translate (4, 5, 6);
var wld = new World ();
wld.AddChild (node1);
wld.AddChild (node2);
// コリジョン ワールドと同期
wld.CollisionUpdate ();
// BulletPhysics側ではオフセット込みの座標
Assert.AreEqual (new Vector3 (1, 2, 3), node1.CollisionObject.Data.WorldTransform.Origin.ToDD());
Assert.AreEqual (new Vector3 (4, 5, 6), node2.CollisionObject.Data.WorldTransform.Origin.ToDD ());
}
示例12: Test_RegisterCollisionObject
public void Test_RegisterCollisionObject()
{
var node1 = new Node ("Node1");
var col1 = new CollisionObject ();
col1.Shape = new BoxShape (1, 1, 1);
node1.Attach (col1);
var node2 = new Node ("Node2");
var col2 = new CollisionObject ();
col2.Shape = new BoxShape (1, 1, 1);
node2.Attach (col2);
var wld = new World ();
wld.AddChild (node1);
wld.AddChild (node2);
// ここで登録される
wld.CollisionUpdate ();
Assert.AreEqual (2, wld.CollisionAnalyzer.CollisionObjectCount);
Assert.AreEqual (2, wld.CollisionAnalyzer.CollisionObjects.Count ());
wld.Destroy ();
}
示例13: Test_SphereShape
public void Test_SphereShape()
{
var node = new Node ();
var col = new CollisionObject ();
col.Shape = new SphereShape (1);
col.SetOffset (1, 0, 0);
node.Attach (col);
node.Translate (1, 0, 0);
node.Rotate (45, 0, 0, 1);
var wld = new World ();
wld.AddChild (node);
wld.CollisionUpdate ();
// (1+1) - 1
var result = wld.RayCast (new Vector3 (-10, 0, 0), new Vector3 (10, 0, 0)).First ();
Assert.AreEqual (true, result.Hit);
Assert.AreEqual (new Vector3 (1, 0, 0), result.Point);
Assert.AreEqual (new Vector3 (-1, 0, 0), result.Normal);
Assert.AreEqual (11, result.Distance, 0.01f);
Assert.AreEqual (0.55f, result.Fraction, 0.01f);
// (1+1) + 1
result = wld.RayCast (new Vector3 (10, 0, 0), new Vector3 (-10, 0, 0)).First ();
Assert.AreEqual (true, result.Hit);
Assert.AreEqual (new Vector3 (3, 0, 0), result.Point);
Assert.AreEqual (new Vector3 (1, 0, 0), result.Normal);
Assert.AreEqual (7, result.Distance, 0.01f);
Assert.AreEqual (0.35f, result.Fraction, 0.01f);
wld.Destroy ();
}
示例14: Test_CollideWith
public void Test_CollideWith()
{
var node = new Node ();
var col = new CollisionObject ();
col.Shape = new SphereShape (1);
node.Attach (col);
node.GroupID = 1 << 1;
var wld = new World ();
wld.AddChild (node);
wld.CollisionUpdate ();
// 1<<0
var result = wld.RayCast (new Vector3 (-10, 0, 0), new Vector3 (10, 0, 0), 1 << 0).FirstOrDefault ();
Assert.AreEqual (false, result.Hit);
// 1<<1
result = wld.RayCast (new Vector3 (-10, 0, 0), new Vector3 (10, 0, 0), 1 << 1).FirstOrDefault ();
Assert.AreEqual (true, result.Hit);
// 1<<2
result = wld.RayCast (new Vector3 (-10, 0, 0), new Vector3 (10, 0, 0), 1 << 2).FirstOrDefault ();
Assert.AreEqual (false, result.Hit);
// 0
result = wld.RayCast (new Vector3 (-10, 0, 0), new Vector3 (10, 0, 0), 0).FirstOrDefault ();
Assert.AreEqual (false, result.Hit);
// -1
result = wld.RayCast (new Vector3 (-10, 0, 0), new Vector3 (10, 0, 0), -1).FirstOrDefault ();
Assert.AreEqual (true, result.Hit);
wld.Destroy ();
}
示例15: Test_RayCast
public void Test_RayCast()
{
var node1 = new Node ("Node1");
var col1 = new CollisionObject ();
col1.Shape = new BoxShape (1, 1, 1);
node1.Attach (col1);
var node2 = new Node ("Node1");
var col2 = new CollisionObject ();
col2.Shape = new BoxShape (1, 1, 1);
node2.Attach (col2);
var wld = new World ();
wld.AddChild (node1);
wld.AddChild (node2);
node1.Translate (1, 0, 0);
node2.Translate (-1, 0, 0);
wld.CollisionUpdate ();
var start = new Vector3 (10, 0, 0);
var end = new Vector3 (-10, 0, 0);
var results = wld.RayCast (start, end).ToArray ();
Assert.AreEqual (2, results.Count ());
var result1 = results[0];
var result2 = results[1];
Assert.AreEqual (node1, result1.Node);
Assert.AreEqual (0.39394f, result1.Fraction, 0.01f);
Assert.AreEqual (new Vector3 (2, 0, 0), result1.Point);
Assert.AreEqual (node2, result2.Node);
Assert.AreEqual (0.49495f, result2.Fraction, 0.01f);
Assert.AreEqual (new Vector3 (0, 0, 0), result2.Point);
}