mirror of
https://github.com/Dejvino/roadtrip
synced 2024-11-14 13:03:28 +00:00
Added HideControl to hide eye-candy objects in the distance.
This commit is contained in:
parent
d3c6b622f7
commit
6214ff34e8
@ -18,7 +18,7 @@ public class RoadTripPlanner extends SimpleApplication {
|
||||
app.start();
|
||||
}
|
||||
|
||||
public static boolean DEBUG = /*false;/*/true;/**/
|
||||
public static boolean DEBUG = !true;/**/
|
||||
|
||||
protected BulletAppState bulletAppState;
|
||||
private GameWorldState gameWorldState;
|
||||
|
@ -264,6 +264,7 @@ public class GameWorldView {
|
||||
}
|
||||
modelInstance.setLocalTranslation(pos);
|
||||
modelInstance.setLocalScale(scale);
|
||||
modelInstance.addControl(new HideControl());
|
||||
objects.attachChild(modelInstance);
|
||||
}
|
||||
}
|
||||
|
77
src/roadtrip/view/HideControl.java
Normal file
77
src/roadtrip/view/HideControl.java
Normal file
@ -0,0 +1,77 @@
|
||||
package roadtrip.view;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import com.jme3.bounding.BoundingVolume;
|
||||
import com.jme3.renderer.Camera;
|
||||
import com.jme3.renderer.RenderManager;
|
||||
import com.jme3.renderer.ViewPort;
|
||||
import com.jme3.scene.Node;
|
||||
import com.jme3.scene.Spatial;
|
||||
import com.jme3.scene.control.AbstractControl;
|
||||
import com.jme3.scene.control.Control;
|
||||
|
||||
public class HideControl extends AbstractControl
|
||||
{
|
||||
private static final float DISTANCE_HIDE = 200;
|
||||
|
||||
private ArrayList<Spatial> children;
|
||||
private boolean hidden;
|
||||
|
||||
private BoundingVolume prevBv;
|
||||
|
||||
@Override
|
||||
public Control cloneForSpatial(Spatial spatial)
|
||||
{
|
||||
// TODO
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void controlRender(RenderManager rm, ViewPort vp)
|
||||
{
|
||||
Camera cam = vp.getCamera();
|
||||
BoundingVolume bv = spatial.getWorldBound();
|
||||
|
||||
if (bv == null) {
|
||||
bv = prevBv;
|
||||
} else {
|
||||
prevBv = bv;
|
||||
}
|
||||
|
||||
float distance = bv.distanceTo(cam.getLocation());
|
||||
|
||||
if (distance > HideControl.DISTANCE_HIDE) {
|
||||
if (!hidden) {
|
||||
for (int i = 0; i < children.size(); i++) {
|
||||
children.get(i).removeFromParent();
|
||||
}
|
||||
spatial.updateGeometricState();
|
||||
hidden = true;
|
||||
}
|
||||
} else {
|
||||
if (hidden) {
|
||||
for (int i = 0; i < children.size(); i++) {
|
||||
((Node) spatial).attachChild(children.get(i));
|
||||
}
|
||||
}
|
||||
spatial.updateGeometricState();
|
||||
hidden = false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void controlUpdate(float tpf)
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSpatial(Spatial spatial)
|
||||
{
|
||||
if (!(spatial instanceof Node)) {
|
||||
throw new IllegalArgumentException("only Node type is supported");
|
||||
}
|
||||
super.setSpatial(spatial);
|
||||
|
||||
children = new ArrayList<>(((Node) spatial).getChildren());
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user