aboutsummaryrefslogtreecommitdiff
path: root/src/test/scala/sims/test/gui/scenes/CollisionScene.scala
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/scala/sims/test/gui/scenes/CollisionScene.scala')
-rw-r--r--src/test/scala/sims/test/gui/scenes/CollisionScene.scala41
1 files changed, 41 insertions, 0 deletions
diff --git a/src/test/scala/sims/test/gui/scenes/CollisionScene.scala b/src/test/scala/sims/test/gui/scenes/CollisionScene.scala
new file mode 100644
index 0000000..cf2ea61
--- /dev/null
+++ b/src/test/scala/sims/test/gui/scenes/CollisionScene.scala
@@ -0,0 +1,41 @@
+package sims.test.gui
+package scenes
+
+import sims.dynamics._
+import sims.math._
+import sims.dynamics._
+
+object CollisionScene extends Scene {
+ override def description = "A basic collision detection test."
+
+ var c1 = (new Circle(1) {restitution = 1.0}).asBody
+ var c2 = (new Circle(1) {position = Vector2D(3, 0)}).asBody
+ var r1 = (new Rectangle(0.5, 0.5) {position = Vector2D(6,0)}).asBody
+
+ def init() = {
+ c1 = (new Circle(1) {restitution = 1.0}).asBody
+ c2 = (new Circle(1) {position = Vector2D(3, 0); restitution = 1.0}).asBody
+ r1 = (new Rectangle(0.5, 0.5) {position = Vector2D(6,0)}).asBody
+
+ c1.linearVelocity = Vector2D(1, 0)
+
+ world.gravity = Vector2D(0, 0)
+ world += c1
+ world += c2
+ world += r1
+
+ reactions += {
+ case Stepped(`world`) =>
+ println(
+ "p: " + (c1.linearMomentum.length + c2.linearMomentum.length + r1.linearMomentum.length).toFloat +
+ "\tE: " + (E(c1) + E(c2) + E(r1)).toFloat
+ )
+ }
+ }
+
+
+ def E(b: Body) = {
+ (b.linearVelocity dot b.linearVelocity) * b.mass / 2
+ }
+
+} \ No newline at end of file