Fix issues with origin offset

This commit is contained in:
SiboVG 2023-08-23 13:16:25 +02:00
parent 454b81bf8e
commit 855adcab13
3 changed files with 17 additions and 16 deletions

View File

@ -60,9 +60,9 @@ public class CoordTransform {
* Create a new coordinate system converter. * Create a new coordinate system converter.
* @param axialAxis the OBJ axis that corresponds to the OpenRocket axial (x-)axis * @param axialAxis the OBJ axis that corresponds to the OpenRocket axial (x-)axis
* @param forwardAxis the OBJ axis that corresponds to the OpenRocket forward (y-)axis * @param forwardAxis the OBJ axis that corresponds to the OpenRocket forward (y-)axis
* @param origXOffs the x-offset of the origin of the OBJ coordinate system, <b>in the OBJ coordinate system</b> * @param origXOffs the x-offset of the origin of the OBJ coordinate system, <b>in the OpenRocket coordinate system</b>
* @param origYOffs the y-offset of the origin of the OBJ coordinate system, <b>in the OBJ coordinate system</b> * @param origYOffs the y-offset of the origin of the OBJ coordinate system, <b>in the OpenRocket coordinate system</b>
* @param origZOffs the z-offset of the origin of the OBJ coordinate system, <b>in the OBJ coordinate system</b> * @param origZOffs the z-offset of the origin of the OBJ coordinate system, <b>in the OpenRocket coordinate system</b>
*/ */
public static CoordTransform generateUsingLongitudinalAndForwardAxes(Axis axialAxis, Axis forwardAxis, public static CoordTransform generateUsingLongitudinalAndForwardAxes(Axis axialAxis, Axis forwardAxis,
double origXOffs, double origYOffs, double origZOffs) { double origXOffs, double origYOffs, double origZOffs) {
@ -79,12 +79,13 @@ public class CoordTransform {
Axis zAxis = null; Axis zAxis = null;
switch (axialAxis) { switch (axialAxis) {
case X -> xAxis = Axis.X; // X-axis points from the tip to the bottom, so invert it
case X_MIN -> xAxis = Axis.X_MIN; case X -> xAxis = Axis.X_MIN;
case Y -> yAxis = Axis.X; case X_MIN -> xAxis = Axis.X;
case Y_MIN -> yAxis = Axis.X_MIN; case Y -> yAxis = Axis.X_MIN;
case Z -> zAxis = Axis.X; case Y_MIN -> yAxis = Axis.X;
case Z_MIN -> zAxis = Axis.X_MIN; case Z -> zAxis = Axis.X_MIN;
case Z_MIN -> zAxis = Axis.X;
} }
switch (forwardAxis) { switch (forwardAxis) {
case X -> xAxis = Axis.Y; case X -> xAxis = Axis.Y;
@ -109,11 +110,7 @@ public class CoordTransform {
throw new IllegalStateException("Axes should not be null"); throw new IllegalStateException("Axes should not be null");
} }
final double origXTrans = getTransformedOriginOffset(xAxis, origXOffs, origYOffs, origZOffs); return new CoordTransform(xAxis, yAxis, zAxis, origXOffs, origYOffs, origZOffs);
final double origYTrans = getTransformedOriginOffset(yAxis, origXOffs, origYOffs, origZOffs);
final double origZTrans = getTransformedOriginOffset(zAxis, origXOffs, origYOffs, origZOffs);
return new CoordTransform(xAxis, yAxis, zAxis, origXTrans, origYTrans, origZTrans);
} }
@ -179,6 +176,10 @@ public class CoordTransform {
return convertLoc(x, y, z, 0, 0, 0); return convertLoc(x, y, z, 0, 0, 0);
} }
public FloatTuple convertLocWithoutOriginOffs(Coordinate coordinate) {
return convertLoc(coordinate.x, coordinate.y, coordinate.z, 0, 0, 0);
}
/** /**
* Converts the rotation coordinates from OpenRocket to OBJ coordinates. * Converts the rotation coordinates from OpenRocket to OBJ coordinates.
* @param xRot OpenRocket rotation in radians around the x-axis * @param xRot OpenRocket rotation in radians around the x-axis

View File

@ -11,6 +11,6 @@ package net.sf.openrocket.file.wavefrontobj;
*/ */
public class DefaultCoordTransform extends CoordTransform { public class DefaultCoordTransform extends CoordTransform {
public DefaultCoordTransform(double rocketLength) { public DefaultCoordTransform(double rocketLength) {
super(Axis.Y, Axis.Z, Axis.X_MIN, 0, 0, rocketLength); super(Axis.Y, Axis.Z, Axis.X_MIN, rocketLength, 0, 0);
} }
} }

View File

@ -143,7 +143,7 @@ public class ObjUtils {
*/ */
public static void translateVerticesFromComponentLocation(DefaultObj obj, CoordTransform transformer, public static void translateVerticesFromComponentLocation(DefaultObj obj, CoordTransform transformer,
int startIdx, int endIdx, Coordinate translation) { int startIdx, int endIdx, Coordinate translation) {
FloatTuple translatedLoc = transformer.convertLoc(translation); FloatTuple translatedLoc = transformer.convertLocWithoutOriginOffs(translation);
ObjUtils.translateVertices(obj, startIdx, endIdx, translatedLoc.getX(), translatedLoc.getY(), translatedLoc.getZ()); ObjUtils.translateVertices(obj, startIdx, endIdx, translatedLoc.getX(), translatedLoc.getY(), translatedLoc.getZ());
} }