package javara.world.physical;
import javara.world.PhysicalObject;
import com.jme3.asset.AssetManager;
import com.jme3.bullet.collision.shapes.HeightfieldCollisionShape;
import com.jme3.bullet.control.RigidBodyControl;
import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
import com.jme3.math.Vector3f;
import com.jme3.renderer.queue.RenderQueue.ShadowMode;
import com.jme3.scene.Geometry;
import com.jme3.scene.Node;
import com.jme3.scene.shape.Box;
public class Ground extends PhysicalObject {
protected Material groundMat;
public Ground(AssetManager am, float radius, ColorRGBA color) {
super(0, false, color);
groundMat = new Material(am, "Common/MatDefs/Misc/Unshaded.j3md");
groundMat.setColor("Color", color);
spatial = new Node(identifier);
Geometry geom = new Geometry(identifier, new Box(Vector3f.ZERO, radius, 0, radius));
geom.setMaterial(groundMat);
geom.setShadowMode(ShadowMode.Receive);
((Node)spatial).attachChild(geom);
// shape = new PlaneCollisionShape(new Plane(Vector3f.UNIT_Y, 0));
// The PlaneCollisionShape causes collision listeners to ALWAYS fire for some reason. This
// is a hacky workaround.
int num = (int)radius * (int)radius;
float[] height = new float[num];
shape = new HeightfieldCollisionShape(height);// , new Vector3f(radius, 0, radius));
physics = new RigidBodyControl(shape, 0);
}
public void setColor(ColorRGBA color) {
this.color = color;
groundMat.setColor("Color", color);
}
@Override
public void setHologram(boolean set) {
if (set)
throw new UnsupportedOperationException();
else
super.setHologram(set);
}
public void update(float tpf) {
Vector3f groundTrans = world.getPlayer().getCameraNode().getWorldTranslation().clone();
groundTrans.y = 0;
setLocalTranslation(groundTrans);
}
}