Search in sources :

Example 91 with Vector2f

use of com.jme3.math.Vector2f in project jmonkeyengine by jMonkeyEngine.

the class TestPostFilters method setupFloor.

public void setupFloor() {
    Material mat = assetManager.loadMaterial("Textures/Terrain/BrickWall/BrickWall.j3m");
    Box floor = new Box(50, 1f, 50);
    TangentBinormalGenerator.generate(floor);
    floor.scaleTextureCoordinates(new Vector2f(5, 5));
    Geometry floorGeom = new Geometry("Floor", floor);
    floorGeom.setMaterial(mat);
    floorGeom.setShadowMode(ShadowMode.Receive);
    rootNode.attachChild(floorGeom);
}
Also used : Geometry(com.jme3.scene.Geometry) Material(com.jme3.material.Material) Box(com.jme3.scene.shape.Box)

Example 92 with Vector2f

use of com.jme3.math.Vector2f in project jmonkeyengine by jMonkeyEngine.

the class TerrainGridAlphaMapTest method updateMarkerElevations.

private void updateMarkerElevations() {
    for (Spatial s : markers.getChildren()) {
        float h = terrain.getHeight(new Vector2f(s.getLocalTranslation().x, s.getLocalTranslation().z));
        s.setLocalTranslation(s.getLocalTranslation().x, h + 1, s.getLocalTranslation().z);
    }
}
Also used : Spatial(com.jme3.scene.Spatial) Vector2f(com.jme3.math.Vector2f)

Example 93 with Vector2f

use of com.jme3.math.Vector2f in project jmonkeyengine by jMonkeyEngine.

the class TerrainTestModifyHeight method adjustHeight.

private void adjustHeight(Vector3f loc, float radius, float height) {
    // offset it by radius because in the loop we iterate through 2 radii
    int radiusStepsX = (int) (radius / terrain.getLocalScale().x);
    int radiusStepsZ = (int) (radius / terrain.getLocalScale().z);
    float xStepAmount = terrain.getLocalScale().x;
    float zStepAmount = terrain.getLocalScale().z;
    long start = System.currentTimeMillis();
    List<Vector2f> locs = new ArrayList<Vector2f>();
    List<Float> heights = new ArrayList<Float>();
    for (int z = -radiusStepsZ; z < radiusStepsZ; z++) {
        for (int x = -radiusStepsX; x < radiusStepsX; x++) {
            float locX = loc.x + (x * xStepAmount);
            float locZ = loc.z + (z * zStepAmount);
            if (isInRadius(locX - loc.x, locZ - loc.z, radius)) {
                // see if it is in the radius of the tool
                float h = calculateHeight(radius, height, locX - loc.x, locZ - loc.z);
                locs.add(new Vector2f(locX, locZ));
                heights.add(h);
            }
        }
    }
    terrain.adjustHeight(locs, heights);
    //System.out.println("Modified "+locs.size()+" points, took: " + (System.currentTimeMillis() - start)+" ms");
    terrain.updateModelBound();
}
Also used : Vector2f(com.jme3.math.Vector2f) ArrayList(java.util.ArrayList)

Example 94 with Vector2f

use of com.jme3.math.Vector2f in project jmonkeyengine by jMonkeyEngine.

the class TestSceneWater method simpleInitApp.

public void simpleInitApp() {
    this.flyCam.setMoveSpeed(10);
    Node mainScene = new Node();
    cam.setLocation(new Vector3f(-27.0f, 1.0f, 75.0f));
    cam.setRotation(new Quaternion(0.03f, 0.9f, 0f, 0.4f));
    // load sky
    mainScene.attachChild(SkyFactory.createSky(assetManager, "Textures/Sky/Bright/BrightSky.dds", false));
    File file = new File("wildhouse.zip");
    if (file.exists()) {
        useHttp = false;
    }
    // load the level from zip or http zip
    if (useHttp) {
        assetManager.registerLocator("https://storage.googleapis.com/google-code-archive-downloads/v2/code.google.com/jmonkeyengine/wildhouse.zip", HttpZipLocator.class);
    } else {
        assetManager.registerLocator("wildhouse.zip", ZipLocator.class);
    }
    Spatial scene = assetManager.loadModel("main.scene");
    DirectionalLight sun = new DirectionalLight();
    Vector3f lightDir = new Vector3f(-0.37352666f, -0.50444174f, -0.7784704f);
    sun.setDirection(lightDir);
    sun.setColor(ColorRGBA.White.clone().multLocal(2));
    scene.addLight(sun);
    Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    mat.setTexture("ColorMap", assetManager.loadTexture("Interface/Logo/Monkey.jpg"));
    //add lightPos Geometry
    Sphere lite = new Sphere(8, 8, 3.0f);
    Geometry lightSphere = new Geometry("lightsphere", lite);
    lightSphere.setMaterial(mat);
    Vector3f lightPos = lightDir.multLocal(-400);
    lightSphere.setLocalTranslation(lightPos);
    rootNode.attachChild(lightSphere);
    SimpleWaterProcessor waterProcessor = new SimpleWaterProcessor(assetManager);
    waterProcessor.setReflectionScene(mainScene);
    waterProcessor.setDebug(false);
    waterProcessor.setLightPosition(lightPos);
    waterProcessor.setRefractionClippingOffset(1.0f);
    //setting the water plane
    Vector3f waterLocation = new Vector3f(0, -20, 0);
    waterProcessor.setPlane(new Plane(Vector3f.UNIT_Y, waterLocation.dot(Vector3f.UNIT_Y)));
    WaterUI waterUi = new WaterUI(inputManager, waterProcessor);
    waterProcessor.setWaterColor(ColorRGBA.Brown);
    waterProcessor.setDebug(true);
    //lower render size for higher performance
    //        waterProcessor.setRenderSize(128,128);
    //raise depth to see through water
    //        waterProcessor.setWaterDepth(20);
    //lower the distortion scale if the waves appear too strong
    //        waterProcessor.setDistortionScale(0.1f);
    //lower the speed of the waves if they are too fast
    //        waterProcessor.setWaveSpeed(0.01f);
    Quad quad = new Quad(400, 400);
    //the texture coordinates define the general size of the waves
    quad.scaleTextureCoordinates(new Vector2f(6f, 6f));
    Geometry water = new Geometry("water", quad);
    water.setShadowMode(ShadowMode.Receive);
    water.setLocalRotation(new Quaternion().fromAngleAxis(-FastMath.HALF_PI, Vector3f.UNIT_X));
    water.setMaterial(waterProcessor.getMaterial());
    water.setLocalTranslation(-200, -20, 250);
    rootNode.attachChild(water);
    viewPort.addProcessor(waterProcessor);
    mainScene.attachChild(scene);
    rootNode.attachChild(mainScene);
}
Also used : Quad(com.jme3.scene.shape.Quad) Node(com.jme3.scene.Node) Material(com.jme3.material.Material) SimpleWaterProcessor(com.jme3.water.SimpleWaterProcessor) Sphere(com.jme3.scene.shape.Sphere) Geometry(com.jme3.scene.Geometry) Spatial(com.jme3.scene.Spatial) DirectionalLight(com.jme3.light.DirectionalLight) File(java.io.File)

Example 95 with Vector2f

use of com.jme3.math.Vector2f in project jmonkeyengine by jMonkeyEngine.

the class IosTouchHandler method actionMove.

public void actionMove(int pointerId, long time, float x, float y) {
    float jmeX = iosInput.getJmeX(x);
    float jmeY = iosInput.invertY(iosInput.getJmeY(y));
    Vector2f lastPos = lastPositions.get(pointerId);
    if (lastPos == null) {
        lastPos = new Vector2f(jmeX, jmeY);
        lastPositions.put(pointerId, lastPos);
    }
    float dX = jmeX - lastPos.x;
    float dY = jmeY - lastPos.y;
    if (dX != 0 || dY != 0) {
        TouchEvent touch = iosInput.getFreeTouchEvent();
        touch.set(TouchEvent.Type.MOVE, jmeX, jmeY, dX, dY);
        touch.setPointerId(pointerId);
        touch.setTime(time);
        touch.setPressure(1.0f);
        //touch.setPressure(event.getPressure(p));
        lastPos.set(jmeX, jmeY);
        processEvent(touch);
    }
}
Also used : Vector2f(com.jme3.math.Vector2f) TouchEvent(com.jme3.input.event.TouchEvent)

Aggregations

Vector2f (com.jme3.math.Vector2f)80 Vector3f (com.jme3.math.Vector3f)38 Geometry (com.jme3.scene.Geometry)22 Material (com.jme3.material.Material)20 Box (com.jme3.scene.shape.Box)17 ArrayList (java.util.ArrayList)14 Texture (com.jme3.texture.Texture)9 List (java.util.List)9 Node (com.jme3.scene.Node)8 Sphere (com.jme3.scene.shape.Sphere)8 FloatBuffer (java.nio.FloatBuffer)8 InputCapsule (com.jme3.export.InputCapsule)7 Spatial (com.jme3.scene.Spatial)7 DirectionalLight (com.jme3.light.DirectionalLight)6 Mesh (com.jme3.scene.Mesh)6 AmbientLight (com.jme3.light.AmbientLight)5 Quad (com.jme3.scene.shape.Quad)5 BoundingBox (com.jme3.bounding.BoundingBox)4 RigidBodyControl (com.jme3.bullet.control.RigidBodyControl)4 CollisionResult (com.jme3.collision.CollisionResult)4