use of com.jme3.scene.Geometry in project jmonkeyengine by jMonkeyEngine.
the class RenderQueue method renderGeometryList.
private void renderGeometryList(GeometryList list, RenderManager rm, Camera cam, boolean clear) {
// select camera for sorting
list.setCamera(cam);
list.sort();
for (int i = 0; i < list.size(); i++) {
Geometry obj = list.get(i);
assert obj != null;
rm.renderGeometry(obj);
obj.queueDistance = Float.NEGATIVE_INFINITY;
}
if (clear) {
list.clear();
}
}
use of com.jme3.scene.Geometry in project jmonkeyengine by jMonkeyEngine.
the class LodControl method setSpatial.
@Override
public void setSpatial(Spatial spatial) {
if (!(spatial instanceof Geometry)) {
throw new IllegalArgumentException("LodControl can only be attached to Geometry!");
}
super.setSpatial(spatial);
Geometry geom = (Geometry) spatial;
Mesh mesh = geom.getMesh();
numLevels = mesh.getNumLodLevels();
numTris = new int[numLevels];
for (int i = numLevels - 1; i >= 0; i--) {
numTris[i] = mesh.getTriangleCount(i);
}
}
use of com.jme3.scene.Geometry in project jmonkeyengine by jMonkeyEngine.
the class CubeField method createFirstCube.
private Geometry createFirstCube() {
Vector3f loc = player.getLocalTranslation();
loc.addLocal(4, 0, 0);
Box b = new Box(1, 1, 1);
Geometry geom = new Geometry("Box", b);
geom.setLocalTranslation(loc);
Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
mat.setColor("Color", ColorRGBA.Blue);
geom.setMaterial(mat);
return geom;
}
use of com.jme3.scene.Geometry in project jmonkeyengine by jMonkeyEngine.
the class CubeField method randomizeCube.
/**
* Randomly Places a cube on the map between 30 and 90 paces away from player
*/
private void randomizeCube() {
Geometry cube = fcube.clone();
int playerX = (int) player.getLocalTranslation().getX();
int playerZ = (int) player.getLocalTranslation().getZ();
// float x = FastMath.nextRandomInt(playerX + difficulty + 10, playerX + difficulty + 150);
float x = FastMath.nextRandomInt(playerX + difficulty + 30, playerX + difficulty + 90);
float z = FastMath.nextRandomInt(playerZ - difficulty - 50, playerZ + difficulty + 50);
cube.getLocalTranslation().set(x, 0, z);
// playerX+difficulty+30,playerX+difficulty+90
Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
if (!solidBox) {
mat.getAdditionalRenderState().setWireframe(true);
}
mat.setColor("Color", obstacleColors.get(FastMath.nextRandomInt(0, obstacleColors.size() - 1)));
cube.setMaterial(mat);
rootNode.attachChild(cube);
cubeField.add(cube);
}
use of com.jme3.scene.Geometry in project jmonkeyengine by jMonkeyEngine.
the class CubeField method gameLogic.
/**
* Core Game Logic
*/
private void gameLogic(float tpf) {
//Subtract difficulty level in accordance to speed every 10 seconds
if (timer.getTimeInSeconds() >= coreTime2) {
coreTime2 = timer.getTimeInSeconds() + 10;
if (difficulty <= lowCap) {
difficulty = lowCap;
} else if (difficulty > lowCap) {
difficulty -= 5;
diffHelp += 1;
}
}
if (speed < .1f) {
speed += .000001f * tpf * fpsRate;
}
player.move(speed * tpf * fpsRate, 0, 0);
if (cubeField.size() > difficulty) {
cubeField.remove(0);
} else if (cubeField.size() != difficulty) {
randomizeCube();
}
if (cubeField.isEmpty()) {
requestClose(false);
} else {
for (int i = 0; i < cubeField.size(); i++) {
//better way to check collision
Geometry playerModel = (Geometry) player.getChild(0);
Geometry cubeModel = cubeField.get(i);
cubeModel.updateGeometricState();
BoundingVolume pVol = playerModel.getWorldBound();
BoundingVolume vVol = cubeModel.getWorldBound();
if (pVol.intersects(vVol)) {
gameLost();
return;
}
//Remove cube if 10 world units behind player
if (cubeField.get(i).getLocalTranslation().getX() + 10 < player.getLocalTranslation().getX()) {
cubeField.get(i).removeFromParent();
cubeField.remove(cubeField.get(i));
}
}
}
Score += fpsRate * tpf;
fpsScoreText.setText("Current Score: " + Score);
}
Aggregations