summaryrefslogtreecommitdiff
path: root/src/main/scala/graphyx/tests
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/scala/graphyx/tests')
-rw-r--r--src/main/scala/graphyx/tests/Atom.scala36
-rw-r--r--src/main/scala/graphyx/tests/BallStack.scala25
-rw-r--r--src/main/scala/graphyx/tests/Cannon.scala59
-rw-r--r--src/main/scala/graphyx/tests/Carriage.scala55
-rw-r--r--src/main/scala/graphyx/tests/Chain.scala26
-rw-r--r--src/main/scala/graphyx/tests/CompositeShape.scala36
-rw-r--r--src/main/scala/graphyx/tests/Cup.scala31
-rw-r--r--src/main/scala/graphyx/tests/EmptyTest.scala15
-rw-r--r--src/main/scala/graphyx/tests/Friction.scala57
-rw-r--r--src/main/scala/graphyx/tests/Friction2.scala33
-rw-r--r--src/main/scala/graphyx/tests/General1.scala126
-rw-r--r--src/main/scala/graphyx/tests/General2.scala28
-rw-r--r--src/main/scala/graphyx/tests/Joints1.scala24
-rw-r--r--src/main/scala/graphyx/tests/Joints2.scala29
-rw-r--r--src/main/scala/graphyx/tests/Net.scala22
-rw-r--r--src/main/scala/graphyx/tests/RagdollTest.scala26
-rw-r--r--src/main/scala/graphyx/tests/Restitution.scala21
-rw-r--r--src/main/scala/graphyx/tests/Spring.scala23
-rw-r--r--src/main/scala/graphyx/tests/Stacking.scala24
-rw-r--r--src/main/scala/graphyx/tests/Test.scala17
-rw-r--r--src/main/scala/graphyx/tests/Wave.scala34
21 files changed, 747 insertions, 0 deletions
diff --git a/src/main/scala/graphyx/tests/Atom.scala b/src/main/scala/graphyx/tests/Atom.scala
new file mode 100644
index 0000000..31d03fc
--- /dev/null
+++ b/src/main/scala/graphyx/tests/Atom.scala
@@ -0,0 +1,36 @@
+package graphyx.tests
+
+import sims.dynamics._
+import sims.dynamics.joints._
+import sims.geometry._
+
+object Atom extends Test{
+ val title = "Atom"
+ val world = new World
+
+ var nucleus = new Body(Circle(0.05, 1000)) {fixed = true}
+ var electrons: List[Body] = Nil
+ var connections: List[SpringJoint] = Nil
+
+ def init = {
+ world -= nucleus
+ nucleus = new Body(Circle(0.05, 10)) {fixed = true}
+ world += nucleus
+ world --= electrons
+ electrons = Nil
+ for (c <- connections) world -= c
+ connections = Nil
+ }
+
+ enableEvent = true
+ override def fireEvent = {
+ val e = (new Circle(0.1, 10) {pos = Vector2D(0, -1)}).asBody
+ e.linearVelocity = Vector2D(-50,100)
+ electrons = e :: electrons
+ world += e
+
+ val c = new SpringJoint(nucleus, e, 500)
+ connections = c :: connections
+ world += c
+ }
+}
diff --git a/src/main/scala/graphyx/tests/BallStack.scala b/src/main/scala/graphyx/tests/BallStack.scala
new file mode 100644
index 0000000..8e45611
--- /dev/null
+++ b/src/main/scala/graphyx/tests/BallStack.scala
@@ -0,0 +1,25 @@
+/*
+ * Graphyx
+ * copyright (c) 2009 Jakob Odersky
+ * made available under the MIT License
+*/
+
+package graphyx.tests
+
+import sims.dynamics._
+import sims.geometry._
+
+object BallStack extends Test{
+ val world = new World
+ val title = "BallStack"
+ def init(): Unit = {
+ val ground = new Rectangle(1,0.1,1) {pos = Vector2D(1,0)}
+ val wallLeft = new Rectangle(0.1,1,1) {pos = Vector2D(0,1)}
+ val wallRight = new Rectangle(0.1,1,1) {pos = Vector2D(2,1)}
+ val box = new Body(ground, wallLeft, wallRight) {fixed = true}
+ world += box
+ world += (new Circle(0.1,1) {pos = Vector2D(1.1, 2.8)}).asBody
+ world ++= (for (i <- 0 to 50) yield (new Circle(0.1,1) {pos = Vector2D(1, 3 + 0.2 * i)}).asBody)
+
+ }
+}
diff --git a/src/main/scala/graphyx/tests/Cannon.scala b/src/main/scala/graphyx/tests/Cannon.scala
new file mode 100644
index 0000000..6c59d3f
--- /dev/null
+++ b/src/main/scala/graphyx/tests/Cannon.scala
@@ -0,0 +1,59 @@
+package graphyx.tests
+
+import sims.dynamics._
+import sims.geometry._
+import sims.prefabs._
+
+object Cannon extends Test{
+ val title = "Cannon"
+ val world = new World
+
+ def init = {
+ val cannon = new Prefab{
+ val hull = new Body(
+ new Rectangle(0.1,0.5,1) {pos = Vector2D(0.1, 0.6); friction = 0.0},
+ new Rectangle(0.1,0.5,1) {pos = Vector2D(0.5, 0.6); friction = 0.0},
+ new Rectangle(0.1,0.1,1) {pos = Vector2D(0.3, 0.2); friction = 0.0}
+ )
+ hull.fixed = true
+ hull.rotation -= math.Pi / 2
+
+ val ball = new Body(new Circle(0.1,100) {pos = Vector2D(0.3, 0.56)})
+
+ override val bodies = List(hull, ball)
+ override val joints = Nil
+ }
+ val n = 10
+ val r = 0.1
+ val initialPos = Vector2D(5,0)
+ val stack = for (i <- (0 to n).toList) yield {
+ for (j <- (0 to n-i).toList) yield
+ new Body(
+ new Circle(r,10){
+ pos = Vector2D(2 * j * r + i * r, 1.7 * i * r) + initialPos
+ }
+ ) {fixed = (i == 0)}
+ }
+ world += cannon
+ world ++= stack.flatten
+
+ }
+
+ enableEvent = true
+ override def fireEvent() = blastBomb
+
+ def blastBomb() = {
+ val bombPos = Vector2D(0, 0.56)
+ val bombRadius = 1
+ val bombImpulse = 200
+ val region = new Circle(bombRadius, 0) {pos = bombPos}
+ val detector = world.detector.asInstanceOf[sims.collision.GridDetector]
+ val collisions = for (s <- world.shapes; if detector.colliding(sims.collision.Pair(region, s))) yield detector.collision(sims.collision.Pair(region, s))
+ for (c <- collisions) {
+ if (c.shape1 != region)
+ for(p <- c.points) c.shape1.body.applyImpulse((p - bombPos).unit * bombImpulse, p)
+ if (c.shape2 != region)
+ for(p <- c.points) c.shape2.body.applyImpulse((p - bombPos).unit * bombImpulse, p)
+ }
+ }
+}
diff --git a/src/main/scala/graphyx/tests/Carriage.scala b/src/main/scala/graphyx/tests/Carriage.scala
new file mode 100644
index 0000000..967c6e5
--- /dev/null
+++ b/src/main/scala/graphyx/tests/Carriage.scala
@@ -0,0 +1,55 @@
+/*
+ * Graphyx
+ * copyright (c) 2009 Jakob Odersky
+ * made available under the MIT License
+*/
+
+package graphyx.tests
+
+import sims.dynamics._
+import sims.dynamics.joints._
+import sims.geometry._
+
+object Carriage extends Test{
+ val title = "Carriage"
+ val world = new World
+
+ def init = {
+ val car = new Car
+
+ val groundShapes = for (i <- (0 to 200).toList) yield (new Rectangle(0.2, 0.1, 1) {
+ pos = Vector2D(0.4 * i, 0)
+ transientShapes += car.chassis.shapes(0)
+ })
+ val ground = new Body(groundShapes: _*) //Rectangle(100, 0.1, 1).asBody
+ ground.pos = Vector2D(0,0)
+ ground.fixed = true
+ ground.rotation = -0.2
+
+
+ world += ground
+ world += car
+
+ }
+
+ class Car extends sims.prefabs.Prefab {
+
+ val chassis = (new Rectangle(0.5, 0.05, 10) {pos = Vector2D(0, 1)}).asBody
+ val rightWheel = (new Circle(0.1, 10) {pos = Vector2D(0.4,0.8)}).asBody
+ val leftWheel = (new Circle(0.1, 10) {pos = Vector2D(-0.4,0.8)}).asBody
+
+ override val bodies = List(chassis, rightWheel, leftWheel)
+
+ val rightStabelizer = new DistanceJoint(chassis, rightWheel)
+ val rightDamper = new SpringJoint(chassis, chassis.pos + Vector2D(rightWheel.pos.x, 0),
+ rightWheel, rightWheel.pos, 500) {damping = 1}
+
+ val leftStabelizer = new DistanceJoint(chassis, leftWheel)
+ val leftDamper = new SpringJoint(chassis, chassis.pos + Vector2D(leftWheel.pos.x, 0),
+ leftWheel, leftWheel.pos, 500) {damping = 1}
+
+ override val joints = List(rightStabelizer, rightDamper, leftStabelizer, leftDamper)
+
+ }
+
+}
diff --git a/src/main/scala/graphyx/tests/Chain.scala b/src/main/scala/graphyx/tests/Chain.scala
new file mode 100644
index 0000000..27511ca
--- /dev/null
+++ b/src/main/scala/graphyx/tests/Chain.scala
@@ -0,0 +1,26 @@
+/*
+ * Graphyx
+ * copyright (c) 2009 Jakob Odersky
+ * made available under the MIT License
+*/
+
+package graphyx.tests
+
+import sims.dynamics._
+import sims.dynamics.joints._
+import sims.prefabs._
+import sims.geometry._
+
+object Chain extends Test{
+ override val title = "Chain"
+ val world = new World
+ def init = {
+ val nodes = for (i <- (0 until 20).toList) yield (new Circle(0.02, 1) {pos = Vector2D(i * 0.2, 1)}).asBody
+ nodes(0).fixed = true
+ nodes(19).fixed = true
+ val connectors = for (i <- (0 until nodes.length - 1).toList) yield new DistanceJoint(nodes(i), nodes(i + 1))
+ for (n <- nodes) world += n
+ for (c <- connectors) world += c
+ world += (new Circle(1,0.001) {pos = Vector2D(2,2)}).asBody
+ }
+}
diff --git a/src/main/scala/graphyx/tests/CompositeShape.scala b/src/main/scala/graphyx/tests/CompositeShape.scala
new file mode 100644
index 0000000..184bab9
--- /dev/null
+++ b/src/main/scala/graphyx/tests/CompositeShape.scala
@@ -0,0 +1,36 @@
+/*
+ * Graphyx
+ * copyright (c) 2009 Jakob Odersky
+ * made available under the MIT License
+*/
+
+package graphyx.tests
+
+import sims.geometry._
+import sims.dynamics._
+
+import sims.util._
+import sims.util.Positioning._
+
+object CompositeShape extends Test{
+ val title = "Composite Shape"
+ val world = new World
+
+ def init = {
+
+ val ground = new Body(Rectangle(1000,0.1,1)) {fixed = true}
+ world += ground
+
+ val h2o = {
+ val h = new Circle(0.2,1)
+ val o1 = new Circle(0.05,1)
+ val o2 = new Circle(0.05,1) {rotation = 0.3}
+ position(o1) {0.25 above h}
+ o2.pos = (new Polar(0.25, math.Pi / 3)) from h
+ new Body(h, o1, o2) {pos = Vector2D(0, 0.5)}
+ }
+ world += h2o
+ }
+
+}
+
diff --git a/src/main/scala/graphyx/tests/Cup.scala b/src/main/scala/graphyx/tests/Cup.scala
new file mode 100644
index 0000000..ad791f0
--- /dev/null
+++ b/src/main/scala/graphyx/tests/Cup.scala
@@ -0,0 +1,31 @@
+/*
+ * Graphyx
+ * copyright (c) 2009 Jakob Odersky
+ * made available under the MIT License
+*/
+
+package graphyx.tests
+
+import sims.dynamics._
+import sims.geometry._
+object Cup extends Test {
+ val title = "Cup"
+ val world = new World
+
+ def init = {
+ val ground = (new Rectangle(1000, 0.1, 1) {friction = 1}).asBody
+ ground.fixed = true
+ world += ground
+
+ val cupShapes = for (i <- 0 to (10 * math.Pi).toInt) yield new Circle(0.1,1) {pos = Vector2D(math.cos(-i / 10.0), math.sin(-i / 10.0)); restitution = 0.0; friction = 1.0}
+ val cup = new Body(cupShapes: _*) {fixed = true; pos = Vector2D(0, 1)}
+ world += cup
+
+ val ball1 = (new Circle(0.2, 1) {pos = Vector2D(0, 2)}).asBody
+ val ball2 = (new Circle(0.2, 1) {pos = Vector2D(-0.4, 2)}).asBody
+ val ball3 = (new Circle(0.2, 1) {pos = Vector2D(0.4, 2)}).asBody
+ world += ball1
+ world += ball2
+ world += ball3
+ }
+}
diff --git a/src/main/scala/graphyx/tests/EmptyTest.scala b/src/main/scala/graphyx/tests/EmptyTest.scala
new file mode 100644
index 0000000..0e3bd84
--- /dev/null
+++ b/src/main/scala/graphyx/tests/EmptyTest.scala
@@ -0,0 +1,15 @@
+/*
+ * Graphyx
+ * copyright (c) 2009 Jakob Odersky
+ * made available under the MIT License
+*/
+
+package graphyx.tests
+
+import sims.dynamics._
+import sims.geometry._
+object EmptyTest extends Test{
+ override val title = "Empty Test"
+ val world = new World
+ def init = {}
+}
diff --git a/src/main/scala/graphyx/tests/Friction.scala b/src/main/scala/graphyx/tests/Friction.scala
new file mode 100644
index 0000000..ba9fb69
--- /dev/null
+++ b/src/main/scala/graphyx/tests/Friction.scala
@@ -0,0 +1,57 @@
+/*
+ * Graphyx
+ * copyright (c) 2009 Jakob Odersky
+ * made available under the MIT License
+*/
+
+package graphyx.tests
+
+import sims.geometry._
+import sims.dynamics._
+import sims.dynamics.joints._
+
+object Friction extends Test{
+ val title = "Friction"
+ val world = new World
+
+ var r1: RevoluteJoint = _
+ var r2: RevoluteJoint = _
+ var r3: RevoluteJoint = _
+
+ def init = {
+ val ground = (new Rectangle(1000, 0.1, 1) {friction = 1}).asBody
+ ground.fixed = true
+ world += ground
+
+ val ball1 = (new Circle(0.2, 1) {pos = Vector2D(0, 1); friction = 0.05}).asBody
+ ball1.angularVelocity = -80
+ ball1.monitor = true
+ val ball2 = (new Circle(0.2, 1) {pos = Vector2D(1, 1); friction = 0.2}).asBody
+ ball2.angularVelocity = -80
+ ball2.monitor = true
+ val ball3 = (new Circle(0.2, 1) {pos = Vector2D(2, 1); friction = 1}).asBody
+ ball3.angularVelocity = -80
+ ball3.monitor = true
+
+ world += ball1
+ world += ball2
+ world += ball3
+
+ world.monitors += ("", (b: Body) => "I=" + b.I + "\tw=" + b.angularVelocity + "\tEcin=" + 0.5 * b.I * b.angularVelocity * b.angularVelocity)
+
+ r1 = RevoluteJoint(ground, ball1, ball1.pos)
+ r2 = RevoluteJoint(ground, ball2, ball2.pos)
+ r3 = RevoluteJoint(ground, ball3, ball3.pos)
+ world += r1
+ world += r2
+ world += r3
+ }
+
+ enableEvent = true
+ override def fireEvent = {
+ world -= r1
+ world -= r2
+ world -= r3
+ }
+
+}
diff --git a/src/main/scala/graphyx/tests/Friction2.scala b/src/main/scala/graphyx/tests/Friction2.scala
new file mode 100644
index 0000000..5204fcf
--- /dev/null
+++ b/src/main/scala/graphyx/tests/Friction2.scala
@@ -0,0 +1,33 @@
+/*
+ * Graphyx
+ * copyright (c) 2009 Jakob Odersky
+ * made available under the MIT License
+*/
+
+package graphyx.tests
+
+import sims.geometry._
+import sims.dynamics._
+import sims.dynamics.joints._
+
+object Friction2 extends Test{
+ val title = "Friction2"
+ val world = new World {override val detector = new sims.collision.GridDetector(this) {gridSide = 0.2}}
+
+ def init = {
+ val shapes = for (i <- (0 to 20).toList) yield (new Rectangle(0.2, 0.1, 1) {
+ pos = Vector2D(0.4 * i, 0)
+ friction = (i * 1.0 / 10)
+ restitution = 0
+ })
+ val ground = new Body(shapes: _*)
+ ground.pos = Vector2D(0,0)
+ ground.fixed = true
+ ground.rotation = -math.Pi / 5
+ world += ground
+
+ val b: Body = (new Circle(0.1,10)) ~ (new Circle(0.1,10) {pos = Vector2D(0.2,0)}) ~ (new Circle(0.1,10) {pos = Vector2D(0.4,0)})
+ b.pos = Vector2D(0.1,0.1)
+ world += b
+ }
+}
diff --git a/src/main/scala/graphyx/tests/General1.scala b/src/main/scala/graphyx/tests/General1.scala
new file mode 100644
index 0000000..4ab401f
--- /dev/null
+++ b/src/main/scala/graphyx/tests/General1.scala
@@ -0,0 +1,126 @@
+/*
+ * Graphyx
+ * copyright (c) 2009 Jakob Odersky
+ * made available under the MIT License
+*/
+
+package graphyx.tests
+
+import sims._
+import sims.geometry._
+import sims.collision._
+import sims.dynamics._
+import sims.dynamics.joints._
+object General1 extends Test{
+ override val title = "General1"
+ val world = new World
+
+ def init() = {
+ val b0 = new Circle(0.1,1).asBody
+ b0.fixed = true
+ val b1 = (new Circle(0.1,1) {pos = Vector2D(0,1)}).asBody
+ //b0.linearVelocity = Vector2D(0,0.4)
+ b0.monitor = true
+ b1.monitor = true
+ val circles = for (i <- (0 until 10).toList) yield (new Circle(0.1,1) {pos = Vector2D(0, 1.2 + 0.2 * i)}).asBody
+ //for (c <- circles) world += c
+ //world.gravity = Vector2D.Null
+ // world += b0
+ //world += b1
+
+ world.monitors += ("Veclocity = ", _.linearVelocity.length.toString)
+
+ val b2 = (new Rectangle(0.1,0.15,1) {pos = Vector2D(1,0)}).asBody
+ b2.fixed = true
+ b2.rotation = 2
+ val b3 = (new Circle(0.1,1) {pos = Vector2D(1,1.1)}).asBody
+ //world += b2
+ //world += b3
+
+ val b4 = (new Rectangle(0.1,0.15,1) {pos = Vector2D(2,0)}).asBody
+ b4.fixed = true
+ b4.rotation = 2
+ val b5 = (new Rectangle(0.1,0.15,1) {pos = Vector2D(2,1.2)}).asBody
+ //world += b4
+ //world += b5
+
+ val bn = (new RegularPolygon(5,0.1,1) {pos = Vector2D(3,0)}).asBody
+ //world += bn
+
+ //Make cannon and balls
+ val hull = new Body(
+ new Rectangle(0.1,0.5,1) {pos = Vector2D(0.1, 0.5)},
+ new Rectangle(0.1,0.5,1) {pos = Vector2D(0.5, 0.5)},
+ new Rectangle(0.1,0.1,1) {pos = Vector2D(0.3, 0.1)}
+ )
+ hull.fixed = true
+ hull.rotation -= scala.math.Pi / 4
+
+ val ball = new Body(
+ new Circle(0.1,20) {pos = Vector2D(0.3, 0.3)}
+ )
+ val ball2 = new Body(
+ new Circle(0.1,20) {pos = Vector2D(0.3, 0.5)}
+ )
+ world += hull
+ world += ball
+ world += ball2
+
+ //Swing
+ val anchor = (new Circle(0.05,1) {pos = Vector2D(25,10)}).asBody
+ anchor.fixed = true
+ val block = (new RegularPolygon(9,0.5,2) {pos = Vector2D(25,1)}).asBody
+ val joint = new DistanceJoint(anchor, block)
+ world += anchor
+ world += block
+ world += joint
+
+ //Make stack
+ val stack = for (i <- (0 until 10).toList) yield (new Circle(0.1,1) {pos = Vector2D(30, 0.2 + 0.2 * i)}).asBody
+ for (e <- stack) world += e
+
+
+ /*
+ val springBoardHull = new Body(
+ new Rectangle(0.1,0.5,1) {pos = Vector2D(-1.1, 0.5)},
+ new Rectangle(0.1,0.5,1) {pos = Vector2D(-1.5, 0.5)},
+ new Rectangle(0.1,0.1,1) {pos = Vector2D(-1.3, 0.1)}
+ )
+ springBoardHull.fixed = true
+ world += springBoardHull
+
+ val springBoard = new Body(
+ new Circle(0.1,20) {pos = Vector2D(-1.3, 0.5)}
+ )
+ world += springBoard
+
+ val spring = new SpringJoint(springBoardHull, Vector2D(-1.3, 0.1), springBoard, springBoard.pos, 2000)
+ spring.damping = 10
+ world += spring
+ */
+
+ val ground = (new Rectangle(1000,0.5,1) {pos = Vector2D(0, -0.4)}).asBody
+ ground.fixed = true
+ world += ground
+
+ world += (new Circle(0.1,1) {pos = Vector2D(2,2)}) ~ (new Circle(0.1,1) {pos = Vector2D(2,2.2)})
+ }
+
+ enableEvent = true
+ override def fireEvent() = blastBomb
+
+ def blastBomb() = {
+ val bombPos = Vector2D(0, 0)
+ val bombRadius = 1
+ val bombImpulse = 10
+ val region = new Circle(bombRadius, 0) {pos = bombPos}
+ val detector = world.detector.asInstanceOf[GridDetector]
+ val collisions = for (s <- world.shapes; if detector.colliding(collision.Pair(region, s))) yield detector.collision(collision.Pair(region, s))
+ for (c <- collisions) {
+ if (c.shape1 != region)
+ for(p <- c.points) c.shape1.body.applyImpulse((p - bombPos).unit * bombImpulse, p)
+ if (c.shape2 != region)
+ for(p <- c.points) c.shape2.body.applyImpulse((p - bombPos).unit * bombImpulse, p)
+ }
+ }
+}
diff --git a/src/main/scala/graphyx/tests/General2.scala b/src/main/scala/graphyx/tests/General2.scala
new file mode 100644
index 0000000..2006080
--- /dev/null
+++ b/src/main/scala/graphyx/tests/General2.scala
@@ -0,0 +1,28 @@
+/*
+ * Graphyx
+ * copyright (c) 2009 Jakob Odersky
+ * made available under the MIT License
+*/
+
+package graphyx.tests
+
+import sims.geometry._
+import sims.dynamics._
+
+object General2 extends Test{
+ val title = "General2"
+ val world = new World
+
+ def init = {
+ world += new Body(new Rectangle(100,0.5,1) {pos = Vector2D(0, -0.5)}) {fixed = true}
+ //new Body(new Circle(0.05,1) {pos = Vector2D(0, 0.05)}),
+ //new Body(new Rectangle(0.5,0.1,1) {pos = Vector2D(0, 0.2)}),
+ //new Body(new Circle(0.05,1) {pos = Vector2D(1, 0.05)}))
+
+ world += new Body(new Circle(0.2,1) {pos = Vector2D(5, 0.2)})
+ world += new Body(new Rectangle(1.5,0.1,1) {pos = Vector2D(4.5, 0.5)}, new Rectangle(0.05,0.1,1) {pos = Vector2D(3.05,0.7)})
+ world += new Body(new Circle(0.1,1) {pos = Vector2D(3.2, 0.7)})
+ world += new Body(new Circle(0.5,10) {pos = Vector2D(8, 0.5)})
+
+ }
+}
diff --git a/src/main/scala/graphyx/tests/Joints1.scala b/src/main/scala/graphyx/tests/Joints1.scala
new file mode 100644
index 0000000..ad143ec
--- /dev/null
+++ b/src/main/scala/graphyx/tests/Joints1.scala
@@ -0,0 +1,24 @@
+/*
+ * Graphyx
+ * copyright (c) 2009 Jakob Odersky
+ * made available under the MIT License
+*/
+
+package graphyx.tests
+
+import sims.dynamics._
+import sims.dynamics.joints._
+import sims.geometry._
+
+object Joints1 extends Test{
+ override val title = "Joints1"
+ val world = new World
+ def init = {
+ val anchor = new Body(new Circle(0.03, 1) {pos = Vector2D(1,5)}) {fixed = true}
+ val weight = (new Rectangle(0.1, 0.5, 1) {pos = Vector2D(1,0)}).asBody
+ val joint = new DistanceJoint(anchor, anchor.pos, weight, weight.pos + Vector2D(0.1,0.2))
+ world += anchor
+ world += weight
+ world += joint
+ }
+}
diff --git a/src/main/scala/graphyx/tests/Joints2.scala b/src/main/scala/graphyx/tests/Joints2.scala
new file mode 100644
index 0000000..c190bc9
--- /dev/null
+++ b/src/main/scala/graphyx/tests/Joints2.scala
@@ -0,0 +1,29 @@
+/*
+ * Graphyx
+ * copyright (c) 2009 Jakob Odersky
+ * made available under the MIT License
+*/
+
+package graphyx.tests
+
+import sims.dynamics._
+import sims.dynamics.joints._
+import sims.geometry._
+import sims.util._
+import sims.util.Positioning._
+
+object Joints2 extends Test{
+ override val title = "Joints2"
+ val world = new World
+ def init() = {
+ val length = 100
+ val distance = 0.2
+ val anchors = for (i <- (0 until length).toList) yield new Body(new Circle(0.03,1) {pos = Vector2D(i * distance,5)}) {fixed = true}
+ val balls = for (i <- (0 until length).toList) yield new Body(new Circle(0.1,1) {pos = Vector2D(i * distance,0); restitution = 1})
+ balls(0).pos = Vector2D(0, 5) + Polar(5, -math.Pi / 1.5).toCarthesian
+ val joints = for (i <- (0 until length).toList) yield new DistanceJoint(anchors(i), balls(i))
+ for (a <- anchors) world += a
+ for (b <- balls) world += b
+ for (j <- joints) world += j
+ }
+}
diff --git a/src/main/scala/graphyx/tests/Net.scala b/src/main/scala/graphyx/tests/Net.scala
new file mode 100644
index 0000000..c340a80
--- /dev/null
+++ b/src/main/scala/graphyx/tests/Net.scala
@@ -0,0 +1,22 @@
+/*
+ * Graphyx
+ * copyright (c) 2009 Jakob Odersky
+ * made available under the MIT License
+*/
+
+package graphyx.tests
+
+import sims._
+import sims.geometry._
+import sims.dynamics._
+
+object Net extends Test{
+ val title = "Net"
+ val world = new World
+
+ def init = {
+ val n = new prefabs.Net(10, 10, Vector2D(4,4))
+ n.bodies(9).fixed = true
+ world += n
+ }
+}
diff --git a/src/main/scala/graphyx/tests/RagdollTest.scala b/src/main/scala/graphyx/tests/RagdollTest.scala
new file mode 100644
index 0000000..63c9ce5
--- /dev/null
+++ b/src/main/scala/graphyx/tests/RagdollTest.scala
@@ -0,0 +1,26 @@
+/*
+ * Graphyx
+ * copyright (c) 2009 Jakob Odersky
+ * made available under the MIT License
+*/
+
+package graphyx.tests
+
+import sims.dynamics._
+import sims.dynamics.joints._
+import sims.geometry._
+import sims.prefabs._
+
+object RagdollTest extends Test {
+ val title = "Ragdoll"
+ val world = new World
+
+ def init = {
+ val ground = new Body((for (i <- 0 to 1000) yield new Circle(0.5,1) {pos = Vector2D(0.5 * (i - 500), 0)}): _*)
+ ground.fixed = true
+ world += ground
+
+ world += new Ragdoll(Vector2D(0, 5))
+ }
+
+}
diff --git a/src/main/scala/graphyx/tests/Restitution.scala b/src/main/scala/graphyx/tests/Restitution.scala
new file mode 100644
index 0000000..9501a36
--- /dev/null
+++ b/src/main/scala/graphyx/tests/Restitution.scala
@@ -0,0 +1,21 @@
+/*
+ * Graphyx
+ * copyright (c) 2009 Jakob Odersky
+ * made available under the MIT License
+*/
+
+package graphyx.tests
+
+import sims.geometry._
+import sims.dynamics._
+
+object Restitution extends Test{
+ val title = "Restitution"
+ val world = new World
+
+ def init = {
+ world += new Body(new Rectangle(1000,0.1,10) {restitution = 1}) {fixed = true}
+ world ++= (for (i <- 0 until 10) yield (new Circle(0.05, 10) {pos = Vector2D(i * 0.5, 1); restitution = i / 10.0}).asBody)
+ }
+
+}
diff --git a/src/main/scala/graphyx/tests/Spring.scala b/src/main/scala/graphyx/tests/Spring.scala
new file mode 100644
index 0000000..e7fecb8
--- /dev/null
+++ b/src/main/scala/graphyx/tests/Spring.scala
@@ -0,0 +1,23 @@
+package graphyx.tests
+
+import sims.dynamics._
+import sims.dynamics.joints._
+import sims.geometry._
+import java.io._
+
+object Spring extends Test{
+ val title = "Spring"
+ val world = new World
+
+ def init = {
+ val anchor = Circle(0.05, 10).asBody
+ anchor.fixed = true
+ val particle = (new Circle(0.1, 20) {pos = Vector2D(0, -3)}).asBody
+ val spring = new SpringJoint(anchor, particle, 500, 2)
+ spring.damping = 0.5
+
+ world += anchor
+ world += particle
+ world += spring
+ }
+}
diff --git a/src/main/scala/graphyx/tests/Stacking.scala b/src/main/scala/graphyx/tests/Stacking.scala
new file mode 100644
index 0000000..63734b6
--- /dev/null
+++ b/src/main/scala/graphyx/tests/Stacking.scala
@@ -0,0 +1,24 @@
+/*
+ * Graphyx
+ * copyright (c) 2009 Jakob Odersky
+ * made available under the MIT License
+*/
+
+package graphyx.tests
+
+import sims.dynamics._
+import sims.geometry._
+
+object Stacking extends Test{
+ val world = new World
+ val title = "Stacking"
+ def init(): Unit = {
+ val sideWidth = 0.3
+ val sideHeight = 0.2
+ val boxes = 5
+ val distance = 0.1
+ val stack = for (i <- (0 until boxes).toList) yield (new Rectangle(sideWidth / (2 + 0.3 * i), sideHeight / 2, 1) {pos = Vector2D(1, i * (sideHeight + distance))}).asBody
+ stack(0).fixed = true
+ for (box <- stack) world += box
+ }
+}
diff --git a/src/main/scala/graphyx/tests/Test.scala b/src/main/scala/graphyx/tests/Test.scala
new file mode 100644
index 0000000..ca0f8e8
--- /dev/null
+++ b/src/main/scala/graphyx/tests/Test.scala
@@ -0,0 +1,17 @@
+/*
+ * Graphyx
+ * copyright (c) 2009 Jakob Odersky
+ * made available under the MIT License
+*/
+
+package graphyx.tests
+
+import sims.dynamics._
+trait Test {
+ val world: World
+ val title: String
+ def init(): Unit
+ var enableEvent: Boolean = false
+ def fireEvent(): Unit = println("No custom event method defined.")
+ override def toString() = title
+}
diff --git a/src/main/scala/graphyx/tests/Wave.scala b/src/main/scala/graphyx/tests/Wave.scala
new file mode 100644
index 0000000..d3359c1
--- /dev/null
+++ b/src/main/scala/graphyx/tests/Wave.scala
@@ -0,0 +1,34 @@
+package graphyx.tests
+
+import sims.dynamics._
+import sims.dynamics.joints._
+import sims.dynamics.joints.test._
+import sims.geometry._
+
+object Wave extends Test{
+ val title = "Wave"
+ val world = new World {gravity = Vector2D.Null}
+
+ def init = {
+ val n = 50
+
+ val anchors = for (i <- (0 to n).toList) yield
+ new Body(new Circle(0.01,1) {pos = Vector2D(0.4 * i, 5)}) {fixed = true}
+
+ val particles = for (i <- (0 to n).toList) yield
+ new Body(new Circle(0.1,10) {pos = Vector2D(0.4 * i, 0)})
+
+ val rails = for (i <- (0 to n).toList) yield
+ new PrismaticJoint(anchors(i), particles(i))
+
+ val springs = for (i <- (0 to n).toList) yield
+ new SpringJoint(anchors(i), particles(i), 5)// {damping = 0.00})
+
+ val lateralSprings = for (i <- (0 to (n - 1)).toList) yield
+ new SpringJoint(particles(i), particles(i + 1), 50.0)
+
+ world ++= anchors
+ world ++= particles
+ for (j <- rails ++ springs ++ lateralSprings) world += j
+ }
+}