aboutsummaryrefslogtreecommitdiff
path: root/src/test/scala/sims/test/gui/RichJoint.scala
blob: 2c3d5fd94abdffe9687c8ec5cb5e9211465b2c6c (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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package sims.test.gui

import processing.core.PApplet
import processing.core.PConstants._
import sims.dynamics._

class RichJoint(joint: Joint) {
private implicit def double2Float(x: Double): Float = x.toFloat
	
	def toGraphical(implicit parent: PApplet) = new GraphicalJoint(joint) {
		
		val top = parent
		
		val render = joint match {
			
			case j: DistanceJoint => () => {
				top.pushMatrix()
				top.stroke(0, 0, 0)
				top.fill(0, 0, 0)
				top.line(j.x1.x, j.x1.y, j.x2.x, j.x2.y)
				top.stroke(100, 100, 100)
				top.line(j.body1.position.x, j.body1.position.y, j.x1.x, j.x1.y)
				top.line(j.body2.position.x, j.body2.position.y, j.x2.x, j.x2.y)
				top.popMatrix()
			}
			
			case j: RevoluteJoint => () => {
				top.pushMatrix()
				top.stroke(0, 0, 0)
				top.fill(0, 0, 0)
				top.line(j.x1.x, j.x1.y, j.x2.x, j.x2.y)
				top.stroke(100, 100, 100)
				top.line(j.body1.position.x, j.body1.position.y, j.x1.x, j.x1.y)
				top.line(j.body2.position.x, j.body2.position.y, j.x2.x, j.x2.y)
				top.popMatrix()
			}
			
			case j: MouseJoint => () => ()
			
			case _ => throw new IllegalArgumentException("Cannot create graphical joint: unknown joint.")
		}
	
	}
	
}

object RichJoint {
	
	implicit def jointToRichShape(j: Joint) = new RichJoint(j)
	
}