diff --git a/ShootingStars/assets/Textures/Hex.jpg b/ShootingStars/assets/Textures/Hex.jpg new file mode 100644 index 0000000..53c1cf3 Binary files /dev/null and b/ShootingStars/assets/Textures/Hex.jpg differ diff --git a/ShootingStars/src/org/wyrez/shootingstars/ShootingStars.java b/ShootingStars/src/org/wyrez/shootingstars/ShootingStars.java index eaa8dab..c718ce0 100644 --- a/ShootingStars/src/org/wyrez/shootingstars/ShootingStars.java +++ b/ShootingStars/src/org/wyrez/shootingstars/ShootingStars.java @@ -21,6 +21,7 @@ import com.jme3.app.DebugKeysAppState; import com.jme3.app.SimpleApplication; import com.jme3.app.StatsAppState; import com.jme3.app.state.AppStateManager; +import com.jme3.math.Vector3f; import com.jme3.renderer.Camera; import com.jme3.scene.Node; import org.wyrez.persij.PersiJContainer; @@ -51,6 +52,8 @@ public class ShootingStars extends SimpleApplication { Materials.initialize(assetManager); cam.setFrustumFar(2500f); + //TODO debug + cam.setLocation(new Vector3f(0f, 2500f, 0f)); sManager = container.resolve(StateManager.class); sManager.setState(State.START); diff --git a/ShootingStars/src/org/wyrez/shootingstars/factories/Materials.java b/ShootingStars/src/org/wyrez/shootingstars/factories/Materials.java index 37091e7..d5d4d7d 100644 --- a/ShootingStars/src/org/wyrez/shootingstars/factories/Materials.java +++ b/ShootingStars/src/org/wyrez/shootingstars/factories/Materials.java @@ -25,7 +25,8 @@ import com.jme3.material.Material; */ public enum Materials { - UNSHADED("Common/MatDefs/Misc/Unshaded.j3md", null); + UNSHADED("Common/MatDefs/Misc/Unshaded.j3md", null), + HEX("Common/MatDefs/Light/Lighting.j3md", "Textures/Hex.jpg"); private static AssetManager assetManager; private String material; private String texture; @@ -37,10 +38,9 @@ public enum Materials { public Material create() { Material mat = new Material(assetManager, material); - //TODO load textures - //if (texture != null) { - //mat.setTexture("ColorMap", texture); - //} + if (texture != null) { + mat.setTexture("DiffuseMap", assetManager.loadTexture(texture)); + } return mat; } diff --git a/ShootingStars/src/org/wyrez/shootingstars/game/Ground.java b/ShootingStars/src/org/wyrez/shootingstars/game/Ground.java new file mode 100644 index 0000000..fcc8d14 --- /dev/null +++ b/ShootingStars/src/org/wyrez/shootingstars/game/Ground.java @@ -0,0 +1,92 @@ +/* + * Copyright (C) 2013 Darth Affe and contributors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package org.wyrez.shootingstars.game; + +import com.jme3.light.AmbientLight; +import com.jme3.material.Material; +import com.jme3.math.ColorRGBA; +import com.jme3.math.FastMath; +import com.jme3.math.Vector3f; +import com.jme3.scene.Geometry; +import com.jme3.scene.Node; +import org.wyrez.shootingstars.factories.Materials; +import org.wyrez.shootingstars.mesh.HexPrism; + +/** + * + * @author Darth Affe + */ +public class Ground extends Node { + + public Ground() { + this(1000f); + } + + public Ground(float radius) { + this(radius, 0.1f); + } + + public Ground(float radius, float factor) { + super("Ground"); + generateHexGrid(radius, factor); + addLight(); + } + + //TODO cleanup + private void generateHexGrid(float borderWidth, float factor) { + float size = borderWidth * factor; + int maxIterations = (int) (borderWidth / size) - 2; + + Material mat = Materials.HEX.create(); + Geometry geom = new Geometry("HexPrism" + 0 + " - " + 0, + new HexPrism(new Vector3f(0f, 0f, 0f), size, 10f)); + geom.setMaterial(mat); + this.attachChild(geom); + + float xcc = 0f; + float ycc = 0f; + float centerDistance = size * FastMath.sqrt(3f); + for (int iteration = 0; iteration < maxIterations; iteration++) { + float xc = xcc; + float yc = ycc - (float) iteration * centerDistance; + float dx = (FastMath.sqrt(3f) * centerDistance / 2f); + float dy = centerDistance / 2f; + + for (int directions = 0; directions < 6; directions++) { + for (int steps = 0; steps < iteration; steps++) { + geom = new Geometry("HexPrism" + xc + " - " + yc, + new HexPrism(new Vector3f(xc, 0f, yc), size, + (iteration == maxIterations - 1) ? 160f : 10f)); + geom.setMaterial(mat); + this.attachChild(geom); + xc = xc + dx; + yc = yc + dy; + } + float dxn = (FastMath.cos(FastMath.PI / 3f) * dx - FastMath.sin(FastMath.PI / 3f) * dy); + float dyn = (FastMath.sin(FastMath.PI / 3f) * dx + FastMath.cos(FastMath.PI / 3f) * dy); + dx = dxn; + dy = dyn; + } + } + } + + private void addLight() { + AmbientLight ambient = new AmbientLight(); + ambient.setColor(ColorRGBA.White); + this.addLight(ambient); + } +} diff --git a/ShootingStars/src/org/wyrez/shootingstars/states/GameState.java b/ShootingStars/src/org/wyrez/shootingstars/states/GameState.java index cbb2884..1419f3d 100644 --- a/ShootingStars/src/org/wyrez/shootingstars/states/GameState.java +++ b/ShootingStars/src/org/wyrez/shootingstars/states/GameState.java @@ -22,6 +22,7 @@ import com.jme3.app.state.AppStateManager; import com.jme3.renderer.RenderManager; import com.jme3.scene.Node; import org.wyrez.shootingstars.game.Cinema; +import org.wyrez.shootingstars.game.Ground; import org.wyrez.shootingstars.gui.GameGUI; import org.wyrez.shootingstars.gui.listener.GameListener; import tonegod.gui.core.Screen; @@ -36,6 +37,7 @@ public class GameState extends AbstractAppState implements GameListener { private Node rootNode; private GameGUI gui; private Cinema cinema; + private Ground ground; public GameState(Node rootNode, Screen screen, StateManager stateManager) { this.rootNode = rootNode; @@ -43,8 +45,13 @@ public class GameState extends AbstractAppState implements GameListener { this.stateManager = stateManager; } + public void loadGround() { + this.ground = new Ground(); + } + public void loadCinema() { this.cinema = new Cinema("Broken.mp4"); //TODO settings? + cinema.move(0f, 160f, 0f); } public void start() { @@ -56,6 +63,7 @@ public class GameState extends AbstractAppState implements GameListener { public void stateAttached(AppStateManager stateManager) { stateManager.attach(new FlyCamAppState()); //TODO debug rootNode.attachChild(cinema); + rootNode.attachChild(ground); gui.setWait(); gui.attach(); } @@ -64,6 +72,7 @@ public class GameState extends AbstractAppState implements GameListener { public void stateDetached(AppStateManager stateManager) { stateManager.detach(new FlyCamAppState()); //TODO debug gui.detach(); + rootNode.detachChild(ground); rootNode.detachChild(cinema); cinema.cleanup(); } diff --git a/ShootingStars/src/org/wyrez/shootingstars/states/LoadingState.java b/ShootingStars/src/org/wyrez/shootingstars/states/LoadingState.java index 1654bf3..001af2f 100644 --- a/ShootingStars/src/org/wyrez/shootingstars/states/LoadingState.java +++ b/ShootingStars/src/org/wyrez/shootingstars/states/LoadingState.java @@ -91,7 +91,8 @@ public class LoadingState extends AbstractAppState { } private void generateScene() { - //TODO fill + GameState gs = stateManager.getState(State.GAME); + gs.loadGround(); } public void done() {