|
|
@ -77,21 +77,38 @@ public class QuaternionPropertyEditor implements PropertyEditor { |
|
|
|
return "[" + (float) Math.toDegrees(angles[0]) + ", " + (float) Math.toDegrees(angles[1]) + ", " + (float) Math.toDegrees(angles[2]) + "]"; |
|
|
|
return "[" + (float) Math.toDegrees(angles[0]) + ", " + (float) Math.toDegrees(angles[1]) + ", " + (float) Math.toDegrees(angles[2]) + "]"; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void setAsText(String text) throws IllegalArgumentException { |
|
|
|
private void parseInto(String text, Quaternion res) throws IllegalArgumentException { |
|
|
|
text = text.replace('[', ' '); |
|
|
|
text = text.replace('[', ' '); |
|
|
|
text = text.replace(']', ' '); |
|
|
|
text = text.replace(']', ' ').trim(); |
|
|
|
String[] values = text.split(","); |
|
|
|
String[] a = text.split("\\s*(,|\\s)\\s*"); |
|
|
|
if (values.length != 3) { |
|
|
|
|
|
|
|
throw (new IllegalArgumentException("String not correct")); |
|
|
|
|
|
|
|
|
|
|
|
if (a.length == 1) { |
|
|
|
|
|
|
|
if (text.trim().toLowerCase().equals("nan")) { |
|
|
|
|
|
|
|
res.set(Float.NaN, Float.NaN, Float.NaN, Float.NaN); |
|
|
|
|
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
float f = Float.parseFloat(text); |
|
|
|
|
|
|
|
f = (float) Math.toRadians(f); |
|
|
|
|
|
|
|
res.fromAngles(f, f, f); |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (a.length == 3) { |
|
|
|
float[] floats = new float[3]; |
|
|
|
float[] floats = new float[3]; |
|
|
|
for (int i = 0; i < values.length; i++) { |
|
|
|
for (int i = 0; i < a.length; i++) { |
|
|
|
String string = values[i]; |
|
|
|
floats[i] = (float) Math.toRadians(Float.parseFloat(a[i])); |
|
|
|
floats[i] = (float)Math.toRadians(Float.parseFloat(string)); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
res.fromAngles(floats); |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
throw new IllegalArgumentException("String not correct"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void setAsText(String text) throws IllegalArgumentException { |
|
|
|
Quaternion old = new Quaternion(); |
|
|
|
Quaternion old = new Quaternion(); |
|
|
|
old.set(quaternion); |
|
|
|
old.set(quaternion); |
|
|
|
quaternion.fromAngles(floats); |
|
|
|
parseInto(text, quaternion); |
|
|
|
notifyListeners(old, quaternion); |
|
|
|
notifyListeners(old, quaternion); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|