Search in sources :

Example 81 with Geometry

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();
    }
}
Also used : Geometry(com.jme3.scene.Geometry)

Example 82 with Geometry

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);
    }
}
Also used : Geometry(com.jme3.scene.Geometry) Mesh(com.jme3.scene.Mesh)

Example 83 with Geometry

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;
}
Also used : Geometry(com.jme3.scene.Geometry) Vector3f(com.jme3.math.Vector3f) Box(com.jme3.scene.shape.Box) Material(com.jme3.material.Material)

Example 84 with Geometry

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);
}
Also used : Geometry(com.jme3.scene.Geometry) Material(com.jme3.material.Material)

Example 85 with Geometry

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);
}
Also used : Geometry(com.jme3.scene.Geometry) BoundingVolume(com.jme3.bounding.BoundingVolume)

Aggregations

Geometry (com.jme3.scene.Geometry)246 Material (com.jme3.material.Material)175 Vector3f (com.jme3.math.Vector3f)116 Box (com.jme3.scene.shape.Box)92 DirectionalLight (com.jme3.light.DirectionalLight)56 Node (com.jme3.scene.Node)54 Sphere (com.jme3.scene.shape.Sphere)49 Spatial (com.jme3.scene.Spatial)41 Quaternion (com.jme3.math.Quaternion)39 Quad (com.jme3.scene.shape.Quad)33 Texture (com.jme3.texture.Texture)30 RigidBodyControl (com.jme3.bullet.control.RigidBodyControl)26 Mesh (com.jme3.scene.Mesh)25 KeyTrigger (com.jme3.input.controls.KeyTrigger)24 AmbientLight (com.jme3.light.AmbientLight)24 ColorRGBA (com.jme3.math.ColorRGBA)21 FilterPostProcessor (com.jme3.post.FilterPostProcessor)21 PointLight (com.jme3.light.PointLight)20 Vector2f (com.jme3.math.Vector2f)17 FloatBuffer (java.nio.FloatBuffer)17