How can I translate a point defined in the local space of a Spatial(entity) to the world space?
Currently I'm using the following function but I think it's wrong:
/**
* Transforms a point from the entity's local space into world space.
* @param entity the entity in which relative coordinates the point is set.
* @param point the point to convert.
* @return the world coordinates of the specified <code>point</code>.
*/
public static Vector3f pointToWorldSpace(Spatial entity, Vector3f point) {
//thid code has been copied from Spatial.updateWorldTranslation()
if (entity != null) {
return entity.getWorldRotation().mult(point).multLocal(entity.getWorldScale()).addLocal(entity.getWorldTranslation());
} else {
return point;
}
}
/**
* Sets the world translation of a spatial according to a supplied body.
* This is done by going "the other way around"; figuring
* out what its local translation has to be in order for the world
* translation to be the same as the one of the body.
*
* @param spat The Spatial to synchronize.
* @param worldTranslation
* @param store
*/
void worldToLocal( Spatial spat, Vector3f worldTranslation, Vector3f store ) {
if ( spat.getParent() != null ) {
store.set( worldTranslation ).subtractLocal( spat.getParent().getWorldTranslation() );
store.divideLocal( spat.getParent().getWorldScale() );
inverseWorldRotation.set( spat.getParent().getWorldRotation() ).inverseLocal()
.multLocal( store );
}
else {
store.set( worldTranslation );
}
}