Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fix] 2D Rocket Figure will now display off-axis CoM and CoP #655

Merged
merged 2 commits into from
May 8, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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