diff options
Diffstat (limited to 'src/graphyx/tests')
-rw-r--r-- | src/graphyx/tests/BallStack.scala | 25 | ||||
-rw-r--r-- | src/graphyx/tests/Chain.scala | 26 | ||||
-rw-r--r-- | src/graphyx/tests/CompositeShape.scala | 36 | ||||
-rw-r--r-- | src/graphyx/tests/Cup.scala | 31 | ||||
-rw-r--r-- | src/graphyx/tests/EmptyTest.scala | 15 | ||||
-rw-r--r-- | src/graphyx/tests/Friction.scala | 56 | ||||
-rw-r--r-- | src/graphyx/tests/Friction2.scala | 33 | ||||
-rw-r--r-- | src/graphyx/tests/General1.scala | 125 | ||||
-rw-r--r-- | src/graphyx/tests/General2.scala | 28 | ||||
-rw-r--r-- | src/graphyx/tests/Joints1.scala | 24 | ||||
-rw-r--r-- | src/graphyx/tests/Joints2.scala | 29 | ||||
-rw-r--r-- | src/graphyx/tests/Net.scala | 22 | ||||
-rw-r--r-- | src/graphyx/tests/RagdollTest.scala | 26 | ||||
-rw-r--r-- | src/graphyx/tests/Restitution.scala | 21 | ||||
-rw-r--r-- | src/graphyx/tests/Stacking.scala | 24 | ||||
-rw-r--r-- | src/graphyx/tests/Test.scala | 16 |
16 files changed, 537 insertions, 0 deletions
diff --git a/src/graphyx/tests/BallStack.scala b/src/graphyx/tests/BallStack.scala new file mode 100644 index 0000000..8e45611 --- /dev/null +++ b/src/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/graphyx/tests/Chain.scala b/src/graphyx/tests/Chain.scala new file mode 100644 index 0000000..27511ca --- /dev/null +++ b/src/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/graphyx/tests/CompositeShape.scala b/src/graphyx/tests/CompositeShape.scala new file mode 100644 index 0000000..51ffd0b --- /dev/null +++ b/src/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 + } + +} +
\ No newline at end of file diff --git a/src/graphyx/tests/Cup.scala b/src/graphyx/tests/Cup.scala new file mode 100644 index 0000000..598a9be --- /dev/null +++ b/src/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/graphyx/tests/EmptyTest.scala b/src/graphyx/tests/EmptyTest.scala new file mode 100644 index 0000000..bbca800 --- /dev/null +++ b/src/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._ +object EmptyTest extends Test{ + override val title = "Empty Test" + val world = new World + def init = {} + +} diff --git a/src/graphyx/tests/Friction.scala b/src/graphyx/tests/Friction.scala new file mode 100644 index 0000000..268d054 --- /dev/null +++ b/src/graphyx/tests/Friction.scala @@ -0,0 +1,56 @@ +/* + * 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 + } + + override def fireEvent = { + world -= r1 + world -= r2 + world -= r3 + } + +} diff --git a/src/graphyx/tests/Friction2.scala b/src/graphyx/tests/Friction2.scala new file mode 100644 index 0000000..6eb445b --- /dev/null +++ b/src/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: _*) //Rectangle(100, 0.1, 1).asBody + ground.pos = Vector2D(0,0) + ground.fixed = true + ground.rotation = -0.2 + 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 + } +}
\ No newline at end of file diff --git a/src/graphyx/tests/General1.scala b/src/graphyx/tests/General1.scala new file mode 100644 index 0000000..1a71c24 --- /dev/null +++ b/src/graphyx/tests/General1.scala @@ -0,0 +1,125 @@ +/* + * 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 -= 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)}) + } + + 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/graphyx/tests/General2.scala b/src/graphyx/tests/General2.scala new file mode 100644 index 0000000..2006080 --- /dev/null +++ b/src/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/graphyx/tests/Joints1.scala b/src/graphyx/tests/Joints1.scala new file mode 100644 index 0000000..ad143ec --- /dev/null +++ b/src/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/graphyx/tests/Joints2.scala b/src/graphyx/tests/Joints2.scala new file mode 100644 index 0000000..9ff5df3 --- /dev/null +++ b/src/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/graphyx/tests/Net.scala b/src/graphyx/tests/Net.scala new file mode 100644 index 0000000..c340a80 --- /dev/null +++ b/src/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/graphyx/tests/RagdollTest.scala b/src/graphyx/tests/RagdollTest.scala new file mode 100644 index 0000000..63c9ce5 --- /dev/null +++ b/src/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/graphyx/tests/Restitution.scala b/src/graphyx/tests/Restitution.scala new file mode 100644 index 0000000..9501a36 --- /dev/null +++ b/src/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/graphyx/tests/Stacking.scala b/src/graphyx/tests/Stacking.scala new file mode 100644 index 0000000..63734b6 --- /dev/null +++ b/src/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/graphyx/tests/Test.scala b/src/graphyx/tests/Test.scala new file mode 100644 index 0000000..b539283 --- /dev/null +++ b/src/graphyx/tests/Test.scala @@ -0,0 +1,16 @@ +/* + * 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 + def fireEvent(): Unit = println("No custom event method defined.") + override def toString() = title +} |