[refactor] RocketFigure3D converted to use 'util.BoundingBox'
This commit is contained in:
parent
56c60a0013
commit
257e635937
@ -51,6 +51,7 @@ import net.sf.openrocket.startup.Application;
|
|||||||
import net.sf.openrocket.startup.Preferences;
|
import net.sf.openrocket.startup.Preferences;
|
||||||
import net.sf.openrocket.util.Coordinate;
|
import net.sf.openrocket.util.Coordinate;
|
||||||
import net.sf.openrocket.util.MathUtil;
|
import net.sf.openrocket.util.MathUtil;
|
||||||
|
import net.sf.openrocket.util.BoundingBox;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* @author Bill Kuker <bkuker@billkuker.com>
|
* @author Bill Kuker <bkuker@billkuker.com>
|
||||||
@ -468,47 +469,19 @@ public class RocketFigure3d extends JPanel implements GLEventListener {
|
|||||||
redrawExtras = true;
|
redrawExtras = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
private BoundingBox cachedBounds = null;
|
||||||
private static class Bounds {
|
|
||||||
double xMin, xMax, xSize;
|
|
||||||
double yMin, yMax, ySize;
|
|
||||||
double zMin, zMax, zSize;
|
|
||||||
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 BoundingBox calculateBounds() {
|
||||||
if (cachedBounds != null) {
|
if (cachedBounds == null) {
|
||||||
return cachedBounds;
|
|
||||||
} else {
|
|
||||||
final Bounds b = new Bounds();
|
|
||||||
final FlightConfiguration configuration = rkt.getSelectedConfiguration();
|
final FlightConfiguration configuration = rkt.getSelectedConfiguration();
|
||||||
final Collection<Coordinate> bounds = configuration.getBounds();
|
cachedBounds = configuration.getBoundingBox();
|
||||||
for (Coordinate c : bounds) {
|
|
||||||
b.xMax = Math.max(b.xMax, c.x);
|
|
||||||
b.xMin = Math.min(b.xMin, c.x);
|
|
||||||
|
|
||||||
b.yMax = Math.max(b.yMax, c.y);
|
|
||||||
b.yMin = Math.min(b.yMin, c.y);
|
|
||||||
|
|
||||||
b.zMax = Math.max(b.zMax, c.z);
|
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
return cachedBounds;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setupView(final GL2 gl, final GLU glu) {
|
private void setupView(final GL2 gl, final GLU glu) {
|
||||||
@ -516,16 +489,16 @@ public class RocketFigure3d extends JPanel implements GLEventListener {
|
|||||||
|
|
||||||
gl.glLightfv(GLLightingFunc.GL_LIGHT1, GLLightingFunc.GL_POSITION,
|
gl.glLightfv(GLLightingFunc.GL_LIGHT1, GLLightingFunc.GL_POSITION,
|
||||||
lightPosition, 0);
|
lightPosition, 0);
|
||||||
|
|
||||||
// Get the bounds
|
// Get the bounds
|
||||||
final Bounds b = calculateBounds();
|
final BoundingBox b = calculateBounds();
|
||||||
|
|
||||||
// Calculate the distance needed to fit the bounds in both the X and Y
|
// Calculate the distance needed to fit the bounds in both the X and Y
|
||||||
// direction
|
// direction
|
||||||
// Add 10% for space around it.
|
// Add 10% for space around it.
|
||||||
final double dX = (b.xSize * 1.2 / 2.0)
|
final double dX = (b.span().x * 1.2 / 2.0)
|
||||||
/ Math.tan(Math.toRadians(fovX / 2.0));
|
/ Math.tan(Math.toRadians(fovX / 2.0));
|
||||||
final double dY = (b.rMax * 2.0 * 1.2 / 2.0)
|
final double dY = (b.span().y * 2.0 * 1.2 / 2.0)
|
||||||
/ Math.tan(Math.toRadians(fovY / 2.0));
|
/ Math.tan(Math.toRadians(fovY / 2.0));
|
||||||
|
|
||||||
// Move back the greater of the 2 distances
|
// Move back the greater of the 2 distances
|
||||||
@ -535,7 +508,7 @@ public class RocketFigure3d extends JPanel implements GLEventListener {
|
|||||||
gl.glRotated(roll * (180.0 / Math.PI), 1, 0, 0);
|
gl.glRotated(roll * (180.0 / Math.PI), 1, 0, 0);
|
||||||
|
|
||||||
// Center the rocket in the view.
|
// Center the rocket in the view.
|
||||||
gl.glTranslated(-b.xMin - b.xSize / 2.0, 0, 0);
|
gl.glTranslated(-b.min.x - b.span().x / 2.0, 0, 0);
|
||||||
|
|
||||||
//Change to LEFT Handed coordinates
|
//Change to LEFT Handed coordinates
|
||||||
gl.glScaled(1, 1, -1);
|
gl.glScaled(1, 1, -1);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user