[fix] re-implements RocketRenderer-tree-code
This commit is contained in:
parent
efabe81790
commit
0711cb785b
@ -4,6 +4,7 @@ import java.awt.Point;
|
|||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.Vector;
|
import java.util.Vector;
|
||||||
|
|
||||||
@ -23,6 +24,8 @@ import net.sf.openrocket.gui.figure3d.geometry.Geometry.Surface;
|
|||||||
import net.sf.openrocket.motor.Motor;
|
import net.sf.openrocket.motor.Motor;
|
||||||
import net.sf.openrocket.motor.MotorConfiguration;
|
import net.sf.openrocket.motor.MotorConfiguration;
|
||||||
import net.sf.openrocket.rocketcomponent.FlightConfiguration;
|
import net.sf.openrocket.rocketcomponent.FlightConfiguration;
|
||||||
|
import net.sf.openrocket.rocketcomponent.InstanceContext;
|
||||||
|
import net.sf.openrocket.rocketcomponent.InstanceMap;
|
||||||
import net.sf.openrocket.rocketcomponent.MotorMount;
|
import net.sf.openrocket.rocketcomponent.MotorMount;
|
||||||
import net.sf.openrocket.rocketcomponent.RocketComponent;
|
import net.sf.openrocket.rocketcomponent.RocketComponent;
|
||||||
import net.sf.openrocket.util.Coordinate;
|
import net.sf.openrocket.util.Coordinate;
|
||||||
@ -159,39 +162,29 @@ public abstract class RocketRenderer {
|
|||||||
|
|
||||||
private Collection<Geometry> getTreeGeometry( FlightConfiguration config){
|
private Collection<Geometry> getTreeGeometry( FlightConfiguration config){
|
||||||
System.err.println(String.format("==== Building tree geometry ===="));
|
System.err.println(String.format("==== Building tree geometry ===="));
|
||||||
return getTreeGeometry("", new ArrayList<Geometry>(), config, config.getRocket(), Transformation.IDENTITY);
|
|
||||||
}
|
|
||||||
|
|
||||||
private Collection<Geometry> getTreeGeometry(String indent, Collection<Geometry> treeGeometry, FlightConfiguration config, RocketComponent comp, final Transformation parentTransform){
|
// input
|
||||||
final int instanceCount = comp.getInstanceCount();
|
final InstanceMap imap = config.getActiveInstances();
|
||||||
double[] instanceAngles = comp.getInstanceAngles();
|
|
||||||
Coordinate[] instanceLocations = comp.getInstanceLocations();
|
|
||||||
|
|
||||||
if( instanceLocations.length != instanceAngles.length ){
|
// output buffer
|
||||||
throw new ArrayIndexOutOfBoundsException(String.format("lengths of location array (%d) and angle arrays (%d) differs! (in: %s) ", instanceLocations.length, instanceAngles.length, comp.getName()));
|
final Collection<Geometry> treeGeometry = new ArrayList<Geometry>();
|
||||||
}
|
|
||||||
|
|
||||||
// iterate over the aggregated instances for the whole tree.
|
for(Map.Entry<RocketComponent, ArrayList<InstanceContext>> entry: imap.entrySet() ) {
|
||||||
for( int instanceNumber = 0; instanceNumber < instanceCount; ++instanceNumber) {
|
final RocketComponent comp = entry.getKey();
|
||||||
Coordinate currentLocation = instanceLocations[instanceNumber];
|
|
||||||
final double currentAngle = instanceAngles[instanceNumber];
|
final ArrayList<InstanceContext> contextList = entry.getValue();
|
||||||
|
System.err.println(String.format("....[%s]", comp.getName()));
|
||||||
|
|
||||||
|
for(InstanceContext context: contextList ) {
|
||||||
|
System.err.println(String.format("........[% 2d] %s", context.instanceNumber, context.getLocation().toPreciseString()));
|
||||||
|
|
||||||
// System.err.println( String.format("%s[ %s ]", indent, comp.getName()));
|
// System.err.println( String.format("%s[ %s ]", indent, comp.getName()));
|
||||||
// System.err.println( String.format("%s :: %12.8g / %12.8g / %12.8g (m) @ %8.4g (rads) ", indent, currentLocation.x, currentLocation.y, currentLocation.z, currentAngle ));
|
// System.err.println( String.format("%s :: %12.8g / %12.8g / %12.8g (m) @ %8.4g (rads) ", indent, currentLocation.x, currentLocation.y, currentLocation.z, currentAngle ));
|
||||||
|
|
||||||
Transformation currentTransform = parentTransform
|
Geometry instanceGeometry = cr.getComponentGeometry( comp, context.transform );
|
||||||
.applyTransformation( Transformation.getTranslationTransform( currentLocation))
|
instanceGeometry.active = context.active;
|
||||||
.applyTransformation( Transformation.rotate_x( currentAngle ));
|
treeGeometry.add( instanceGeometry );
|
||||||
|
|
||||||
|
|
||||||
// recurse into inactive trees: allow active stages inside inactive stages
|
|
||||||
for(RocketComponent child: comp.getChildren()) {
|
|
||||||
getTreeGeometry(indent+" ", treeGeometry, config, child, currentTransform );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Geometry geom = cr.getComponentGeometry( comp, currentTransform );
|
|
||||||
geom.active = config.isComponentActive( comp );
|
|
||||||
treeGeometry.add( geom );
|
|
||||||
}
|
}
|
||||||
return treeGeometry;
|
return treeGeometry;
|
||||||
}
|
}
|
||||||
|
@ -620,7 +620,7 @@ public class RocketPanel extends JPanel implements TreeSelectionListener, Change
|
|||||||
length = maxX - minX;
|
length = maxX - minX;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (RocketComponent c : curConfig.getActiveComponents()) {
|
for (RocketComponent c : curConfig.getAllComponents()) {
|
||||||
if (c instanceof SymmetricComponent) {
|
if (c instanceof SymmetricComponent) {
|
||||||
double d1 = ((SymmetricComponent) c).getForeRadius() * 2;
|
double d1 = ((SymmetricComponent) c).getForeRadius() * 2;
|
||||||
double d2 = ((SymmetricComponent) c).getAftRadius() * 2;
|
double d2 = ((SymmetricComponent) c).getAftRadius() * 2;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user