Search in sources :

Example 16 with Quad

use of com.jme3.scene.shape.Quad in project jmonkeyengine by jMonkeyEngine.

the class TestChaseCamera method simpleInitApp.

public void simpleInitApp() {
    // Load a teapot model
    teaGeom = (Geometry) assetManager.loadModel("Models/Teapot/Teapot.obj");
    Material mat_tea = new Material(assetManager, "Common/MatDefs/Misc/ShowNormals.j3md");
    teaGeom.setMaterial(mat_tea);
    rootNode.attachChild(teaGeom);
    // Load a floor model
    Material mat_ground = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    mat_ground.setTexture("ColorMap", assetManager.loadTexture("Interface/Logo/Monkey.jpg"));
    Geometry ground = new Geometry("ground", new Quad(50, 50));
    ground.setLocalRotation(new Quaternion().fromAngleAxis(-FastMath.HALF_PI, Vector3f.UNIT_X));
    ground.setLocalTranslation(-25, -1, 25);
    ground.setMaterial(mat_ground);
    rootNode.attachChild(ground);
    // Disable the default first-person cam!
    flyCam.setEnabled(false);
    // Enable a chase cam
    chaseCam = new ChaseCamera(cam, teaGeom, inputManager);
    //Uncomment this to invert the camera's vertical rotation Axis 
    //chaseCam.setInvertVerticalAxis(true);
    //Uncomment this to invert the camera's horizontal rotation Axis
    //chaseCam.setInvertHorizontalAxis(true);
    //Comment this to disable smooth camera motion
    chaseCam.setSmoothMotion(true);
    //Uncomment this to disable trailing of the camera 
    //WARNING, trailing only works with smooth motion enabled. It is true by default.
    //chaseCam.setTrailingEnabled(false);
    //Uncomment this to look 3 world units above the target
    //chaseCam.setLookAtOffset(Vector3f.UNIT_Y.mult(3));
    //Uncomment this to enable rotation when the middle mouse button is pressed (like Blender)
    //WARNING : setting this trigger disable the rotation on right and left mouse button click
    //chaseCam.setToggleRotationTrigger(new MouseButtonTrigger(MouseInput.BUTTON_MIDDLE));
    //Uncomment this to set mutiple triggers to enable rotation of the cam
    //Here spade bar and middle mouse button
    //chaseCam.setToggleRotationTrigger(new MouseButtonTrigger(MouseInput.BUTTON_MIDDLE),new KeyTrigger(KeyInput.KEY_SPACE));
    //registering inputs for target's movement
    registerInput();
}
Also used : Geometry(com.jme3.scene.Geometry) Quad(com.jme3.scene.shape.Quad) Quaternion(com.jme3.math.Quaternion) ChaseCamera(com.jme3.input.ChaseCamera) Material(com.jme3.material.Material)

Example 17 with Quad

use of com.jme3.scene.shape.Quad in project jmonkeyengine by jMonkeyEngine.

the class TerrainQuad method getMeshNormal.

protected Vector3f getMeshNormal(int x, int z) {
    int quad = findQuadrant(x, z);
    int split = (size + 1) >> 1;
    if (children != null) {
        for (int i = children.size(); --i >= 0; ) {
            Spatial spat = children.get(i);
            int col = x;
            int row = z;
            boolean match = false;
            // get the childs quadrant
            int childQuadrant = 0;
            if (spat instanceof TerrainQuad) {
                childQuadrant = ((TerrainQuad) spat).getQuadrant();
            } else if (spat instanceof TerrainPatch) {
                childQuadrant = ((TerrainPatch) spat).getQuadrant();
            }
            if (childQuadrant == 1 && (quad & 1) != 0) {
                match = true;
            } else if (childQuadrant == 2 && (quad & 2) != 0) {
                row = z - split + 1;
                match = true;
            } else if (childQuadrant == 3 && (quad & 4) != 0) {
                col = x - split + 1;
                match = true;
            } else if (childQuadrant == 4 && (quad & 8) != 0) {
                col = x - split + 1;
                row = z - split + 1;
                match = true;
            }
            if (match) {
                if (spat instanceof TerrainQuad) {
                    return ((TerrainQuad) spat).getMeshNormal(col, row);
                } else if (spat instanceof TerrainPatch) {
                    return ((TerrainPatch) spat).getMeshNormal(col, row);
                }
            }
        }
    }
    return null;
}
Also used : Spatial(com.jme3.scene.Spatial)

Example 18 with Quad

use of com.jme3.scene.shape.Quad in project jmonkeyengine by jMonkeyEngine.

the class TerrainQuad method setHeight.

protected void setHeight(List<LocationHeight> locations, boolean overrideHeight) {
    if (children == null)
        return;
    List<LocationHeight> quadLH1 = new ArrayList<LocationHeight>();
    List<LocationHeight> quadLH2 = new ArrayList<LocationHeight>();
    List<LocationHeight> quadLH3 = new ArrayList<LocationHeight>();
    List<LocationHeight> quadLH4 = new ArrayList<LocationHeight>();
    Spatial quad1 = null;
    Spatial quad2 = null;
    Spatial quad3 = null;
    Spatial quad4 = null;
    // get the child quadrants
    for (int i = children.size(); --i >= 0; ) {
        Spatial spat = children.get(i);
        int childQuadrant = 0;
        if (spat instanceof TerrainQuad) {
            childQuadrant = ((TerrainQuad) spat).getQuadrant();
        } else if (spat instanceof TerrainPatch) {
            childQuadrant = ((TerrainPatch) spat).getQuadrant();
        }
        if (childQuadrant == 1)
            quad1 = spat;
        else if (childQuadrant == 2)
            quad2 = spat;
        else if (childQuadrant == 3)
            quad3 = spat;
        else if (childQuadrant == 4)
            quad4 = spat;
    }
    int split = (size + 1) >> 1;
    // distribute each locationHeight into the quadrant it intersects
    for (LocationHeight lh : locations) {
        int quad = findQuadrant(lh.x, lh.z);
        int col = lh.x;
        int row = lh.z;
        if ((quad & 1) != 0) {
            quadLH1.add(lh);
        }
        if ((quad & 2) != 0) {
            row = lh.z - split + 1;
            quadLH2.add(new LocationHeight(lh.x, row, lh.h));
        }
        if ((quad & 4) != 0) {
            col = lh.x - split + 1;
            quadLH3.add(new LocationHeight(col, lh.z, lh.h));
        }
        if ((quad & 8) != 0) {
            col = lh.x - split + 1;
            row = lh.z - split + 1;
            quadLH4.add(new LocationHeight(col, row, lh.h));
        }
    }
    // send the locations to the children
    if (!quadLH1.isEmpty()) {
        if (quad1 instanceof TerrainQuad)
            ((TerrainQuad) quad1).setHeight(quadLH1, overrideHeight);
        else if (quad1 instanceof TerrainPatch)
            ((TerrainPatch) quad1).setHeight(quadLH1, overrideHeight);
    }
    if (!quadLH2.isEmpty()) {
        if (quad2 instanceof TerrainQuad)
            ((TerrainQuad) quad2).setHeight(quadLH2, overrideHeight);
        else if (quad2 instanceof TerrainPatch)
            ((TerrainPatch) quad2).setHeight(quadLH2, overrideHeight);
    }
    if (!quadLH3.isEmpty()) {
        if (quad3 instanceof TerrainQuad)
            ((TerrainQuad) quad3).setHeight(quadLH3, overrideHeight);
        else if (quad3 instanceof TerrainPatch)
            ((TerrainPatch) quad3).setHeight(quadLH3, overrideHeight);
    }
    if (!quadLH4.isEmpty()) {
        if (quad4 instanceof TerrainQuad)
            ((TerrainQuad) quad4).setHeight(quadLH4, overrideHeight);
        else if (quad4 instanceof TerrainPatch)
            ((TerrainPatch) quad4).setHeight(quadLH4, overrideHeight);
    }
}
Also used : Spatial(com.jme3.scene.Spatial) ArrayList(java.util.ArrayList)

Example 19 with Quad

use of com.jme3.scene.shape.Quad in project jmonkeyengine by jMonkeyEngine.

the class ImageTileLoader method getTerrainQuadAt.

public TerrainQuad getTerrainQuadAt(Vector3f location) {
    HeightMap heightMapAt = getHeightMapAt(location);
    TerrainQuad q = new TerrainQuad("Quad" + location, patchSize, quadSize, heightMapAt == null ? null : heightMapAt.getHeightMap());
    return q;
}
Also used : TerrainQuad(com.jme3.terrain.geomipmap.TerrainQuad)

Example 20 with Quad

use of com.jme3.scene.shape.Quad in project jmonkeyengine by jMonkeyEngine.

the class HDRRenderer method initialize.

public void initialize(RenderManager rm, ViewPort vp) {
    if (!enabled)
        return;
    renderer = rm.getRenderer();
    renderManager = rm;
    viewPort = vp;
    // loadInitial()
    fsQuad = new Picture("HDR Fullscreen Quad");
    Format lumFmt = Format.RGB8;
    scene64FB = new FrameBuffer(64, 64, 1);
    scene64 = new Texture2D(64, 64, lumFmt);
    scene64FB.setColorTexture(scene64);
    scene64.setMagFilter(fbMagFilter);
    scene64.setMinFilter(fbMinFilter);
    scene8FB = new FrameBuffer(8, 8, 1);
    scene8 = new Texture2D(8, 8, lumFmt);
    scene8FB.setColorTexture(scene8);
    scene8.setMagFilter(fbMagFilter);
    scene8.setMinFilter(fbMinFilter);
    scene1FB[0] = new FrameBuffer(1, 1, 1);
    scene1[0] = new Texture2D(1, 1, lumFmt);
    scene1FB[0].setColorTexture(scene1[0]);
    scene1FB[1] = new FrameBuffer(1, 1, 1);
    scene1[1] = new Texture2D(1, 1, lumFmt);
    scene1FB[1].setColorTexture(scene1[1]);
    // prepare tonemap shader
    tone = new Material(manager, "Common/MatDefs/Hdr/ToneMap.j3md");
    tone.setFloat("A", 0.18f);
    tone.setFloat("White", 100);
    // load();
    int w = vp.getCamera().getWidth();
    int h = vp.getCamera().getHeight();
    reshape(vp, w, h);
}
Also used : Texture2D(com.jme3.texture.Texture2D) Format(com.jme3.texture.Image.Format) Picture(com.jme3.ui.Picture) Material(com.jme3.material.Material) FrameBuffer(com.jme3.texture.FrameBuffer)

Aggregations

Geometry (com.jme3.scene.Geometry)36 Quad (com.jme3.scene.shape.Quad)35 Material (com.jme3.material.Material)30 Vector3f (com.jme3.math.Vector3f)23 Node (com.jme3.scene.Node)11 Spatial (com.jme3.scene.Spatial)10 DirectionalLight (com.jme3.light.DirectionalLight)9 Quaternion (com.jme3.math.Quaternion)9 Texture (com.jme3.texture.Texture)9 TerrainQuad (com.jme3.terrain.geomipmap.TerrainQuad)7 ColorRGBA (com.jme3.math.ColorRGBA)6 Vector2f (com.jme3.math.Vector2f)6 AmbientLight (com.jme3.light.AmbientLight)5 Mesh (com.jme3.scene.Mesh)5 Texture2D (com.jme3.texture.Texture2D)5 Picture (com.jme3.ui.Picture)5 File (java.io.File)5 ScreenshotAppState (com.jme3.app.state.ScreenshotAppState)4 BulletAppState (com.jme3.bullet.BulletAppState)4 CapsuleCollisionShape (com.jme3.bullet.collision.shapes.CapsuleCollisionShape)4