blob: d1aa1ae6541849c9d963eabc9195d469ea488b2e (
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
/* _____ _ __ ________ ___ *\
** / ___/(_) |/ / ___/ |__ \ Simple Mechanics Simulator 2 **
** \__ \/ / /|_/ /\__ \ __/ / copyright (c) 2011 Jakob Odersky **
** ___/ / / / / /___/ / / __/ **
** /____/_/_/ /_//____/ /____/ **
\* */
package sims.dynamics
import sims.collision._
import sims.math._
/**
* @define shape shape */
trait Shape extends AnyRef with Collidable with CachedCollidable {
override def equals(that: Any) = super.equals(that)
override def hashCode = super.hashCode
/** (temporary solution) Local position of $shape to body.
* @deprecated find solution avoiding NullPointers
* @todo find solution avoiding NullPointers */
var local: Option[Vector2D] = None
var body: sims.dynamics.Body = null
override def fixed = body.fixed
var restitution = 1.0
/**Position of this $shape's center of mass in world coordinates.*/
private var _position: Vector2D = Vector2D.Null
def position = _position
def position_=(pos: Vector2D) = {
_position = pos
move()
}
/**Rotation of this shape about its center of mass.*/
var rotation: Double = 0.0
/** Mass per area. */
def density: Double = 1.0
/** Area of this $shape. */
def area: Double
/** Mass of this $shape. The mass is given by volume times density. */
def mass: Double = area * density
/**Moment of inertia for a rotation about this $shape's center of mass.*/
def inertia: Double
/**Returns this $shape's axis aligned bounding box.*/
def aabb: sims.collision.AABB
/**Returns the projection of this $shape onto the line given by the directional vector <code>axis</code>.
* @param axis directional vector of the line
* @return projection of this shape*/
def project(axis: Vector2D): Projection
/**Checks if the point <code>point</code> is contained in this $shape.*/
def contains(point: Vector2D): Boolean
def asBody = new sims.dynamics.Body(this)
}
|