From d2b6f01798324af6830dcf6290611abbbf503f7b Mon Sep 17 00:00:00 2001 From: Dejvino Date: Sat, 21 Jan 2017 01:46:40 +0100 Subject: [PATCH] Map: Added randomly placed trees. Debug mode. --- .../Materials/Generated/tree-Material_001.j3m | 23 ++++++ .../Materials/Generated/tree-Material_002.j3m | 23 ++++++ assets/Models/tree.j3o | Bin 0 -> 8570 bytes assets/Models/tree.j3odata | 3 + src/roadtrip/RoadTrip.java | 66 +++++++++++++++--- 5 files changed, 104 insertions(+), 11 deletions(-) create mode 100644 assets/Materials/Generated/tree-Material_001.j3m create mode 100644 assets/Materials/Generated/tree-Material_002.j3m create mode 100644 assets/Models/tree.j3o create mode 100644 assets/Models/tree.j3odata diff --git a/assets/Materials/Generated/tree-Material_001.j3m b/assets/Materials/Generated/tree-Material_001.j3m new file mode 100644 index 0000000..0ef6d91 --- /dev/null +++ b/assets/Materials/Generated/tree-Material_001.j3m @@ -0,0 +1,23 @@ +Material MyMaterial : Common/MatDefs/Light/Lighting.j3md { + MaterialParameters { + DiffuseMap : Repeat Textures/solid-road.png + GlowColor : 0.0 0.0 0.0 1.0 + Specular : 0.5 0.5 0.5 1.0 + Diffuse : 0.110066734 0.046717312 0.015608258 1.0 + UseMaterialColors : true + ParallaxHeight : 0.05 + Ambient : 0.13758342 0.058396637 0.019510321 1.0 + Shininess : 12.5 + } + AdditionalRenderState { + FaceCull Back + Wireframe Off + DepthWrite On + PolyOffset 0.0 0.0 + AlphaTestFalloff 0.0 + Blend Off + PointSprite Off + ColorWrite On + DepthTest On + } +} diff --git a/assets/Materials/Generated/tree-Material_002.j3m b/assets/Materials/Generated/tree-Material_002.j3m new file mode 100644 index 0000000..3bfee60 --- /dev/null +++ b/assets/Materials/Generated/tree-Material_002.j3m @@ -0,0 +1,23 @@ +Material MyMaterial : Common/MatDefs/Light/Lighting.j3md { + MaterialParameters { + DiffuseMap : Repeat Textures/solid-grass.png + GlowColor : 0.0 0.0 0.0 1.0 + Specular : 0.051366556 0.24696888 0.0029339949 1.0 + Diffuse : 0.029459173 0.08522777 0.010477433 1.0 + UseMaterialColors : true + ParallaxHeight : 0.05 + Ambient : 0.036823966 0.10653471 0.013096791 1.0 + Shininess : 10.5 + } + AdditionalRenderState { + FaceCull Back + Wireframe Off + DepthWrite On + PolyOffset 0.0 0.0 + AlphaTestFalloff 0.0 + Blend Off + PointSprite Off + ColorWrite On + DepthTest On + } +} diff --git a/assets/Models/tree.j3o b/assets/Models/tree.j3o new file mode 100644 index 0000000000000000000000000000000000000000..f6ea1de5cc62ed6d4a3fc36816833faeec389dd7 GIT binary patch literal 8570 zcmeHMYiu0V6`nJ*5AS-N^()Rhgz!p8vQ8XAfY@H!apFAe#Ic}Id0JYI$ zu(Yx^7-*KR8i@h5G^ko?o|jV&<5_o1HO94+tsYZH4K2tVYMrjEVX7sW1&e00sZqU< z(F`dQ9YOF*}ZGT(lks7 z5{nVAOtU0MQL8Iix}7R&R;plTv_LI$<+anAtt><%R5bNM$(F>dyk_SX%ww&6V1>Cd z@d^R8tlJXTYAt;%S4x4sR*pLEKrenaSHvD2Hw>+ms7i0=)S_l52CyToTIjYkinSj%sKANnW*Q* zSlQWQTm(Bt6(M2F(?6BbvLf7KmImKgDZ7Lv6djlo7CHs;s%?ivtlCA0 zp&BA^1Jtbx2Tp{KAkkdtm%O^=+*84my{%U)&M_@SSGX2DZmGp#5i!b9Z9+u6=o=Ba zr7^D;^sMf9VyA8(dda`oOcmXeJRIar8yQD7P4Na3O1YsW{239^$w3@o|Hsl!@Yo!S zPWT=-EhCc>+o@{p5EIv=bGnhi5mCdEc*d@7635tmnu+tmVs}NZAWfK!P&tA2;f(n* z^3`y-*Ldfd2>t*k!3Iyt>OtWVC5FUVH_S(!P=^C5q8i1VI--eHUWt-H>RsPnv=K!-J@>s`J#pw8<+2IU{X zbuRrHv{PuW1)cyVU_y*Zttd>t9&Ok_+5lvk_{PZnZDF5H_Pq!#_)=oq zGr#-MhAlXj>%IA*X}Cn z>^I09hi;My#F%8D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C0e}{`&dfZSg3U}v6b^dx5?$xtd zd}pAjTNzM`)PT?U-g$(tz@}x>0{*UU7;1T!#^1asGMvMgje=&|6zMa}D?pxpk_yUXWb<7)3?cvrz2rBeOnVU8v}Ylxwn?;EK|)Siuj)c?ZsUlAI=S! zQ?(Qd4QWM9Ed{(v3+6As(tI|`Dj1~)|EJK@0xm$8`7a<`fb0%E#7vuiy8Mos0U^mhR&sgGjM>Q4{8f3c#g`xN^(u=*@gKw(ooMsaZ$uy$SUGu$B z-c5)3MtP5$;D+5dotxIaRY`Do(?Noxt~1%J$Z`R!i8q~tM2BR$)45P}#ooHaHTNZ_ z3-iTG4kz3jIN`3ED~)@SGi4o9R&_y7pG38MZLZw=@0IC(g+}MAUYatjp604|-wgF! zRZ>I`$fU9en^=VPpC_!iBfB#3ta_d`O;B|1#_N=j-MdEezghIZoveP0aI( z-{xHLA9Xc-_L)t~^ zJo$kxZ|mCCJ4YIIbFVLrREwS2jM&+4wAH<93M_&&bC3|Cnt%>G<5|r{fh@WN?*vbj|1F(F^|pEmxZI literal 0 HcmV?d00001 diff --git a/assets/Models/tree.j3odata b/assets/Models/tree.j3odata new file mode 100644 index 0000000..a05c058 --- /dev/null +++ b/assets/Models/tree.j3odata @@ -0,0 +1,3 @@ +# +#Fri Jan 20 22:43:12 CET 2017 +ORIGINAL_PATH=Models/tree.scene diff --git a/src/roadtrip/RoadTrip.java b/src/roadtrip/RoadTrip.java index 447b7a3..c57d35d 100644 --- a/src/roadtrip/RoadTrip.java +++ b/src/roadtrip/RoadTrip.java @@ -2,9 +2,7 @@ package roadtrip; import com.jme3.audio.AudioNode; import com.jme3.audio.AudioSource.Status; -import com.jme3.bullet.collision.shapes.BoxCollisionShape; -import com.jme3.bullet.collision.shapes.CompoundCollisionShape; -import com.jme3.bullet.collision.shapes.HeightfieldCollisionShape; +import com.jme3.bullet.collision.shapes.*; import com.jme3.bullet.control.BetterCharacterControl; import com.jme3.bullet.control.RigidBodyControl; import com.jme3.bullet.control.VehicleControl; @@ -15,12 +13,10 @@ import com.jme3.input.ChaseCamera; import com.jme3.input.KeyInput; import com.jme3.input.controls.ActionListener; import com.jme3.input.controls.KeyTrigger; +import com.jme3.light.AmbientLight; import com.jme3.light.DirectionalLight; import com.jme3.material.Material; -import com.jme3.math.ColorRGBA; -import com.jme3.math.FastMath; -import com.jme3.math.Quaternion; -import com.jme3.math.Vector3f; +import com.jme3.math.*; import com.jme3.renderer.queue.RenderQueue; import com.jme3.scene.Geometry; import com.jme3.scene.Node; @@ -28,8 +24,10 @@ import com.jme3.scene.Spatial; import com.jme3.scene.debug.Arrow; import com.jme3.scene.shape.Box; import com.jme3.scene.shape.Cylinder; +import com.jme3.terrain.geomipmap.TerrainGrid; import com.jme3.terrain.geomipmap.TerrainGridListener; import com.jme3.terrain.geomipmap.TerrainQuad; +import java.util.Random; import roadtrip.model.VehicleInstance; import roadtrip.view.CompassNode; import roadtrip.view.GameMenuNode; @@ -49,7 +47,7 @@ public class RoadTrip extends GameApplication implements ActionListener { app.start(); } - public static boolean DEBUG = false;//true; + public static boolean DEBUG = /*false;/*/true;/**/ private GameWorldState gameWorldState; private GameWorldView gameWorldView; @@ -73,6 +71,11 @@ public class RoadTrip extends GameApplication implements ActionListener { public void initializeGame() { super.initializeGame(); + bulletAppState.setDebugEnabled(DEBUG); + if (DEBUG) { + attachDebugStates(); + } + setupKeys(); //audioRenderer.setEnvironment(Environment.Dungeon); @@ -83,10 +86,14 @@ public class RoadTrip extends GameApplication implements ActionListener { dl.setColor(ColorRGBA.LightGray); dl.setDirection(new Vector3f(1, -1, 1)); rootNode.addLight(dl); + AmbientLight al = new AmbientLight(); + al.setColor(new ColorRGBA(0.5f, 0.5f, 0.5f, 1.0f)); + rootNode.addLight(al); gameWorldState = new GameWorldState(); gameWorldView = GameWorldView.create(gameWorldState, assetManager, cam, rootNode); - gameWorldView.terrain.terrainGrid.addListener(new TerrainGridListener() { + final TerrainGrid terrainGrid = gameWorldView.terrain.terrainGrid; + terrainGrid.addListener(new TerrainGridListener() { @Override public void gridMoved(Vector3f newCenter) { @@ -97,8 +104,41 @@ public class RoadTrip extends GameApplication implements ActionListener { while(quad.getControl(RigidBodyControl.class)!=null){ quad.removeControl(RigidBodyControl.class); } - quad.addControl(new RigidBodyControl(new HeightfieldCollisionShape(quad.getHeightMap(), gameWorldView.terrain.terrainGrid.getLocalScale()), 0)); + quad.addControl(new RigidBodyControl(new HeightfieldCollisionShape(quad.getHeightMap(), terrainGrid.getLocalScale()), 0)); getPhysicsSpace().add(quad); + + String treesKey = "trees-" + quad.getName(); + Spatial treesOld = rootNode.getChild(treesKey); + if (treesOld != null) { + getPhysicsSpace().removeAll(treesOld); + treesOld.removeFromParent(); + } + + Node trees = new Node(treesKey); + Random quadRand = new Random(treesKey.hashCode()); + Spatial treeModel = assetManager.loadModel("Models/tree.j3o"); + System.out.println("Grid @ " + terrainGrid.getLocalTranslation() + " s " + terrainGrid.getLocalScale()); + System.out.println("Quad " + quad.getName() + " @ " + quad.getLocalTranslation()); + float cellSize = terrainGrid.getPatchSize() * terrainGrid.getLocalScale().x * 2f; + for (int i = 0; i < quadRand.nextInt(1000); i++) { + Vector2f pos = new Vector2f((quadRand.nextFloat() - 0.5f) * cellSize, (quadRand.nextFloat() - 0.5f) * cellSize) + .addLocal(quad.getWorldTranslation().x, quad.getWorldTranslation().z); + float height = quad.getHeight(pos); + Vector3f location = new Vector3f(pos.x, height, pos.y) + .addLocal(terrainGrid.getWorldTranslation()); + System.out.println("Tree " + i + ": " + location); + Spatial treeInstance = treeModel.clone(); + treeInstance.setLocalTranslation(location); + //RigidBodyControl control = treeInstance.getControl(RigidBodyControl.class); + RigidBodyControl control = new RigidBodyControl(new ConeCollisionShape(1f, 5f), 0f); + if (control != null) { + treeInstance.addControl(control); + control.setPhysicsLocation(location); + getPhysicsSpace().add(control); + } + trees.attachChild(treeInstance); + } + rootNode.attachChild(trees); } @Override @@ -106,11 +146,15 @@ public class RoadTrip extends GameApplication implements ActionListener { if (quad.getControl(RigidBodyControl.class) != null) { getPhysicsSpace().remove(quad); quad.removeControl(RigidBodyControl.class); + String treesKey = "trees-" + quad.getName(); + Spatial trees = rootNode.getChild(treesKey); + getPhysicsSpace().removeAll(trees); + trees.removeFromParent(); } } }); - + addCar(); addCar(); addCar();