diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/graphyx/Graphyx.scala | 1 | ||||
-rw-r--r-- | src/graphyx/tests/Carriage.scala | 55 | ||||
-rw-r--r-- | src/graphyx/tests/EmptyTest.scala | 1 | ||||
-rw-r--r-- | src/sims/collision/Collision.scala | 1 |
4 files changed, 56 insertions, 2 deletions
diff --git a/src/graphyx/Graphyx.scala b/src/graphyx/Graphyx.scala index cfd67c6..81a8ee8 100644 --- a/src/graphyx/Graphyx.scala +++ b/src/graphyx/Graphyx.scala @@ -27,6 +27,7 @@ object Graphyx{ Friction2, Restitution, RagdollTest, + Carriage, General1, General2, EmptyTest diff --git a/src/graphyx/tests/Carriage.scala b/src/graphyx/tests/Carriage.scala new file mode 100644 index 0000000..967c6e5 --- /dev/null +++ b/src/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/graphyx/tests/EmptyTest.scala b/src/graphyx/tests/EmptyTest.scala index bbca800..585a053 100644 --- a/src/graphyx/tests/EmptyTest.scala +++ b/src/graphyx/tests/EmptyTest.scala @@ -11,5 +11,4 @@ object EmptyTest extends Test{ override val title = "Empty Test" val world = new World def init = {} - } diff --git a/src/sims/collision/Collision.scala b/src/sims/collision/Collision.scala index ad23f4d..d674b30 100644 --- a/src/sims/collision/Collision.scala +++ b/src/sims/collision/Collision.scala @@ -69,7 +69,6 @@ abstract class Collision extends Constraint { val cr2 = r2 cross tangent val invMass = 1/b1.mass * (tangent dot tangent) + 1/b1.I * cr1 * cr1 + 1/b2.mass * (tangent dot tangent) + 1/b2.I * cr2 * cr2 val m = if (invMass == 0.0) 0.0 else 1/invMass - val mu = shape1.friction * shape2.friction val lambda = -m * Cdot val cf = shape1.friction * shape2.friction val cl = Math.min(Math.max(-normalForce * cf * h, lambda), normalForce * cf * h) |