added Ground
This commit is contained in:
parent
7879750ca7
commit
e30b9c352e
BIN
ShootingStars/assets/Textures/Hex.jpg
Normal file
BIN
ShootingStars/assets/Textures/Hex.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 22 KiB |
@ -21,6 +21,7 @@ import com.jme3.app.DebugKeysAppState;
|
|||||||
import com.jme3.app.SimpleApplication;
|
import com.jme3.app.SimpleApplication;
|
||||||
import com.jme3.app.StatsAppState;
|
import com.jme3.app.StatsAppState;
|
||||||
import com.jme3.app.state.AppStateManager;
|
import com.jme3.app.state.AppStateManager;
|
||||||
|
import com.jme3.math.Vector3f;
|
||||||
import com.jme3.renderer.Camera;
|
import com.jme3.renderer.Camera;
|
||||||
import com.jme3.scene.Node;
|
import com.jme3.scene.Node;
|
||||||
import org.wyrez.persij.PersiJContainer;
|
import org.wyrez.persij.PersiJContainer;
|
||||||
@ -51,6 +52,8 @@ public class ShootingStars extends SimpleApplication {
|
|||||||
|
|
||||||
Materials.initialize(assetManager);
|
Materials.initialize(assetManager);
|
||||||
cam.setFrustumFar(2500f);
|
cam.setFrustumFar(2500f);
|
||||||
|
//TODO debug
|
||||||
|
cam.setLocation(new Vector3f(0f, 2500f, 0f));
|
||||||
|
|
||||||
sManager = container.resolve(StateManager.class);
|
sManager = container.resolve(StateManager.class);
|
||||||
sManager.setState(State.START);
|
sManager.setState(State.START);
|
||||||
|
|||||||
@ -25,7 +25,8 @@ import com.jme3.material.Material;
|
|||||||
*/
|
*/
|
||||||
public enum Materials {
|
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 static AssetManager assetManager;
|
||||||
private String material;
|
private String material;
|
||||||
private String texture;
|
private String texture;
|
||||||
@ -37,10 +38,9 @@ public enum Materials {
|
|||||||
|
|
||||||
public Material create() {
|
public Material create() {
|
||||||
Material mat = new Material(assetManager, material);
|
Material mat = new Material(assetManager, material);
|
||||||
//TODO load textures
|
if (texture != null) {
|
||||||
//if (texture != null) {
|
mat.setTexture("DiffuseMap", assetManager.loadTexture(texture));
|
||||||
//mat.setTexture("ColorMap", texture);
|
}
|
||||||
//}
|
|
||||||
return mat;
|
return mat;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
92
ShootingStars/src/org/wyrez/shootingstars/game/Ground.java
Normal file
92
ShootingStars/src/org/wyrez/shootingstars/game/Ground.java
Normal file
@ -0,0 +1,92 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2013 Darth Affe <http://wyrez.org> 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 <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -22,6 +22,7 @@ import com.jme3.app.state.AppStateManager;
|
|||||||
import com.jme3.renderer.RenderManager;
|
import com.jme3.renderer.RenderManager;
|
||||||
import com.jme3.scene.Node;
|
import com.jme3.scene.Node;
|
||||||
import org.wyrez.shootingstars.game.Cinema;
|
import org.wyrez.shootingstars.game.Cinema;
|
||||||
|
import org.wyrez.shootingstars.game.Ground;
|
||||||
import org.wyrez.shootingstars.gui.GameGUI;
|
import org.wyrez.shootingstars.gui.GameGUI;
|
||||||
import org.wyrez.shootingstars.gui.listener.GameListener;
|
import org.wyrez.shootingstars.gui.listener.GameListener;
|
||||||
import tonegod.gui.core.Screen;
|
import tonegod.gui.core.Screen;
|
||||||
@ -36,6 +37,7 @@ public class GameState extends AbstractAppState implements GameListener {
|
|||||||
private Node rootNode;
|
private Node rootNode;
|
||||||
private GameGUI gui;
|
private GameGUI gui;
|
||||||
private Cinema cinema;
|
private Cinema cinema;
|
||||||
|
private Ground ground;
|
||||||
|
|
||||||
public GameState(Node rootNode, Screen screen, StateManager stateManager) {
|
public GameState(Node rootNode, Screen screen, StateManager stateManager) {
|
||||||
this.rootNode = rootNode;
|
this.rootNode = rootNode;
|
||||||
@ -43,8 +45,13 @@ public class GameState extends AbstractAppState implements GameListener {
|
|||||||
this.stateManager = stateManager;
|
this.stateManager = stateManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void loadGround() {
|
||||||
|
this.ground = new Ground();
|
||||||
|
}
|
||||||
|
|
||||||
public void loadCinema() {
|
public void loadCinema() {
|
||||||
this.cinema = new Cinema("Broken.mp4"); //TODO settings?
|
this.cinema = new Cinema("Broken.mp4"); //TODO settings?
|
||||||
|
cinema.move(0f, 160f, 0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void start() {
|
public void start() {
|
||||||
@ -56,6 +63,7 @@ public class GameState extends AbstractAppState implements GameListener {
|
|||||||
public void stateAttached(AppStateManager stateManager) {
|
public void stateAttached(AppStateManager stateManager) {
|
||||||
stateManager.attach(new FlyCamAppState()); //TODO debug
|
stateManager.attach(new FlyCamAppState()); //TODO debug
|
||||||
rootNode.attachChild(cinema);
|
rootNode.attachChild(cinema);
|
||||||
|
rootNode.attachChild(ground);
|
||||||
gui.setWait();
|
gui.setWait();
|
||||||
gui.attach();
|
gui.attach();
|
||||||
}
|
}
|
||||||
@ -64,6 +72,7 @@ public class GameState extends AbstractAppState implements GameListener {
|
|||||||
public void stateDetached(AppStateManager stateManager) {
|
public void stateDetached(AppStateManager stateManager) {
|
||||||
stateManager.detach(new FlyCamAppState()); //TODO debug
|
stateManager.detach(new FlyCamAppState()); //TODO debug
|
||||||
gui.detach();
|
gui.detach();
|
||||||
|
rootNode.detachChild(ground);
|
||||||
rootNode.detachChild(cinema);
|
rootNode.detachChild(cinema);
|
||||||
cinema.cleanup();
|
cinema.cleanup();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -91,7 +91,8 @@ public class LoadingState extends AbstractAppState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void generateScene() {
|
private void generateScene() {
|
||||||
//TODO fill
|
GameState gs = stateManager.getState(State.GAME);
|
||||||
|
gs.loadGround();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void done() {
|
public void done() {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user