* Plane.normal is now created by default and set instead of using references
* TerrainTestModifyHeight now uses mouse left/right buttons to raise/lower height git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@7674 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
This commit is contained in:
parent
e8069191a3
commit
c410fae0a6
engine/src
@ -63,7 +63,7 @@ public class Plane implements Savable, Cloneable {
|
|||||||
/**
|
/**
|
||||||
* Vector normal to the plane.
|
* Vector normal to the plane.
|
||||||
*/
|
*/
|
||||||
protected Vector3f normal;
|
protected Vector3f normal = new Vector3f();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constant of the plane. See formula in class definition.
|
* Constant of the plane. See formula in class definition.
|
||||||
@ -75,7 +75,6 @@ public class Plane implements Savable, Cloneable {
|
|||||||
* default object and contains a normal of (0,0,0) and a constant of 0.
|
* default object and contains a normal of (0,0,0) and a constant of 0.
|
||||||
*/
|
*/
|
||||||
public Plane() {
|
public Plane() {
|
||||||
normal = new Vector3f();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -89,10 +88,10 @@ public class Plane implements Savable, Cloneable {
|
|||||||
*/
|
*/
|
||||||
public Plane(Vector3f normal, float constant) {
|
public Plane(Vector3f normal, float constant) {
|
||||||
if (normal == null) {
|
if (normal == null) {
|
||||||
logger.warning("Normal was null, created default normal.");
|
throw new IllegalArgumentException("normal cannot be null");
|
||||||
normal = new Vector3f();
|
|
||||||
}
|
}
|
||||||
this.normal = normal;
|
|
||||||
|
this.normal.set(normal);
|
||||||
this.constant = constant;
|
this.constant = constant;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -104,8 +103,7 @@ public class Plane implements Savable, Cloneable {
|
|||||||
*/
|
*/
|
||||||
public void setNormal(Vector3f normal) {
|
public void setNormal(Vector3f normal) {
|
||||||
if (normal == null) {
|
if (normal == null) {
|
||||||
logger.warning("Normal was null, created default normal.");
|
throw new IllegalArgumentException("normal cannot be null");
|
||||||
normal = new Vector3f();
|
|
||||||
}
|
}
|
||||||
this.normal.set(normal);
|
this.normal.set(normal);
|
||||||
}
|
}
|
||||||
@ -113,13 +111,10 @@ public class Plane implements Savable, Cloneable {
|
|||||||
/**
|
/**
|
||||||
* <code>setNormal</code> sets the normal of the plane.
|
* <code>setNormal</code> sets the normal of the plane.
|
||||||
*
|
*
|
||||||
* @param normal
|
|
||||||
* the new normal of the plane.
|
|
||||||
*/
|
*/
|
||||||
public void setNormal(float x, float y, float z) {
|
public void setNormal(float x, float y, float z) {
|
||||||
if (normal == null) {
|
if (normal == null) {
|
||||||
logger.warning("Normal was null, created default normal.");
|
throw new IllegalArgumentException("normal cannot be null");
|
||||||
normal = new Vector3f();
|
|
||||||
}
|
}
|
||||||
this.normal.set(x,y,z);
|
this.normal.set(x,y,z);
|
||||||
}
|
}
|
||||||
|
@ -37,8 +37,10 @@ import com.jme3.collision.CollisionResult;
|
|||||||
import com.jme3.collision.CollisionResults;
|
import com.jme3.collision.CollisionResults;
|
||||||
import com.jme3.font.BitmapText;
|
import com.jme3.font.BitmapText;
|
||||||
import com.jme3.input.KeyInput;
|
import com.jme3.input.KeyInput;
|
||||||
|
import com.jme3.input.MouseInput;
|
||||||
import com.jme3.input.controls.ActionListener;
|
import com.jme3.input.controls.ActionListener;
|
||||||
import com.jme3.input.controls.KeyTrigger;
|
import com.jme3.input.controls.KeyTrigger;
|
||||||
|
import com.jme3.input.controls.MouseButtonTrigger;
|
||||||
import com.jme3.light.AmbientLight;
|
import com.jme3.light.AmbientLight;
|
||||||
import com.jme3.light.DirectionalLight;
|
import com.jme3.light.DirectionalLight;
|
||||||
import com.jme3.material.Material;
|
import com.jme3.material.Material;
|
||||||
@ -87,12 +89,12 @@ public class TerrainTestModifyHeight extends SimpleApplication {
|
|||||||
if (raiseTerrain){
|
if (raiseTerrain){
|
||||||
Vector3f intersection = getWorldIntersection();
|
Vector3f intersection = getWorldIntersection();
|
||||||
if (intersection != null) {
|
if (intersection != null) {
|
||||||
adjustHeight(intersection, 64, 1);
|
adjustHeight(intersection, 64, tpf * 60);
|
||||||
}
|
}
|
||||||
}else if (lowerTerrain){
|
}else if (lowerTerrain){
|
||||||
Vector3f intersection = getWorldIntersection();
|
Vector3f intersection = getWorldIntersection();
|
||||||
if (intersection != null) {
|
if (intersection != null) {
|
||||||
adjustHeight(intersection, 64, -1);
|
adjustHeight(intersection, 64, -tpf * 60);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -143,8 +145,6 @@ public class TerrainTestModifyHeight extends SimpleApplication {
|
|||||||
TerrainLodControl control = new TerrainLodControl(terrain, cameras);
|
TerrainLodControl control = new TerrainLodControl(terrain, cameras);
|
||||||
terrain.addControl(control);
|
terrain.addControl(control);
|
||||||
terrain.setMaterial(matTerrain);
|
terrain.setMaterial(matTerrain);
|
||||||
terrain.setModelBound(new BoundingBox());
|
|
||||||
terrain.updateModelBound();
|
|
||||||
terrain.setLocalTranslation(0, -100, 0);
|
terrain.setLocalTranslation(0, -100, 0);
|
||||||
terrain.setLocalScale(2f, 1f, 2f);
|
terrain.setLocalScale(2f, 1f, 2f);
|
||||||
rootNode.attachChild(terrain);
|
rootNode.attachChild(terrain);
|
||||||
@ -163,7 +163,6 @@ public class TerrainTestModifyHeight extends SimpleApplication {
|
|||||||
|
|
||||||
public void loadHintText() {
|
public void loadHintText() {
|
||||||
hintText = new BitmapText(guiFont, false);
|
hintText = new BitmapText(guiFont, false);
|
||||||
hintText.setSize(guiFont.getCharSet().getRenderedSize());
|
|
||||||
hintText.setLocalTranslation(0, getCamera().getHeight(), 0);
|
hintText.setLocalTranslation(0, getCamera().getHeight(), 0);
|
||||||
hintText.setText("Hit 1 to raise terrain, hit 2 to lower terrain");
|
hintText.setText("Hit 1 to raise terrain, hit 2 to lower terrain");
|
||||||
guiNode.attachChild(hintText);
|
guiNode.attachChild(hintText);
|
||||||
@ -173,11 +172,10 @@ public class TerrainTestModifyHeight extends SimpleApplication {
|
|||||||
int x = (int) getCamera().getLocation().x;
|
int x = (int) getCamera().getLocation().x;
|
||||||
int y = (int) getCamera().getLocation().y;
|
int y = (int) getCamera().getLocation().y;
|
||||||
int z = (int) getCamera().getLocation().z;
|
int z = (int) getCamera().getLocation().z;
|
||||||
hintText.setText("Hit 1 to raise terrain, hit 2 to lower terrain. " + x + "," + y + "," + z);
|
hintText.setText("Press left mouse button to raise terrain, press right mouse button to lower terrain. " + x + "," + y + "," + z);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void initCrossHairs() {
|
protected void initCrossHairs() {
|
||||||
//guiFont = assetManager.loadFont("Interface/Fonts/Default.fnt");
|
|
||||||
BitmapText ch = new BitmapText(guiFont, false);
|
BitmapText ch = new BitmapText(guiFont, false);
|
||||||
ch.setSize(guiFont.getCharSet().getRenderedSize() * 2);
|
ch.setSize(guiFont.getCharSet().getRenderedSize() * 2);
|
||||||
ch.setText("+"); // crosshairs
|
ch.setText("+"); // crosshairs
|
||||||
@ -189,11 +187,12 @@ public class TerrainTestModifyHeight extends SimpleApplication {
|
|||||||
|
|
||||||
private void setupKeys() {
|
private void setupKeys() {
|
||||||
flyCam.setMoveSpeed(100);
|
flyCam.setMoveSpeed(100);
|
||||||
|
|
||||||
inputManager.addMapping("wireframe", new KeyTrigger(KeyInput.KEY_T));
|
inputManager.addMapping("wireframe", new KeyTrigger(KeyInput.KEY_T));
|
||||||
inputManager.addListener(actionListener, "wireframe");
|
inputManager.addListener(actionListener, "wireframe");
|
||||||
inputManager.addMapping("Raise", new KeyTrigger(KeyInput.KEY_1));
|
inputManager.addMapping("Raise", new MouseButtonTrigger(MouseInput.BUTTON_LEFT));
|
||||||
inputManager.addListener(actionListener, "Raise");
|
inputManager.addListener(actionListener, "Raise");
|
||||||
inputManager.addMapping("Lower", new KeyTrigger(KeyInput.KEY_2));
|
inputManager.addMapping("Lower", new MouseButtonTrigger(MouseInput.BUTTON_RIGHT));
|
||||||
inputManager.addListener(actionListener, "Lower");
|
inputManager.addListener(actionListener, "Lower");
|
||||||
}
|
}
|
||||||
private ActionListener actionListener = new ActionListener() {
|
private ActionListener actionListener = new ActionListener() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user