use of javax.vecmath.Vector3d in project JMRI by JMRI.
the class ListeningSpot method setOrientation.
public void setOrientation(PhysicalLocation target) {
Vector3d la = new Vector3d();
// Calculate the look-at vector
// la = target - location
la.sub(target.toVector3d(), _location);
la.normalize();
_lookAt = la;
// Calculate the up vector
_up = calcUpFromLookAt(la);
}
use of javax.vecmath.Vector3d in project JMRI by JMRI.
the class ListeningSpot method calcUpFromLookAt.
private Vector3d calcUpFromLookAt(Vector3d la) {
Vector3d _la = la;
_la.normalize();
Vector3d up = new Vector3d();
up.cross(_la, _rightVector);
up.cross(up, _la);
return (up);
}
use of javax.vecmath.Vector3d in project JMRI by JMRI.
the class ListeningSpot method setOrientation.
public void setOrientation(double bearing, double azimuth) {
// Convert bearing + azimuth to look-at and up vectors.
// Bearing measured clockwise from Y axis.
// Azimuth measured up (or down) from X/Y plane.
// map y = r sin (90-azimuth) cos bearing
// map x = r sin (90-azimuth) sin bearing
// map z = r cos (90-azimuth)
// Assumes r = 1;
double y = Math.sin(Math.toRadians(90 - azimuth)) * Math.cos(bearing);
double x = Math.sin(Math.toRadians(90 - azimuth)) * Math.sin(bearing);
double z = Math.cos(Math.toRadians(90 - azimuth));
_lookAt = new Vector3d(x, y, z);
_up = calcUpFromLookAt(_lookAt);
}
use of javax.vecmath.Vector3d in project JMRI by JMRI.
the class ListeningSpot method parseVector3d.
private Vector3d parseVector3d(String pos) {
if (pos == null) {
return (null);
}
// position is stored as a tuple string "(x,y,z)"
// Regex [-+]?[0-9]*\.?[0-9]+
String syntax = "\\((\\s*[-+]?[0-9]*\\.?[0-9]+),(\\s*[-+]?[0-9]*\\.?[0-9]+),(\\s*[-+]?[0-9]*\\.?[0-9]+)\\)";
try {
Pattern p = Pattern.compile(syntax);
Matcher m = p.matcher(pos);
if (!m.matches()) {
log.error("String does not match a valid position pattern. syntax= " + syntax + " string = " + pos);
return (null);
}
// ++debug
String xs = m.group(1);
String ys = m.group(2);
String zs = m.group(3);
log.debug("Loading Vector3d: x = " + xs + " y = " + ys + " z = " + zs);
// --debug
return (new Vector3d(Double.parseDouble(m.group(1)), Double.parseDouble(m.group(2)), Double.parseDouble(m.group(3))));
} catch (PatternSyntaxException e) {
log.error("Malformed Vector3d syntax! " + syntax);
return (null);
} catch (IllegalStateException e) {
log.error("Group called before match operation executed syntax=" + syntax + " string= " + pos + " " + e.toString());
return (null);
} catch (IndexOutOfBoundsException e) {
log.error("Index out of bounds " + syntax + " string= " + pos + " " + e.toString());
return (null);
}
}
use of javax.vecmath.Vector3d in project JMRI by JMRI.
the class RpsReporter method getPhysicalLocation.
/**
* getPhysicalLocation(String s)
*
* Returns the PhysicalLocation of the Transmitter with the given ID
*
* Given an ID (in String form), looks up the Transmitter and gets its
* current PhysicalLocation (translated from the RPS Measurement).
*/
public PhysicalLocation getPhysicalLocation(String s) {
if (s.length() > 0) {
try {
int id = Integer.parseInt(s);
Vector3d v = Engine.instance().getTransmitter(id).getLastMeasurement().getVector();
return (new PhysicalLocation(new Vector3f(v)));
} catch (NumberFormatException e) {
return (null);
} catch (NullPointerException e) {
return (null);
}
} else {
return (null);
}
}
Aggregations