summaryrefslogtreecommitdiff
path: root/src/graphyx/tests
diff options
context:
space:
mode:
Diffstat (limited to 'src/graphyx/tests')
-rw-r--r--src/graphyx/tests/Atom.scala1
-rw-r--r--src/graphyx/tests/Cannon.scala59
-rw-r--r--src/graphyx/tests/EmptyTest.scala1
-rw-r--r--src/graphyx/tests/Friction.scala1
-rw-r--r--src/graphyx/tests/Friction2.scala4
-rw-r--r--src/graphyx/tests/General1.scala1
-rw-r--r--src/graphyx/tests/Spring.scala17
-rw-r--r--src/graphyx/tests/Test.scala1
-rw-r--r--src/graphyx/tests/Wave.scala27
9 files changed, 87 insertions, 25 deletions
diff --git a/src/graphyx/tests/Atom.scala b/src/graphyx/tests/Atom.scala
index 84fe05c..31d03fc 100644
--- a/src/graphyx/tests/Atom.scala
+++ b/src/graphyx/tests/Atom.scala
@@ -22,6 +22,7 @@ object Atom extends Test{
connections = Nil
}
+ enableEvent = true
override def fireEvent = {
val e = (new Circle(0.1, 10) {pos = Vector2D(0, -1)}).asBody
e.linearVelocity = Vector2D(-50,100)
diff --git a/src/graphyx/tests/Cannon.scala b/src/graphyx/tests/Cannon.scala
new file mode 100644
index 0000000..7738103
--- /dev/null
+++ b/src/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 ++= List.flatten(stack)
+
+ }
+
+ 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/graphyx/tests/EmptyTest.scala b/src/graphyx/tests/EmptyTest.scala
index 585a053..0e3bd84 100644
--- a/src/graphyx/tests/EmptyTest.scala
+++ b/src/graphyx/tests/EmptyTest.scala
@@ -7,6 +7,7 @@
package graphyx.tests
import sims.dynamics._
+import sims.geometry._
object EmptyTest extends Test{
override val title = "Empty Test"
val world = new World
diff --git a/src/graphyx/tests/Friction.scala b/src/graphyx/tests/Friction.scala
index 268d054..ba9fb69 100644
--- a/src/graphyx/tests/Friction.scala
+++ b/src/graphyx/tests/Friction.scala
@@ -47,6 +47,7 @@ object Friction extends Test{
world += r3
}
+ enableEvent = true
override def fireEvent = {
world -= r1
world -= r2
diff --git a/src/graphyx/tests/Friction2.scala b/src/graphyx/tests/Friction2.scala
index f6731e2..9d03bd9 100644
--- a/src/graphyx/tests/Friction2.scala
+++ b/src/graphyx/tests/Friction2.scala
@@ -20,10 +20,10 @@ object Friction2 extends Test{
friction = (i * 1.0 / 10)
restitution = 0
})
- val ground = new Body(shapes: _*) //Rectangle(100, 0.1, 1).asBody
+ val ground = new Body(shapes: _*)
ground.pos = Vector2D(0,0)
ground.fixed = true
- ground.rotation = -0.2
+ 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)})
diff --git a/src/graphyx/tests/General1.scala b/src/graphyx/tests/General1.scala
index 7d8703b..71e041b 100644
--- a/src/graphyx/tests/General1.scala
+++ b/src/graphyx/tests/General1.scala
@@ -106,6 +106,7 @@ object General1 extends Test{
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() = {
diff --git a/src/graphyx/tests/Spring.scala b/src/graphyx/tests/Spring.scala
index 439259f..e7fecb8 100644
--- a/src/graphyx/tests/Spring.scala
+++ b/src/graphyx/tests/Spring.scala
@@ -7,23 +7,14 @@ import java.io._
object Spring extends Test{
val title = "Spring"
- //val fout = new java.io.FileOutputStream("out.csv")
- //val sout = new java.io.PrintStream(fout)
- val world = new World {
- override def postStep = {
- //for (b <- bodies; if (b.monitor)) sout.println(monitors(0)._2(b))
- }
- }
+ val world = new World
def init = {
val anchor = Circle(0.05, 10).asBody
anchor.fixed = true
- val particle = (new Circle(0.1, 10) {pos = Vector2D(0, -1)}).asBody
- val spring = new SpringJoint(anchor, particle, 500, 0.6)
- //val spring = new PrismaticJoint(anchor, particle)
- spring.damping = 1
- particle.monitor = true
- world.monitors += ("", _.pos.y.toString)
+ 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
diff --git a/src/graphyx/tests/Test.scala b/src/graphyx/tests/Test.scala
index b539283..ca0f8e8 100644
--- a/src/graphyx/tests/Test.scala
+++ b/src/graphyx/tests/Test.scala
@@ -11,6 +11,7 @@ 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/graphyx/tests/Wave.scala b/src/graphyx/tests/Wave.scala
index 62ec194..d3359c1 100644
--- a/src/graphyx/tests/Wave.scala
+++ b/src/graphyx/tests/Wave.scala
@@ -11,17 +11,24 @@ object Wave extends Test{
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}))
- world ++= anchors
- world ++= particles
- for (j <- rails ++ springs) world += j
- val lateralSprings = (for (i <- (0 to (n - 1)).toList) yield (new SpringJoint(particles(i), particles(i + 1), 50.0)))
- for (j <- lateralSprings) world += j
+ 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
}
-
}