blob: 9468d16ad8002d45dd60aec36867ed8440b9a6a6 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
/*
* Graphyx
* copyright (c) 2009 Jakob Odersky
* made available under the MIT License
*/
package graphyx.graphics
import sims.collision._
import sims.dynamics._
import sims.dynamics.joints._
object Parser {
val throwOnUnknown = false
def toGraphical(real: Shape) = real match {
case c: Circle => GraphicalCircle(c)
case r: Rectangle => GraphicalRectangle(r)
case p: RegularPolygon => GraphicalRegularPolygon(p)
case _ => throw new IllegalArgumentException("Cannot cast '" + real.getClass + "' to a graphical object.")
}
def toGraphical(real: Joint) = real match {
case j: DistanceJoint => GraphicalDistanceJoint(j)
case j: SpringJoint => GraphicalSpringJoint(j)
case j: RevoluteJoint => GraphicalRevoluteJoint(j)
case j: Joint => if (!throwOnUnknown) new GraphicalJoint{override val real = j; def draw = ()}
else throw new IllegalArgumentException("Cannot cast '" + real.getClass + "' to a graphical object.")
}
def toGraphical(real: Collision) = GraphicalCollision(real)
def toGraphical(real: Pair) = GraphicalPair(real)
def toGraphical(real: AABB) = GraphicalAABB(real)
def toGraphical(real: Body) = GraphicalBody(real)
}
|