Added chase camera and some cleanup

This commit is contained in:
Ziver Koc 2020-04-27 01:00:59 +02:00
parent 8eced25964
commit 176ee29753
2 changed files with 33 additions and 11 deletions

View file

@ -1,6 +1,10 @@
package se.cookery;
import com.jme3.app.FlyCamAppState;
import com.jme3.app.SimpleApplication;
import com.jme3.input.ChaseCamera;
import com.jme3.input.MouseInput;
import com.jme3.input.controls.MouseButtonTrigger;
import com.jme3.math.ColorRGBA;
import com.jme3.math.Vector3f;
import com.jme3.post.FilterPostProcessor;
@ -17,9 +21,9 @@ public class CookeryClient extends SimpleApplication {
@Override
public void simpleInitApp() {
flyCam.setMoveSpeed(15);
cam.setLocation(new Vector3f(0,20,-10));
cam.lookAt(new Vector3f(0f,0f,0f), Vector3f.UNIT_Z);
// -----------------------------------------
// Setup Terrain
// -----------------------------------------
Block block = new GrassLandWorldGenerator().generateBlock(0, 0);
@ -27,22 +31,42 @@ public class CookeryClient extends SimpleApplication {
terrain.setMaterial(MaterialUtil.createMaterial(assetManager, ColorRGBA.Green));
rootNode.attachChild(terrain);
// Geometry box = GeometryUtil.createBox(assetManager, 1f, 1f, 1f, ColorRGBA.Red);
// box.setLocalTranslation(box.getModelBound().getCenter());
// rootNode.attachChild(box);
// -----------------------------------------
// Setup Player
// -----------------------------------------
Player player = new Player(assetManager);
rootNode.attachChild(player.getGfxNode());
// -----------------------------------------
// Setup Camera
// -----------------------------------------
// flyCam.setMoveSpeed(15);
// cam.setLocation(new Vector3f(0,10,-20));
// cam.lookAt(new Vector3f(0f,0f,0f), Vector3f.UNIT_Z);
flyCam.setEnabled(false);
// stateManager.detach(stateManager.getState(FlyCamAppState.class));
ChaseCamera chaseCam = new ChaseCamera(cam, player.getGfxNode(), inputManager);
chaseCam.setDefaultDistance(10);
chaseCam.setRotationSpeed(2);
chaseCam.setLookAtOffset(Vector3f.UNIT_Y);
chaseCam.setToggleRotationTrigger(new MouseButtonTrigger(MouseInput.BUTTON_RIGHT));
// -----------------------------------------
// Setup Shaders
// -----------------------------------------
// Wireframe mode
// viewPort.addProcessor(new WireFrameProcessor(assetManager));
// Cartoon shader
FilterPostProcessor fpp = new FilterPostProcessor(assetManager);
CartoonEdgeFilter toon = new CartoonEdgeFilter();
toon.setEdgeWidth(0.5f);
toon.setEdgeIntensity(1.0f);
toon.setNormalThreshold(0.8f);
FilterPostProcessor fpp = new FilterPostProcessor(assetManager);
fpp.addFilter(toon);
viewPort.addProcessor(fpp);
}

View file

@ -1,12 +1,10 @@
package se.cookery.gfx.character;
import com.jme3.asset.AssetManager;
import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
import com.jme3.scene.Geometry;
import com.jme3.scene.Node;
import com.jme3.scene.Spatial;
import com.jme3.scene.shape.Box;
import se.cookery.gfx.util.GeometryUtil;
public class Player {
@ -14,7 +12,7 @@ public class Player {
public Player(AssetManager assetManager) {
Geometry box = GeometryUtil.createBox(assetManager, 0.5f,0.7f,0.5f, ColorRGBA.Red);
box.setLocalTranslation(0.5f, 0.7f, 0.5f);
box.setLocalTranslation(0.5f, 0.35f, 0.5f);
playerNode.attachChild(box);
}