Skip to content

Commit

Permalink
Polishing TestBed
Browse files Browse the repository at this point in the history
  • Loading branch information
Villane committed Jun 17, 2009
1 parent 15632b4 commit e1b4b68
Show file tree
Hide file tree
Showing 13 changed files with 83 additions and 141 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,20 @@ import org.newdawn.slick.opengl.TextureImpl;
*
*/
class SlickDebugDraw(var g: Graphics, var container: GameContainer) extends DebugDrawHandler {
def hw = container.getWidth / 2
def hh = container.getHeight / 2
// World 0,0 maps to transX, transY on screen
var transX = 270.0f
var transY = 250.0f
var transX = 0f
var transY = 0f
var scaleFactor = 10.0f
var yFlip = -1.0f

override def setCamera(x: Float, y: Float, scale: Float) {
transX = hw + x * scale - 50 // -50 for control panel
transY = hh + yFlip * y * scale
scaleFactor = scale
}

def map(mapMe: Float, fromLow: Float, fromHigh: Float, toLow: Float, toHigh: Float) = {
val interp = (mapMe - fromLow) / (fromHigh - fromLow)
(interp*toHigh + (1.0f-interp)*toLow)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@ package org.villane.box2d.testbed.slick

import vecmath._
import vecmath.Preamble._
import box2d.draw._
import box2d.shapes._
import box2d.collision._
import box2d.dynamics._
import box2d.dynamics.joints._
import box2d.dynamics.contacts.ContactListener
import org.newdawn.slick.AppGameContainer;
import org.newdawn.slick.BasicGame;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.tests.AntiAliasTest;
import box2d.testbed._
import draw._
import shapes._
import collision._
import dynamics._
import dynamics.joints._
import dynamics.contacts.ContactListener
import org.newdawn.slick.AppGameContainer
import org.newdawn.slick.BasicGame
import org.newdawn.slick.GameContainer
import org.newdawn.slick.Graphics
import org.newdawn.slick.SlickException
import org.newdawn.slick.tests.AntiAliasTest
import tests._

import fenggui.FengWrapper
import org.fenggui.event.mouse.MouseButton
Expand Down Expand Up @@ -74,16 +74,26 @@ class SlickTestGame extends BasicGame("Slick/JBox2d Testbed (Scala)") with Testb
container.setTargetFrameRate(targetFrameRate)
container.setShowFPS(false)

tests += new testbed.tests.Bridge(this)
tests += new testbed.tests.CCDTest(this)
tests += new testbed.tests.Chain(this)
tests += new testbed.tests.Circles(this)
tests += new testbed.tests.Domino(this)
tests += new testbed.tests.Overhang(this)
tests += new testbed.tests.Pyramid(this)
tests += new testbed.tests.VaryingFriction(this)
tests += new testbed.tests.VaryingRestitution(this)
tests += new testbed.tests.VerticalStack(this)
tests += SimpleTest(this, "Bridge", scenes.Bridge,
(0, 10), 20)
tests += SimpleTest(this, "Continuous Collision Test", scenes.CCDTest,
(0, 20), 20)
tests += SimpleTest(this, "Chain", scenes.Chain,
(0, 10), 10)
tests += SimpleTest(this, "Circle Stress Test", scenes.Circles,
5)
tests += SimpleTest(this, "Domino Test", scenes.Domino,
(0, 10), 15)
tests += SimpleTest(this, "Overhang", scenes.Overhang,
(0, 10), 15)
tests += SimpleTest(this, "Pyramid Stress Test", scenes.Pyramid,
(0, 10), 15)
tests += SimpleTest(this, "Varying Friction", scenes.VaryingFriction,
(0, 10), 15)
tests += SimpleTest(this, "Varying Restitution", scenes.VaryingRestitution,
(0, 10), 15)
tests += SimpleTest(this, "Vertical Stack", scenes.VerticalStack,
(0, 10), 15)

currentTest = tests(currentTestIndex)
currentTest.initialize
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package org.villane.box2d.testbed.tests

import vecmath._
import scenes._

object SimpleTest {
def apply(parent: TestbedMain,
name: String,
sf: TestbedScene,
offset: Vector2, scale: Float) =
new SimpleTest(parent, name, sf, offset, scale)

def apply(parent: TestbedMain, name: String, sf: TestbedScene, scale: Float) =
new SimpleTest(parent, name, sf, Vector2.Zero, scale)
}

/**
* Simple test without custom instructions or custom key mapping.
* Can be created given a scene.
*/
class SimpleTest(
_parent: TestbedMain,
val name: String,
scene: TestbedScene,
offset: Vector2,
scale: Float
) extends AbstractExample(_parent) {
var firstTime = true

def create() {
if (firstTime) {
setCamera(offset.x, offset.y, scale)
firstTime = false
}

scene.createScene
}

}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ final class DebugDraw(val handler: DebugDrawHandler) {
m_debughandler.drawSegment(s1, s2, color);
}*/
case _: PointingDeviceJoint =>
//Don't draw mouse joint
handler.drawSegment(p1, p2, Colors.Joint)
case _ =>
handler.drawSegment(x1, p1, Colors.Joint)
handler.drawSegment(p1, p2, Colors.Joint)
Expand Down

0 comments on commit e1b4b68

Please sign in to comment.