Cache model bounds for performance
This commit is contained in:
parent
d1d6e3c2a3
commit
74783afe3f
@ -423,31 +423,37 @@ public class RocketFigure3d extends JPanel implements GLEventListener {
|
|||||||
double rMax;
|
double rMax;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Bounds cachedBounds = null;
|
||||||
/**
|
/**
|
||||||
* Calculates the bounds for the current configuration
|
* Calculates the bounds for the current configuration
|
||||||
*
|
*
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
private Bounds calculateBounds() {
|
private Bounds calculateBounds() {
|
||||||
Bounds ret = new Bounds();
|
if ( cachedBounds != null ){
|
||||||
Collection<Coordinate> bounds = configuration.getBounds();
|
return cachedBounds;
|
||||||
for (Coordinate c : bounds) {
|
} else {
|
||||||
ret.xMax = Math.max(ret.xMax, c.x);
|
Bounds b = new Bounds();
|
||||||
ret.xMin = Math.min(ret.xMin, c.x);
|
Collection<Coordinate> bounds = configuration.getBounds();
|
||||||
|
for (Coordinate c : bounds) {
|
||||||
ret.yMax = Math.max(ret.yMax, c.y);
|
b.xMax = Math.max(b.xMax, c.x);
|
||||||
ret.yMin = Math.min(ret.yMin, c.y);
|
b.xMin = Math.min(b.xMin, c.x);
|
||||||
|
|
||||||
ret.zMax = Math.max(ret.zMax, c.z);
|
b.yMax = Math.max(b.yMax, c.y);
|
||||||
ret.zMin = Math.min(ret.zMin, c.z);
|
b.yMin = Math.min(b.yMin, c.y);
|
||||||
|
|
||||||
double r = MathUtil.hypot(c.y, c.z);
|
b.zMax = Math.max(b.zMax, c.z);
|
||||||
ret.rMax = Math.max(ret.rMax, r);
|
b.zMin = Math.min(b.zMin, c.z);
|
||||||
|
|
||||||
|
double r = MathUtil.hypot(c.y, c.z);
|
||||||
|
b.rMax = Math.max(b.rMax, r);
|
||||||
|
}
|
||||||
|
b.xSize = b.xMax - b.xMin;
|
||||||
|
b.ySize = b.yMax - b.yMin;
|
||||||
|
b.zSize = b.zMax - b.zMin;
|
||||||
|
cachedBounds = b;
|
||||||
|
return b;
|
||||||
}
|
}
|
||||||
ret.xSize = ret.xMax - ret.xMin;
|
|
||||||
ret.ySize = ret.yMax - ret.yMin;
|
|
||||||
ret.zSize = ret.zMax - ret.zMin;
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setupView(GL2 gl, GLU glu) {
|
private void setupView(GL2 gl, GLU glu) {
|
||||||
@ -496,6 +502,7 @@ public class RocketFigure3d extends JPanel implements GLEventListener {
|
|||||||
*/
|
*/
|
||||||
public void updateFigure() {
|
public void updateFigure() {
|
||||||
log.debug("3D Figure Updated");
|
log.debug("3D Figure Updated");
|
||||||
|
cachedBounds = null;
|
||||||
rr.updateFigure();
|
rr.updateFigure();
|
||||||
internalRepaint();
|
internalRepaint();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user