Fix Converting FORWARD rotation to FRON

This commit is contained in:
lucas lelievre committed 2022-04-27 21:30:54 +02:00
1 parent 9d6dda8b17
commit 8609fb9e97
2 files changed
+26 -15

No files matched your search

@@ -4,8 +4,10 @@ import com.jme3.math.Quaternion;
import io.eiren.yaml.YamlNode;
import java.util.Objects;
public class TrackerConfig {
public final String trackerName;
public String designation;
public String description;
@@ -19,7 +21,7 @@ public class TrackerConfig {
this.description = tracker.getDescriptiveName();
this.designation = tracker.getBodyPosition() != null ? tracker.getBodyPosition().designation : null;
}
public TrackerConfig(YamlNode node) {
this.trackerName = node.getString("name");
this.description = node.getString("description");
@@ -37,11 +39,12 @@ public class TrackerConfig {
}
if (oldMountingRotation != null) {
mountingRotation = TrackerMountingRotation.valueOf(oldMountingRotation).quaternion;
TrackerMountingRotation rot = TrackerMountingRotation.fromName(oldMountingRotation);
mountingRotation = Objects.requireNonNullElse(rot, TrackerMountingRotation.FRONT).quaternion;
}
YamlNode adjNode = node.getNode("adjustment");
if(adjNode != null) {
if (adjNode != null) {
adjustment = new Quaternion(
adjNode.getFloat("x", 0),
adjNode.getFloat("y", 0),
@@ -50,22 +53,22 @@ public class TrackerConfig {
);
}
}
public void setDesignation(String newDesignation) {
this.designation = newDesignation;
}
public void saveConfig(YamlNode configNode) {
configNode.setProperty("name", trackerName);
if(designation != null)
if (designation != null)
configNode.setProperty("designation", designation);
else
configNode.removeProperty("designation");
if(hide)
if (hide)
configNode.setProperty("hide", hide);
else
configNode.removeProperty("hide");
if(adjustment != null) {
if (adjustment != null) {
configNode.setProperty("adj.x", adjustment.getX());
configNode.setProperty("adj.y", adjustment.getY());
configNode.setProperty("adj.z", adjustment.getZ());
@@ -73,11 +76,11 @@ public class TrackerConfig {
} else {
configNode.removeProperty("adj");
}
if(oldMountingRotation != null) {
if (oldMountingRotation != null) {
configNode.removeProperty("rotation");
}
if(mountingRotation != null) {
if (mountingRotation != null) {
configNode.setProperty("mountingRotation.x", mountingRotation.getX());
configNode.setProperty("mountingRotation.y", mountingRotation.getY());
configNode.setProperty("mountingRotation.z", mountingRotation.getZ());
@@ -86,7 +89,7 @@ public class TrackerConfig {
configNode.removeProperty("mountingRotation");
}
if(description != null) {
if (description != null) {
configNode.setProperty("description", description);
} else {
configNode.removeProperty("description");
@@ -4,7 +4,7 @@ import com.jme3.math.FastMath;
import com.jme3.math.Quaternion;
public enum TrackerMountingRotation {
FRONT(180),
LEFT(90),
BACK(0),
@@ -13,13 +13,21 @@ public enum TrackerMountingRotation {
public final Quaternion quaternion;
public static final TrackerMountingRotation[] values = values();
TrackerMountingRotation(float angle) {
this.quaternion = new Quaternion().fromAngles(0, angle * FastMath.DEG_TO_RAD, 0);
}
public static TrackerMountingRotation fromName(String name) {
for (TrackerMountingRotation r : values) {
if (r.name().equals(name))
return r;
}
return null;
}
public static TrackerMountingRotation fromQuaternion(Quaternion q) {
for (TrackerMountingRotation r : values()) {
for (TrackerMountingRotation r : values) {
if (r.quaternion.equals(q))
return r;
}