Skip to content

Commit

Permalink
Merge pull request #655 from teyrana/show-cp-y
Browse files Browse the repository at this point in the history
[fix] 2D Rocket Figure will now display off-axis CoM and CoP
  • Loading branch information
teyrana committed May 8, 2020
2 parents 90173c3 + ac6ae0b commit deed818
Showing 1 changed file with 23 additions and 16 deletions.
39 changes: 23 additions & 16 deletions swing/src/net/sf/openrocket/gui/scalefigure/RocketPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
import javax.swing.JSlider;
import javax.swing.JViewport;
import javax.swing.SwingUtilities;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import javax.swing.event.TreeSelectionEvent;
import javax.swing.event.TreeSelectionListener;
import javax.swing.tree.TreePath;
Expand Down Expand Up @@ -121,6 +123,7 @@ public String toString() {
private TreeSelectionModel selectionModel = null;

private BasicSlider rotationSlider;
private DoubleModel rotationModel;
private ScaleSelector scaleSelector;

/* Calculation of CP and CG */
Expand Down Expand Up @@ -323,9 +326,8 @@ public void setSelectedItem(Object o) {
add(configComboBox, "wrap, width 16%, wmin 100");

// Create slider and scroll pane
DoubleModel theta = new DoubleModel(figure, "Rotation",
UnitGroup.UNITS_ANGLE, 0, 2 * Math.PI);
UnitSelector us = new UnitSelector(theta, true);
rotationModel = new DoubleModel(figure, "Rotation", UnitGroup.UNITS_ANGLE, 0, 2 * Math.PI);
UnitSelector us = new UnitSelector(rotationModel, true);
us.setHorizontalAlignment(JLabel.CENTER);
add(us, "alignx 50%, growx");

Expand All @@ -337,8 +339,14 @@ public void setSelectedItem(Object o) {
JLabel l = new JLabel("360" + Chars.DEGREE);
Dimension d = l.getPreferredSize();

add(rotationSlider = new BasicSlider(theta.getSliderModel(0, 2 * Math.PI), JSlider.VERTICAL, true),
add(rotationSlider = new BasicSlider(rotationModel.getSliderModel(0, 2 * Math.PI), JSlider.VERTICAL, true),
"ax 50%, wrap, width " + (d.width + 6) + "px:null:null, growy");
rotationSlider.addChangeListener(new ChangeListener() {
@Override
public void stateChanged(ChangeEvent e) {
updateExtras();
}
});

//// <html>Click to select &nbsp;&nbsp; Shift+click to select other &nbsp;&nbsp; Double-click to edit &nbsp;&nbsp; Click+drag to move
infoMessage = new JLabel(trans.get("RocketPanel.lbl.infoMessage"));
Expand Down Expand Up @@ -554,7 +562,11 @@ private void handleComponentClick(RocketComponent[] clicked, MouseEvent event) {

private void updateExtras() {
Coordinate cp, cg;
double cpx, cgx;
double cgx = Double.NaN;
double cgy = Double.NaN;
double cpx = Double.NaN;
double cpy = Double.NaN;
final double rotation = rotationModel.getValue();

FlightConfiguration curConfig = document.getSelectedConfiguration();
// TODO: MEDIUM: User-definable conditions
Expand Down Expand Up @@ -594,14 +606,14 @@ private void updateExtras() {

if (cp.weight > MathUtil.EPSILON){
cpx = cp.x;
}else{
cpx = Double.NaN;
// map the 3D value into the 2D Display Panel
cpy = cp.y * Math.cos(rotation) + cp.z*Math.sin(rotation);
}

if (cg.weight > MassCalculator.MIN_MASS){
cgx = cg.x;
}else{
cgx = Double.NaN;
// map the 3D value into the 2D Display Panel
cgy = cg.y * Math.cos(rotation) + cg.z*Math.sin(rotation);
}

figure3d.setCG(cg);
Expand Down Expand Up @@ -629,16 +641,11 @@ private void updateExtras() {
extraText.setWarnings(warnings);

if (figure.getType() == RocketPanel.VIEW_TYPE.SideView && length > 0) {

// TODO: LOW: Y-coordinate and rotation
extraCP.setPosition(cpx, 0);
extraCG.setPosition(cgx, 0);

extraCP.setPosition(cpx, cpy);
extraCG.setPosition(cgx, cgy);
} else {

extraCP.setPosition(Double.NaN, Double.NaN);
extraCG.setPosition(Double.NaN, Double.NaN);

}

//////// Flight simulation in background
Expand Down

0 comments on commit deed818

Please sign in to comment.