[fix] MassCalculator now accounts for rotation in Component Assembly Instance Trees
This commit is contained in:
parent
91652e7e4f
commit
cce900d408
@ -266,19 +266,26 @@ public class MassCalculation {
|
|||||||
final RocketComponent component = this.root;
|
final RocketComponent component = this.root;
|
||||||
final Transformation parentTransform = this.transform;
|
final Transformation parentTransform = this.transform;
|
||||||
final int instanceCount = component.getInstanceCount();
|
final int instanceCount = component.getInstanceCount();
|
||||||
Coordinate[] instanceLocations = component.getInstanceLocations();
|
final Coordinate[] allInstanceOffsets = component.getInstanceLocations();
|
||||||
|
final double[] allInstanceAngles = component.getInstanceAngles();
|
||||||
// // vvv DEBUG
|
|
||||||
// if( this.config.isComponentActive(component) ){
|
// // vvv DEBUG
|
||||||
// System.err.println(String.format( "%s[%s]....", prefix, component.getName()));
|
// if( this.config.isComponentActive(component) ){
|
||||||
// }
|
// System.err.println(String.format( "%s>>[%s]....", prefix, component.getName()));
|
||||||
|
// }
|
||||||
|
|
||||||
// iterate over the aggregated instances for the whole tree.
|
// iterate over the aggregated instances for the whole tree.
|
||||||
MassCalculation children = this.copy(component, parentTransform );
|
MassCalculation children = this.copy(component, parentTransform );
|
||||||
for( int instanceNumber = 0; instanceNumber < instanceCount; ++instanceNumber) {
|
for( int currentInstanceNumber = 0; currentInstanceNumber < instanceCount; ++currentInstanceNumber) {
|
||||||
Coordinate currentLocation = instanceLocations[instanceNumber];
|
final Coordinate currentInstanceOffset = allInstanceOffsets[currentInstanceNumber];
|
||||||
Transformation currentTransform = parentTransform.applyTransformation( Transformation.getTranslationTransform( currentLocation ));
|
final Transformation offsetTransform = Transformation.getTranslationTransform( currentInstanceOffset );
|
||||||
|
|
||||||
|
final double currentInstanceAngle = allInstanceAngles[currentInstanceNumber];
|
||||||
|
final Transformation angleTransform = Transformation.getAxialRotation(currentInstanceAngle);
|
||||||
|
|
||||||
|
final Transformation currentTransform = parentTransform.applyTransformation(offsetTransform)
|
||||||
|
.applyTransformation(angleTransform);
|
||||||
|
|
||||||
for (RocketComponent child : component.getChildren()) {
|
for (RocketComponent child : component.getChildren()) {
|
||||||
// child data, relative to rocket reference frame
|
// child data, relative to rocket reference frame
|
||||||
MassCalculation eachChild = copy( child, currentTransform);
|
MassCalculation eachChild = copy( child, currentTransform);
|
||||||
@ -293,8 +300,8 @@ public class MassCalculation {
|
|||||||
|
|
||||||
if( 0 < children.getMass() ) {
|
if( 0 < children.getMass() ) {
|
||||||
this.merge( children );
|
this.merge( children );
|
||||||
// // vvv DEBUG
|
// // vvv DEBUG
|
||||||
// System.err.println(String.format( "%s....assembly mass (incl/children): %s", prefix, this.toCMDebug()));
|
// System.err.println(String.format( "%s....assembly mass (incl/children): %s", prefix, this.toCMDebug()));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.config.isComponentActive(component) ){
|
if (this.config.isComponentActive(component) ){
|
||||||
@ -302,8 +309,9 @@ public class MassCalculation {
|
|||||||
|
|
||||||
if (!component.getOverrideSubcomponents()) {
|
if (!component.getOverrideSubcomponents()) {
|
||||||
if (component.isMassOverridden()) {
|
if (component.isMassOverridden()) {
|
||||||
// System.err.println("mass override=" + component.getOverrideMass());
|
|
||||||
compCM = compCM.setWeight(MathUtil.max(component.getOverrideMass(), MIN_MASS));
|
compCM = compCM.setWeight(MathUtil.max(component.getOverrideMass(), MIN_MASS));
|
||||||
|
// // vvv DEBUG
|
||||||
|
// System.err.println(String.format( "%s....mass overridden to: %s", prefix, compCM.toPreciseString()));
|
||||||
}
|
}
|
||||||
if (component.isCGOverridden())
|
if (component.isCGOverridden())
|
||||||
compCM = compCM.setXYZ(component.getOverrideCG());
|
compCM = compCM.setXYZ(component.getOverrideCG());
|
||||||
@ -318,10 +326,10 @@ public class MassCalculation {
|
|||||||
RigidBody componentInertia = new RigidBody( compCM, compIx, compIt, compIt );
|
RigidBody componentInertia = new RigidBody( compCM, compIx, compIt, compIt );
|
||||||
|
|
||||||
this.addInertia( componentInertia );
|
this.addInertia( componentInertia );
|
||||||
// vvv DEBUG
|
// // vvv DEBUG
|
||||||
// if( 0 < compCM.weight ) {
|
// if( 0 < compCM.weight ) {
|
||||||
// System.err.println(String.format( "%s....componentData: %s", prefix, compCM.toPreciseString() ));
|
// System.err.println(String.format( "%s....componentData: %s", prefix, compCM.toPreciseString() ));
|
||||||
// }
|
// }
|
||||||
|
|
||||||
if (component.getOverrideSubcomponents()) {
|
if (component.getOverrideSubcomponents()) {
|
||||||
if (component.isMassOverridden()) {
|
if (component.isMassOverridden()) {
|
||||||
@ -337,11 +345,11 @@ public class MassCalculation {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// // vvv DEBUG
|
// // vvv DEBUG
|
||||||
// if( this.config.isComponentActive(component) && 0 < this.getMass() ) {
|
// if( this.config.isComponentActive(component) && 0 < this.getMass() ) {
|
||||||
// System.err.println(String.format( "%s....<< return assemblyData: %s (tree @%s)", prefix, this.toCMDebug(), component.getName() ));
|
// System.err.println(String.format( "%s....<< return data @ %s: %s", prefix, component.getName(), this.toCMDebug() ));
|
||||||
// }
|
// }
|
||||||
// // ^^^ DEBUG
|
// // ^^^ DEBUG
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user