Search in sources :

Example 51 with Vector2f

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

the class TestTexture3DLoading method simpleInitApp.

@Override
public void simpleInitApp() {
    viewPort.setBackgroundColor(ColorRGBA.DarkGray);
    flyCam.setEnabled(false);
    Quad q = new Quad(10, 10);
    Geometry geom = new Geometry("Quad", q);
    Material material = new Material(assetManager, "jme3test/texture/tex3DThumb.j3md");
    TextureKey key = new TextureKey("Textures/3D/flame.dds");
    key.setGenerateMips(true);
    key.setTextureTypeHint(Texture.Type.ThreeDimensional);
    Texture t = assetManager.loadTexture(key);
    //4 * 4
    int rows = 4;
    q.scaleTextureCoordinates(new Vector2f(rows, rows));
    //The image only have 8 pictures and we have 16 thumbs, the data will be interpolated by the GPU
    material.setFloat("InvDepth", 1f / 16f);
    material.setInt("Rows", rows);
    material.setTexture("Texture", t);
    geom.setMaterial(material);
    rootNode.attachChild(geom);
    cam.setLocation(new Vector3f(4.7444625f, 5.160054f, 13.1939f));
}
Also used : Geometry(com.jme3.scene.Geometry) Quad(com.jme3.scene.shape.Quad) TextureKey(com.jme3.asset.TextureKey) Vector2f(com.jme3.math.Vector2f) Vector3f(com.jme3.math.Vector3f) Material(com.jme3.material.Material) Texture(com.jme3.texture.Texture)

Example 52 with Vector2f

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

the class TerrainTestModifyHeight method getWorldIntersection.

private Vector3f getWorldIntersection() {
    Vector3f origin = cam.getWorldCoordinates(new Vector2f(settings.getWidth() / 2, settings.getHeight() / 2), 0.0f);
    Vector3f direction = cam.getWorldCoordinates(new Vector2f(settings.getWidth() / 2, settings.getHeight() / 2), 0.3f);
    direction.subtractLocal(origin).normalizeLocal();
    Ray ray = new Ray(origin, direction);
    CollisionResults results = new CollisionResults();
    int numCollisions = terrain.collideWith(ray, results);
    if (numCollisions > 0) {
        CollisionResult hit = results.getClosestCollision();
        return hit.getContactPoint();
    }
    return null;
}
Also used : CollisionResult(com.jme3.collision.CollisionResult) CollisionResults(com.jme3.collision.CollisionResults) Vector2f(com.jme3.math.Vector2f) Vector3f(com.jme3.math.Vector3f) Ray(com.jme3.math.Ray)

Example 53 with Vector2f

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

the class TerrainTestModifyHeight method simpleUpdate.

@Override
public void simpleUpdate(float tpf) {
    Vector3f intersection = getWorldIntersection();
    updateHintText(intersection);
    if (raiseTerrain) {
        if (intersection != null) {
            adjustHeight(intersection, 64, tpf * 60);
        }
    } else if (lowerTerrain) {
        if (intersection != null) {
            adjustHeight(intersection, 64, -tpf * 60);
        }
    }
    if (terrain != null && intersection != null) {
        float h = terrain.getHeight(new Vector2f(intersection.x, intersection.z));
        Vector3f tl = terrain.getWorldTranslation();
        marker.setLocalTranslation(tl.add(new Vector3f(intersection.x, h, intersection.z)));
        markerNormal.setLocalTranslation(tl.add(new Vector3f(intersection.x, h, intersection.z)));
        Vector3f normal = terrain.getNormal(new Vector2f(intersection.x, intersection.z));
        ((Arrow) markerNormal.getMesh()).setArrowExtent(normal);
    }
}
Also used : Arrow(com.jme3.scene.debug.Arrow) Vector2f(com.jme3.math.Vector2f) Vector3f(com.jme3.math.Vector3f)

Example 54 with Vector2f

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

the class TerrainTestModifyHeight method calculateHeight.

private float calculateHeight(float radius, float heightFactor, float x, float z) {
    // find percentage for each 'unit' in radius
    Vector2f point = new Vector2f(x, z);
    float val = point.length() / radius;
    val = 1 - val;
    if (val <= 0) {
        val = 0;
    }
    return heightFactor * val;
}
Also used : Vector2f(com.jme3.math.Vector2f)

Example 55 with Vector2f

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

the class IosTouchHandler method actionDown.

public void actionDown(int pointerId, long time, float x, float y) {
    logger.log(Level.FINE, "Inject input pointer: {0}, time: {1}, x: {2}, y: {3}", new Object[] { pointerId, time, x, y });
    float jmeX = iosInput.getJmeX(x);
    float jmeY = iosInput.invertY(iosInput.getJmeY(y));
    TouchEvent touch = iosInput.getFreeTouchEvent();
    touch.set(TouchEvent.Type.DOWN, jmeX, jmeY, 0, 0);
    //TODO: pointer ID
    touch.setPointerId(pointerId);
    touch.setTime(time);
    touch.setPressure(1.0f);
    //touch.setPressure(event.getPressure(pointerIndex)); //TODO: preassure
    lastPositions.put(pointerId, new Vector2f(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