1
0
mirror of https://github.com/Dejvino/roadtrip synced 2024-11-24 08:33:20 +00:00

Themeless: made map texture a grid, added grid-aligned rocks instead of grass.

This commit is contained in:
Dejvino 2017-02-01 01:37:19 +01:00
parent e04114e877
commit d69faa4852
11 changed files with 106 additions and 35 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 558 B

BIN
assets/Textures/map-low.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 559 B

BIN
assets/Textures/map-mid.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 559 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.8 KiB

View File

@ -20,6 +20,7 @@ import roadtrip.model.VehicleInstance;
import roadtrip.view.CompassNode; import roadtrip.view.CompassNode;
import roadtrip.view.GameMenuNode; import roadtrip.view.GameMenuNode;
import roadtrip.view.GameWorldView; import roadtrip.view.GameWorldView;
import roadtrip.view.HideControl;
import roadtrip.view.VehicleNode; import roadtrip.view.VehicleNode;
import roadtrip.view.model.GameWorldState; import roadtrip.view.model.GameWorldState;
import roadtrip.view.model.Player; import roadtrip.view.model.Player;
@ -82,7 +83,13 @@ public class RoadTrip extends GameApplication implements ActionListener {
rootNode.addLight(al); rootNode.addLight(al);
gameWorldState = new GameWorldState(1L); gameWorldState = new GameWorldState(1L);
gameWorldView = GameWorldView.create(gameWorldState, assetManager, cam, rootNode, getPhysicsSpace()); gameWorldView = GameWorldView.create(gameWorldState, assetManager, cam, rootNode, getPhysicsSpace(), new HideControl.TargetProvider() {
@Override
public Vector3f getTarget() {
return player.node.getWorldTranslation();
}
});
addCar(); addCar();
addCar(); addCar();

View File

@ -5,6 +5,7 @@ import com.jme3.bullet.BulletAppState;
import com.jme3.bullet.PhysicsSpace; import com.jme3.bullet.PhysicsSpace;
import com.jme3.math.*; import com.jme3.math.*;
import roadtrip.view.GameWorldView; import roadtrip.view.GameWorldView;
import roadtrip.view.HideControl;
import roadtrip.view.model.GameWorldState; import roadtrip.view.model.GameWorldState;
/** /**
@ -37,7 +38,13 @@ public class RoadTripPlanner extends SimpleApplication {
bulletAppState.setDebugEnabled(DEBUG); bulletAppState.setDebugEnabled(DEBUG);
gameWorldState = new GameWorldState(1L); gameWorldState = new GameWorldState(1L);
gameWorldView = GameWorldView.create(gameWorldState, assetManager, cam, rootNode, getPhysicsSpace()); gameWorldView = GameWorldView.create(gameWorldState, assetManager, cam, rootNode, getPhysicsSpace(), new HideControl.TargetProvider() {
@Override
public Vector3f getTarget() {
return cam.getLocation();
}
});
flyCam.setMoveSpeed(300f); flyCam.setMoveSpeed(300f);
cam.setLocation(new Vector3f(0, 200f, 0)); cam.setLocation(new Vector3f(0, 200f, 0));

View File

@ -15,8 +15,10 @@ import com.jme3.math.Vector3f;
import com.jme3.post.FilterPostProcessor; import com.jme3.post.FilterPostProcessor;
import com.jme3.post.filters.DepthOfFieldFilter; import com.jme3.post.filters.DepthOfFieldFilter;
import com.jme3.renderer.Camera; import com.jme3.renderer.Camera;
import com.jme3.scene.Geometry;
import com.jme3.scene.Node; import com.jme3.scene.Node;
import com.jme3.scene.Spatial; import com.jme3.scene.Spatial;
import com.jme3.scene.shape.Box;
import com.jme3.terrain.geomipmap.*; import com.jme3.terrain.geomipmap.*;
import com.jme3.terrain.geomipmap.grid.FractalTileLoader; import com.jme3.terrain.geomipmap.grid.FractalTileLoader;
import com.jme3.terrain.geomipmap.lodcalc.DistanceLodCalculator; import com.jme3.terrain.geomipmap.lodcalc.DistanceLodCalculator;
@ -35,6 +37,7 @@ import roadtrip.model.MapObjectInstance;
import roadtrip.model.ProceduralMapQuadBlock; import roadtrip.model.ProceduralMapQuadBlock;
import roadtrip.model.TerrainDataProvider; import roadtrip.model.TerrainDataProvider;
import roadtrip.view.model.GameWorldState; import roadtrip.view.model.GameWorldState;
import roadtrip.view.model.Player;
/** /**
* Created by dejvino on 14.01.2017. * Created by dejvino on 14.01.2017.
@ -42,26 +45,32 @@ import roadtrip.view.model.GameWorldState;
public class GameWorldView { public class GameWorldView {
public static boolean DEBUG = false;//true; public static boolean DEBUG = false;//true;
private final GameWorldState state; private final GameWorldState state;
private final AssetManager assetManager; private final AssetManager assetManager;
private final Camera camera; private final Camera camera;
private final Node rootNode; private final Node rootNode;
private final PhysicsSpace physicsSpace; private final PhysicsSpace physicsSpace;
private final HideControl.TargetProvider targetProvider;
public TerrainView terrain = new TerrainView(new TerrainDataProvider()); public TerrainView terrain = new TerrainView(new TerrainDataProvider());
public GameWorldView(GameWorldState gameWorldState, AssetManager assetManager, Camera camera, Node rootNode, PhysicsSpace physicsSpace) { public GameWorldView(GameWorldState gameWorldState, AssetManager assetManager,
Camera camera, Node rootNode, PhysicsSpace physicsSpace,
HideControl.TargetProvider targetProvider) {
this.state = gameWorldState; this.state = gameWorldState;
this.assetManager = assetManager; this.assetManager = assetManager;
this.camera = camera; this.camera = camera;
this.rootNode = rootNode; this.rootNode = rootNode;
this.physicsSpace = physicsSpace; this.physicsSpace = physicsSpace;
this.targetProvider = targetProvider;
} }
public static GameWorldView create(GameWorldState gameWorldState, AssetManager assetManager, Camera camera, Node rootNode, PhysicsSpace physicsSpace) { public static GameWorldView create(GameWorldState gameWorldState,
GameWorldView gameWorldView = new GameWorldView(gameWorldState, assetManager, camera, rootNode, physicsSpace); AssetManager assetManager, Camera camera, Node rootNode,
PhysicsSpace physicsSpace, HideControl.TargetProvider targetProvider) {
GameWorldView gameWorldView = new GameWorldView(gameWorldState, assetManager, camera, rootNode, physicsSpace, targetProvider);
gameWorldView.initialize(); gameWorldView.initialize();
return gameWorldView; return gameWorldView;
} }
@ -95,28 +104,27 @@ public class GameWorldView {
// slopeColorMap: the texture to be used for cliffs, and steep mountain sites // slopeColorMap: the texture to be used for cliffs, and steep mountain sites
// slopeTileFactor: the texture scale for slopes // slopeTileFactor: the texture scale for slopes
// terrainSize: the total size of the terrain (used for scaling the texture) // terrainSize: the total size of the terrain (used for scaling the texture)
// GRASS texture Texture textureMid = this.assetManager.loadTexture("Textures/map-mid.png");
Texture grass = this.assetManager.loadTexture("Textures/solid-grass.png"); textureMid.setWrap(Texture.WrapMode.Repeat);
grass.setWrap(Texture.WrapMode.Repeat); Texture textureLow = this.assetManager.loadTexture("Textures/map-low.png");
Texture dirt = this.assetManager.loadTexture("Textures/solid-road.png"); textureLow.setWrap(Texture.WrapMode.Repeat);
dirt.setWrap(Texture.WrapMode.Repeat); Texture textureHigh = this.assetManager.loadTexture("Textures/map-high.png");
Texture rock = this.assetManager.loadTexture("Textures/solid-stone.png"); textureHigh.setWrap(Texture.WrapMode.Repeat);
rock.setWrap(Texture.WrapMode.Repeat);
float modif = (heightScale / 100f) / 3f; float modif = (heightScale / 100f) / 3f;
terrain.mat_terrain.setTexture("region1ColorMap", dirt); terrain.mat_terrain.setTexture("region1ColorMap", textureLow);
terrain.mat_terrain.setVector3("region1", new Vector3f(0, 80 * modif, terrain.dirtScale)); terrain.mat_terrain.setVector3("region1", new Vector3f(0, 80 * modif, terrain.texLowScale));
terrain.mat_terrain.setTexture("region2ColorMap", grass); terrain.mat_terrain.setTexture("region2ColorMap", textureMid);
terrain.mat_terrain.setVector3("region2", new Vector3f(100 * modif, 160 * modif, terrain.grassScale)); terrain.mat_terrain.setVector3("region2", new Vector3f(100 * modif, 160 * modif, terrain.texMidScale));
terrain.mat_terrain.setTexture("region3ColorMap", rock); terrain.mat_terrain.setTexture("region3ColorMap", textureHigh);
terrain.mat_terrain.setVector3("region3", new Vector3f(190 * modif, 240 * modif, terrain.rockScale)); terrain.mat_terrain.setVector3("region3", new Vector3f(190 * modif, 240 * modif, terrain.texHighScale));
terrain.mat_terrain.setTexture("region4ColorMap", dirt); terrain.mat_terrain.setTexture("region4ColorMap", textureLow);
terrain.mat_terrain.setVector3("region4", new Vector3f(250 * modif, 350 * modif, terrain.dirtScale)); terrain.mat_terrain.setVector3("region4", new Vector3f(250 * modif, 350 * modif, terrain.texLowScale));
terrain.mat_terrain.setTexture("slopeColorMap", rock); terrain.mat_terrain.setTexture("slopeColorMap", textureHigh);
terrain.mat_terrain.setFloat("slopeTileFactor", 32); terrain.mat_terrain.setFloat("slopeTileFactor", 32);
terrain.mat_terrain.setFloat("terrainSize", 513); terrain.mat_terrain.setFloat("terrainSize", 513);
@ -175,6 +183,13 @@ public class GameWorldView {
final Spatial houseModel = assetManager.loadModel("Models/house1.j3o"); final Spatial houseModel = assetManager.loadModel("Models/house1.j3o");
final Spatial grassModel = assetManager.loadModel("Models/grass.j3o"); final Spatial grassModel = assetManager.loadModel("Models/grass.j3o");
Material rockMat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
rockMat.setColor("Color", ColorRGBA.Gray);
Geometry rockGeom = new Geometry("rock", new Box(1f, 1f, 1f));
rockGeom.setMaterial(rockMat);
final Node rockModel = new Node("rockNode");
rockModel.attachChild(rockGeom);
final FineTerrainGrid terrainGrid = terrain.terrainGrid; final FineTerrainGrid terrainGrid = terrain.terrainGrid;
terrainGrid.addListener(new TerrainGridListener() { terrainGrid.addListener(new TerrainGridListener() {
@ -248,15 +263,24 @@ public class GameWorldView {
objects.attachChild(modelInstance); objects.attachChild(modelInstance);
} }
for (int i = 0; i < rand.nextInt(10000); i++) { int w = 128;
Vector3f pos = new Vector3f((rand.nextFloat() - 0.5f) * 128f, 0f, (rand.nextFloat() - 0.5f) * 128f).addLocal(quad.getWorldTranslation()); for (int i = 0; i < w*w; i++) {
int x = i % w;
int z = i / w;
if (((x % 8) + (z % 8)) != 0) continue;
Vector3f pos = new Vector3f(x - w/2f + 0.25f*terrainGrid.getLocalScale().x, 0f, z - w/2f + 0.25f*terrainGrid.getLocalScale().z).addLocal(quad.getWorldTranslation());
pos.addLocal(0f, getHeight(quad, pos), 0f); pos.addLocal(0f, getHeight(quad, pos), 0f);
Vector3f scale = Vector3f.UNIT_XYZ; Vector3f scale = Vector3f.UNIT_XYZ;
Spatial modelInstance; Spatial modelInstance;
float s = 0.1f;
if (i == 0) {
s = 0.4f;
} else if ((x % 16) + (z % 16) == 0) {
s = 0.2f;
}
switch ("grass") { switch ("grass") {
case "grass": case "grass":
modelInstance = grassModel.clone(); modelInstance = rockModel.clone();
float s = 0.2f + rand.nextFloat() * 2f;
scale = new Vector3f(s, s, s); scale = new Vector3f(s, s, s);
break; break;
default: default:
@ -264,7 +288,7 @@ public class GameWorldView {
} }
modelInstance.setLocalTranslation(pos); modelInstance.setLocalTranslation(pos);
modelInstance.setLocalScale(scale); modelInstance.setLocalScale(scale);
modelInstance.addControl(new HideControl()); modelInstance.addControl(new HideControl(20f + 140f * s, targetProvider));
objects.attachChild(modelInstance); objects.attachChild(modelInstance);
} }
} }

View File

@ -2,6 +2,7 @@ package roadtrip.view;
import java.util.ArrayList; import java.util.ArrayList;
import com.jme3.bounding.BoundingVolume; import com.jme3.bounding.BoundingVolume;
import com.jme3.math.Vector3f;
import com.jme3.renderer.Camera; import com.jme3.renderer.Camera;
import com.jme3.renderer.RenderManager; import com.jme3.renderer.RenderManager;
import com.jme3.renderer.ViewPort; import com.jme3.renderer.ViewPort;
@ -12,13 +13,29 @@ import com.jme3.scene.control.Control;
public class HideControl extends AbstractControl public class HideControl extends AbstractControl
{ {
private static final float DISTANCE_HIDE = 200; private final float distanceToHide;
private ArrayList<Spatial> children; private ArrayList<Spatial> children;
private boolean hidden; private boolean hidden;
private BoundingVolume prevBv; private BoundingVolume prevBv;
private TargetProvider targetProvider;
public HideControl(float distanceToHide) {
this(distanceToHide, null);
}
public HideControl(float distanceToHide, TargetProvider targetProvider) {
this.distanceToHide = distanceToHide;
this.targetProvider = targetProvider;
}
public void setTargetProvider(TargetProvider targetProvider)
{
this.targetProvider = targetProvider;
}
@Override @Override
public Control cloneForSpatial(Spatial spatial) public Control cloneForSpatial(Spatial spatial)
{ {
@ -29,8 +46,18 @@ public class HideControl extends AbstractControl
@Override @Override
protected void controlRender(RenderManager rm, ViewPort vp) protected void controlRender(RenderManager rm, ViewPort vp)
{ {
Camera cam = vp.getCamera(); if (targetProvider == null) {
BoundingVolume bv = spatial.getWorldBound(); final Camera cam = vp.getCamera();
targetProvider = new TargetProvider() {
@Override
public Vector3f getTarget() {
return cam.getLocation();
}
};
}
/*BoundingVolume bv = spatial.getWorldBound();
if (bv == null) { if (bv == null) {
bv = prevBv; bv = prevBv;
@ -38,9 +65,10 @@ public class HideControl extends AbstractControl
prevBv = bv; prevBv = bv;
} }
float distance = bv.distanceTo(cam.getLocation()); float distance = bv.distanceTo(targetProvider.getTarget());*/
float distance = spatial.getWorldTranslation().distance(targetProvider.getTarget());
if (distance > HideControl.DISTANCE_HIDE) { if (distance > distanceToHide) {
if (!hidden) { if (!hidden) {
for (int i = 0; i < children.size(); i++) { for (int i = 0; i < children.size(); i++) {
children.get(i).removeFromParent(); children.get(i).removeFromParent();
@ -74,4 +102,9 @@ public class HideControl extends AbstractControl
children = new ArrayList<>(((Node) spatial).getChildren()); children = new ArrayList<>(((Node) spatial).getChildren());
} }
public interface TargetProvider
{
Vector3f getTarget();
}
} }

View File

@ -10,9 +10,9 @@ import roadtrip.model.TerrainDataProvider;
public class TerrainView { public class TerrainView {
public Material mat_terrain; public Material mat_terrain;
public FineTerrainGrid terrainGrid; public FineTerrainGrid terrainGrid;
public float grassScale = 64; public float texMidScale = 64;
public float dirtScale = 64; public float texLowScale = 64;
public float rockScale = 64; public float texHighScale = 64;
public TerrainDataProvider terrainDataProvider; public TerrainDataProvider terrainDataProvider;
public TerrainView(TerrainDataProvider terrainDataProvider) { public TerrainView(TerrainDataProvider terrainDataProvider) {