I hope this is enough. Here is the simpleUpdate method used to update the 8 boxes’ locations, or to show the blue highlight box if nothing currently selected:
public void simpleUpdate(float lastTimePerFrame)
{
if(this.selectedEntity != null)
{
selectedEntity.updateGeometricState();
selectedEntity.updateModelBound();
BoundingBox boundingBox = (BoundingBox) selectedEntity //Gets the BoundingBox of the bigger box
.getComponentByType(GeometryComponent.class)
.getGeometry().getModelBound();
Vector3f camTranslation = getParentEntity().getComponentByType( //Gets the players cameras World Translation.
FirstPersonCameraComponent.class)
.getWorldCameraTranslation();
Vector3f corner1, corner2, corner3, corner4, corner5, corner6, corner7, corner8;
Quaternion geomRot = selectedEntity.getComponentByType(GeometryComponent.class).getGeometry().getWorldRotation(); //Gets the bigger boxs World Rotation
Vector3f geomPos = selectedEntity.getComponentByType(GeometryComponent.class).getGeometry().getWorldTranslation(); //Gets the bigger boxs World Translation
corner1 = geomPos.add(geomRot.mult(new Vector3f(boundingBox.getXExtent(),boundingBox.getYExtent(),boundingBox.getZExtent())));
corner2 = geomPos.add(geomRot.mult(new Vector3f(boundingBox.getXExtent(),-boundingBox.getYExtent(),boundingBox.getZExtent())));
corner3 = geomPos.add(geomRot.mult(new Vector3f(-boundingBox.getXExtent(),boundingBox.getYExtent(),boundingBox.getZExtent())));
corner4 = geomPos.add(geomRot.mult(new Vector3f(-boundingBox.getXExtent(),-boundingBox.getYExtent(),boundingBox.getZExtent())));
corner5 = geomPos.add(geomRot.mult(new Vector3f(boundingBox.getXExtent(),boundingBox.getYExtent(),-boundingBox.getZExtent())));
corner6 = geomPos.add(geomRot.mult(new Vector3f(boundingBox.getXExtent(),-boundingBox.getYExtent(),-boundingBox.getZExtent())));
corner7 = geomPos.add(geomRot.mult(new Vector3f(-boundingBox.getXExtent(),boundingBox.getYExtent(),-boundingBox.getZExtent())));
corner8 = geomPos.add(geomRot.mult(new Vector3f(-boundingBox.getXExtent(),-boundingBox.getYExtent(),-boundingBox.getZExtent())));
if(cube1Geo != null)
{
cube1Geo.removeFromParent();
cube2Geo.removeFromParent();
cube3Geo.removeFromParent();
cube4Geo.removeFromParent();
cube5Geo.removeFromParent();
cube6Geo.removeFromParent();
cube7Geo.removeFromParent();
cube8Geo.removeFromParent();
}
cube1Geo = IrisGame.instance.putShape(new Box(0.2f, 0.2f, 0.2f), ColorRGBA.Red);
cube2Geo = IrisGame.instance.putShape(new Box(0.2f, 0.2f, 0.2f), ColorRGBA.Orange);
cube3Geo = IrisGame.instance.putShape(new Box(0.2f, 0.2f, 0.2f), ColorRGBA.Yellow);
cube4Geo = IrisGame.instance.putShape(new Box(0.2f, 0.2f, 0.2f), ColorRGBA.Green);
cube5Geo = IrisGame.instance.putShape(new Box(0.2f, 0.2f, 0.2f), ColorRGBA.Cyan);
cube6Geo = IrisGame.instance.putShape(new Box(0.2f, 0.2f, 0.2f), ColorRGBA.Blue);
cube7Geo = IrisGame.instance.putShape(new Box(0.2f, 0.2f, 0.2f), ColorRGBA.Magenta);
cube8Geo = IrisGame.instance.putShape(new Box(0.2f, 0.2f, 0.2f), ColorRGBA.Pink);
cube1Geo.setLocalTranslation(corner1);
cube2Geo.setLocalTranslation(corner2);
cube3Geo.setLocalTranslation(corner3);
cube4Geo.setLocalTranslation(corner4);
cube5Geo.setLocalTranslation(corner5);
cube6Geo.setLocalTranslation(corner6);
cube7Geo.setLocalTranslation(corner7);
cube8Geo.setLocalTranslation(corner8);
}
else
{ //This section just creates the highlight around the box which the crosshairs are hovered over.
CollisionResults results = getCollisionResults();
if(results.size() > 0)
{
CollisionResult closest = results.getClosestCollision();
Geometry closestGeom = closest.getGeometry();
if(tempHighlightGeom != null)
{
tempHighlightGeom.removeFromParent();
tempHighlightGeom = null;
}
tempHighlightGeom = closestGeom.clone();
tempHighlightGeom.scale(1.05f);
Material wireMaterial = new Material(
IrisGame.instance.getAssetManager(),
"Common/MatDefs/Misc/Unshaded.j3md");
wireMaterial.setColor("Color", new ColorRGBA(0f, 0f,
1f, 0.2f));
wireMaterial.getAdditionalRenderState().setBlendMode(
BlendMode.Alpha);
tempHighlightGeom.setMaterial(wireMaterial);
tempHighlightGeom.setQueueBucket(Bucket.Translucent);
IrisGame.instance.getRootNode().attachChild(
tempHighlightGeom);
}
else
{
if(tempHighlightGeom != null)
{
tempHighlightGeom.removeFromParent();
tempHighlightGeom = null;
}
}
}
}
If you need any other code let me know. The bigger box is attached to the player’s cameraNode when they click on it, so that’s how the big box follows the player as they turn.