// Fetch the transform of the view (avatar) Cell and its "look at"
// direction.
ViewManager vm = ViewManager.getViewManager();
ViewCell viewCell = vm.getPrimaryViewCell();
CellTransform viewTransform = viewCell.getWorldTransform();
ServerSessionManager manager =
viewCell.getCellCache().getSession().getSessionManager();
// The Cell Transform to apply to the Cell
CellTransform transform = null;
// Look for the "bounds hint" provided by the Cell. There are three
// possible cases:
//
// (1) There is a hint and the Cell wants us to do the optimal layout
// so go ahead and do it.
//
// (2) There is no hint, so use the default bounds radius and do the
// optimal layout
//
// (3) There is a hint that says do not do the optimal layout, so we
// will just put the Cell right on top of the avatar.
BoundingVolumeHint hint = state.getBoundingVolumeHint();
logger.info("Using bounding volume hint " + hint.getBoundsHint() +
", do placement=" + hint.isDoSystemPlacement());
if (hint != null && hint.isDoSystemPlacement() == true) {
// Case (1): We have a bounds hint and we want to do the layout,
// so we find the distance away from the avatar and also the height
// above the ground.
BoundingVolume boundsHint = hint.getBoundsHint();
transform = CellPlacementUtils.getCellTransform(manager, boundsHint,
viewTransform);
}
else if (hint == null) {
// Case (2): Do the optimal placement using the default radius.
BoundingVolume boundsHint = new BoundingSphere(DEFAULT_RADIUS, Vector3f.ZERO);
transform = CellPlacementUtils.getCellTransform(manager, boundsHint,
viewTransform);
}
else if (hint != null && hint.isDoSystemPlacement() == false) {
// Case (3): The Cell will take care of its own placement, use
// the origin of the avatar as the initial placement.
// Issue 998: make sure this is actually the current location of
// the avatar, and not the origin. This guarantees that the
// cell will be in the viewcache of the creator at least, so
// that the cell object can be (for example) positioned manually
// by the client.
transform = viewTransform;
}
// We also need to convert the initial origin of the Cell (in world
// coordinates to the coordinates of the parent Cell (if non-null)
if (parentCellID != null) {
Cell parent = viewCell.getCellCache().getCell(parentCellID);
CellTransform worldTransform = new CellTransform(null, null);
CellTransform parentTransform = parent.getWorldTransform();
logger.info("Transform of the parent cell: translation=" +
parentTransform.getTranslation(null).toString() + ", rotation=" +
parentTransform.getRotation(null).toString());
transform = ScenegraphUtils.computeChildTransform(parentTransform,
transform);
}