Search in sources :

Example 66 with Vector2f

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

the class TestBatchNodeTower method simpleInitApp.

@Override
public void simpleInitApp() {
    timer = new NanoTimer();
    bulletAppState = new BulletAppState();
    bulletAppState.setThreadingType(BulletAppState.ThreadingType.PARALLEL);
    //   bulletAppState.setEnabled(false);
    stateManager.attach(bulletAppState);
    bullet = new Sphere(32, 32, 0.4f, true, false);
    bullet.setTextureMode(TextureMode.Projected);
    bulletCollisionShape = new SphereCollisionShape(0.4f);
    brick = new Box(brickWidth, brickHeight, brickDepth);
    brick.scaleTextureCoordinates(new Vector2f(1f, .5f));
    //bulletAppState.getPhysicsSpace().enableDebug(assetManager);
    initMaterial();
    initTower();
    initFloor();
    initCrossHairs();
    this.cam.setLocation(new Vector3f(0, 25f, 8f));
    cam.lookAt(Vector3f.ZERO, new Vector3f(0, 1, 0));
    cam.setFrustumFar(80);
    inputManager.addMapping("shoot", new MouseButtonTrigger(MouseInput.BUTTON_LEFT));
    inputManager.addListener(actionListener, "shoot");
    rootNode.setShadowMode(ShadowMode.Off);
    batchNode.batch();
    batchNode.setShadowMode(ShadowMode.CastAndReceive);
    rootNode.attachChild(batchNode);
    shadowRenderer = new DirectionalLightShadowFilter(assetManager, 1024, 2);
    DirectionalLight dl = new DirectionalLight();
    dl.setDirection(new Vector3f(-1, -1, -1).normalizeLocal());
    shadowRenderer.setLight(dl);
    shadowRenderer.setLambda(0.55f);
    shadowRenderer.setShadowIntensity(0.6f);
    shadowRenderer.setShadowCompareMode(CompareMode.Hardware);
    shadowRenderer.setEdgeFilteringMode(EdgeFilteringMode.PCF4);
    FilterPostProcessor fpp = new FilterPostProcessor(assetManager);
    fpp.addFilter(shadowRenderer);
    viewPort.addProcessor(fpp);
}
Also used : Sphere(com.jme3.scene.shape.Sphere) SphereCollisionShape(com.jme3.bullet.collision.shapes.SphereCollisionShape) NanoTimer(com.jme3.system.NanoTimer) Vector2f(com.jme3.math.Vector2f) BulletAppState(com.jme3.bullet.BulletAppState) Vector3f(com.jme3.math.Vector3f) DirectionalLight(com.jme3.light.DirectionalLight) Box(com.jme3.scene.shape.Box) FilterPostProcessor(com.jme3.post.FilterPostProcessor) MouseButtonTrigger(com.jme3.input.controls.MouseButtonTrigger) DirectionalLightShadowFilter(com.jme3.shadow.DirectionalLightShadowFilter)

Example 67 with Vector2f

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

the class TestBrickWall method initFloor.

public void initFloor() {
    Box floorBox = new Box(10f, 0.1f, 5f);
    floorBox.scaleTextureCoordinates(new Vector2f(3, 6));
    Geometry floor = new Geometry("floor", floorBox);
    floor.setMaterial(mat3);
    floor.setShadowMode(ShadowMode.Receive);
    floor.setLocalTranslation(0, -0.1f, 0);
    floor.addControl(new RigidBodyControl(new BoxCollisionShape(new Vector3f(10f, 0.1f, 5f)), 0));
    this.rootNode.attachChild(floor);
    this.getPhysicsSpace().add(floor);
}
Also used : Geometry(com.jme3.scene.Geometry) Vector2f(com.jme3.math.Vector2f) Vector3f(com.jme3.math.Vector3f) Box(com.jme3.scene.shape.Box) BoxCollisionShape(com.jme3.bullet.collision.shapes.BoxCollisionShape) RigidBodyControl(com.jme3.bullet.control.RigidBodyControl)

Example 68 with Vector2f

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

the class AndroidTouchInput method onTouch.

public boolean onTouch(MotionEvent event) {
    if (!isInitialized()) {
        return false;
    }
    boolean bWasHandled = false;
    TouchEvent touch = null;
    //    System.out.println("native : " + event.getAction());
    int action = getAction(event);
    int pointerIndex = getPointerIndex(event);
    int pointerId = getPointerId(event);
    Vector2f lastPos = lastPositions.get(pointerId);
    float jmeX;
    float jmeY;
    numPointers = event.getPointerCount();
    //final int pointerCount = event.getPointerCount();
    switch(getAction(event)) {
        case MotionEvent.ACTION_POINTER_DOWN:
        case MotionEvent.ACTION_DOWN:
            jmeX = getJmeX(event.getX(pointerIndex));
            jmeY = invertY(getJmeY(event.getY(pointerIndex)));
            touch = getFreeTouchEvent();
            touch.set(TouchEvent.Type.DOWN, jmeX, jmeY, 0, 0);
            touch.setPointerId(pointerId);
            touch.setTime(event.getEventTime());
            touch.setPressure(event.getPressure(pointerIndex));
            lastPos = new Vector2f(jmeX, jmeY);
            lastPositions.put(pointerId, lastPos);
            addEvent(touch);
            addEvent(generateMouseEvent(touch));
            bWasHandled = true;
            break;
        case MotionEvent.ACTION_POINTER_UP:
        case MotionEvent.ACTION_CANCEL:
        case MotionEvent.ACTION_UP:
            jmeX = getJmeX(event.getX(pointerIndex));
            jmeY = invertY(getJmeY(event.getY(pointerIndex)));
            touch = getFreeTouchEvent();
            touch.set(TouchEvent.Type.UP, jmeX, jmeY, 0, 0);
            touch.setPointerId(pointerId);
            touch.setTime(event.getEventTime());
            touch.setPressure(event.getPressure(pointerIndex));
            lastPositions.remove(pointerId);
            addEvent(touch);
            addEvent(generateMouseEvent(touch));
            bWasHandled = true;
            break;
        case MotionEvent.ACTION_MOVE:
            // Convert all pointers into events
            for (int p = 0; p < event.getPointerCount(); p++) {
                jmeX = getJmeX(event.getX(p));
                jmeY = invertY(getJmeY(event.getY(p)));
                lastPos = lastPositions.get(event.getPointerId(p));
                if (lastPos == null) {
                    lastPos = new Vector2f(jmeX, jmeY);
                    lastPositions.put(event.getPointerId(p), lastPos);
                }
                float dX = jmeX - lastPos.x;
                float dY = jmeY - lastPos.y;
                if (dX != 0 || dY != 0) {
                    touch = getFreeTouchEvent();
                    touch.set(TouchEvent.Type.MOVE, jmeX, jmeY, dX, dY);
                    touch.setPointerId(event.getPointerId(p));
                    touch.setTime(event.getEventTime());
                    touch.setPressure(event.getPressure(p));
                    lastPos.set(jmeX, jmeY);
                    addEvent(touch);
                    addEvent(generateMouseEvent(touch));
                    bWasHandled = true;
                }
            }
            break;
        case MotionEvent.ACTION_OUTSIDE:
            break;
    }
    // Try to detect gestures
    if (gestureDetector != null) {
        gestureDetector.onTouchEvent(event);
    }
    if (scaleDetector != null) {
        scaleDetector.onTouchEvent(event);
    }
    return bWasHandled;
}
Also used : Vector2f(com.jme3.math.Vector2f) TouchEvent(com.jme3.input.event.TouchEvent)

Example 69 with Vector2f

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

the class AndroidTouchInput14 method onHover.

public boolean onHover(MotionEvent event) {
    boolean consumed = false;
    int action = getAction(event);
    int pointerId = getPointerId(event);
    int pointerIndex = getPointerIndex(event);
    Vector2f lastPos = lastHoverPositions.get(pointerId);
    float jmeX;
    float jmeY;
    numPointers = event.getPointerCount();
    //        logger.log(Level.INFO, "onHover pointerId: {0}, action: {1}, x: {2}, y: {3}, numPointers: {4}",
    //                new Object[]{pointerId, action, event.getX(), event.getY(), event.getPointerCount()});
    TouchEvent touchEvent;
    switch(action) {
        case MotionEvent.ACTION_HOVER_ENTER:
            jmeX = getJmeX(event.getX(pointerIndex));
            jmeY = invertY(getJmeY(event.getY(pointerIndex)));
            touchEvent = getFreeTouchEvent();
            touchEvent.set(TouchEvent.Type.HOVER_START, jmeX, jmeY, 0, 0);
            touchEvent.setPointerId(pointerId);
            touchEvent.setTime(event.getEventTime());
            touchEvent.setPressure(event.getPressure(pointerIndex));
            lastPos = new Vector2f(jmeX, jmeY);
            lastHoverPositions.put(pointerId, lastPos);
            addEvent(touchEvent);
            consumed = true;
            break;
        case MotionEvent.ACTION_HOVER_MOVE:
            // Convert all pointers into events
            for (int p = 0; p < event.getPointerCount(); p++) {
                jmeX = getJmeX(event.getX(p));
                jmeY = invertY(getJmeY(event.getY(p)));
                lastPos = lastHoverPositions.get(event.getPointerId(p));
                if (lastPos == null) {
                    lastPos = new Vector2f(jmeX, jmeY);
                    lastHoverPositions.put(event.getPointerId(p), lastPos);
                }
                float dX = jmeX - lastPos.x;
                float dY = jmeY - lastPos.y;
                if (dX != 0 || dY != 0) {
                    touchEvent = getFreeTouchEvent();
                    touchEvent.set(TouchEvent.Type.HOVER_MOVE, jmeX, jmeY, dX, dY);
                    touchEvent.setPointerId(event.getPointerId(p));
                    touchEvent.setTime(event.getEventTime());
                    touchEvent.setPressure(event.getPressure(p));
                    lastPos.set(jmeX, jmeY);
                    addEvent(touchEvent);
                }
            }
            consumed = true;
            break;
        case MotionEvent.ACTION_HOVER_EXIT:
            jmeX = getJmeX(event.getX(pointerIndex));
            jmeY = invertY(getJmeY(event.getY(pointerIndex)));
            touchEvent = getFreeTouchEvent();
            touchEvent.set(TouchEvent.Type.HOVER_END, jmeX, jmeY, 0, 0);
            touchEvent.setPointerId(pointerId);
            touchEvent.setTime(event.getEventTime());
            touchEvent.setPressure(event.getPressure(pointerIndex));
            lastHoverPositions.remove(pointerId);
            addEvent(touchEvent);
            consumed = true;
            break;
        default:
            consumed = false;
            break;
    }
    return consumed;
}
Also used : Vector2f(com.jme3.math.Vector2f) TouchEvent(com.jme3.input.event.TouchEvent)

Example 70 with Vector2f

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

the class HDRRenderer method createLumShader.

private Material createLumShader(int srcW, int srcH, int bufW, int bufH, int mode, int iters, Texture tex) {
    Material mat = new Material(manager, "Common/MatDefs/Hdr/LogLum.j3md");
    Vector2f blockSize = new Vector2f(1f / bufW, 1f / bufH);
    Vector2f pixelSize = new Vector2f(1f / srcW, 1f / srcH);
    Vector2f blocks = new Vector2f();
    float numPixels = Float.POSITIVE_INFINITY;
    if (iters != -1) {
        do {
            pixelSize.multLocal(2);
            blocks.set(blockSize.x / pixelSize.x, blockSize.y / pixelSize.y);
            numPixels = blocks.x * blocks.y;
        } while (numPixels > iters);
    } else {
        blocks.set(blockSize.x / pixelSize.x, blockSize.y / pixelSize.y);
        numPixels = blocks.x * blocks.y;
    }
    mat.setBoolean("Blocks", true);
    if (mode == LUMMODE_ENCODE_LUM)
        mat.setBoolean("EncodeLum", true);
    else if (mode == LUMMODE_DECODE_LUM)
        mat.setBoolean("DecodeLum", true);
    mat.setTexture("Texture", tex);
    mat.setVector2("BlockSize", blockSize);
    mat.setVector2("PixelSize", pixelSize);
    mat.setFloat("NumPixels", numPixels);
    return mat;
}
Also used : Vector2f(com.jme3.math.Vector2f) Material(com.jme3.material.Material)

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