blob: d3522a4eba7aba1d56e940d838780c3dd2180474 (
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
|
/* _____ _ __ ________ ___ *\
** / ___/(_) |/ / ___/ |__ \ Simple Mechanics Simulator 2 **
** \__ \/ / /|_/ /\__ \ __/ / copyright (c) 2011 Jakob Odersky **
** ___/ / / / / /___/ / / __/ **
** /____/_/_/ /_//____/ /____/ **
\* */
package sims.collision
/** Implements features of a collidable object to be evaluated lazily and only
* to be be recomputed when the collidable object moves. */
trait CachedCollidable extends Collidable {
/** Invalidates all features and forces their evaluation on next call.
* Should be called by clients when this object moves. */
def move() = {
_aabbValid = false
}
private var _aabb: AABB = null
private var _aabbValid = false
abstract override def aabb = {
if (! _aabbValid) {
_aabb = super.aabb
_aabbValid = true
}
_aabb
}
}
|