Search in sources :

Example 61 with Point

use of com.jme3.scene.plugins.blender.meshes.Point in project jmonkeyengine by jMonkeyEngine.

the class TestCameraMotionPath method simpleInitApp.

@Override
public void simpleInitApp() {
    createScene();
    cam.setLocation(new Vector3f(8.4399185f, 11.189463f, 14.267577f));
    camNode = new CameraNode("Motion cam", cam);
    camNode.setControlDir(ControlDirection.SpatialToCamera);
    camNode.setEnabled(false);
    path = new MotionPath();
    path.setCycle(true);
    path.addWayPoint(new Vector3f(20, 3, 0));
    path.addWayPoint(new Vector3f(0, 3, 20));
    path.addWayPoint(new Vector3f(-20, 3, 0));
    path.addWayPoint(new Vector3f(0, 3, -20));
    path.setCurveTension(0.83f);
    path.enableDebugShape(assetManager, rootNode);
    cameraMotionControl = new MotionEvent(camNode, path);
    cameraMotionControl.setLoopMode(LoopMode.Loop);
    //cameraMotionControl.setDuration(15f);
    cameraMotionControl.setLookAt(teapot.getWorldTranslation(), Vector3f.UNIT_Y);
    cameraMotionControl.setDirectionType(MotionEvent.Direction.LookAt);
    rootNode.attachChild(camNode);
    guiFont = assetManager.loadFont("Interface/Fonts/Default.fnt");
    final BitmapText wayPointsText = new BitmapText(guiFont, false);
    wayPointsText.setSize(guiFont.getCharSet().getRenderedSize());
    guiNode.attachChild(wayPointsText);
    path.addListener(new MotionPathListener() {

        public void onWayPointReach(MotionEvent control, int wayPointIndex) {
            if (path.getNbWayPoints() == wayPointIndex + 1) {
                wayPointsText.setText(control.getSpatial().getName() + " Finish!!! ");
            } else {
                wayPointsText.setText(control.getSpatial().getName() + " Reached way point " + wayPointIndex);
            }
            wayPointsText.setLocalTranslation((cam.getWidth() - wayPointsText.getLineWidth()) / 2, cam.getHeight(), 0);
        }
    });
    flyCam.setEnabled(false);
    chaser = new ChaseCamera(cam, teapot);
    chaser.registerWithInput(inputManager);
    chaser.setSmoothMotion(true);
    chaser.setMaxDistance(50);
    chaser.setDefaultDistance(50);
    initInputs();
}
Also used : MotionPathListener(com.jme3.cinematic.MotionPathListener) BitmapText(com.jme3.font.BitmapText) Vector3f(com.jme3.math.Vector3f) CameraNode(com.jme3.scene.CameraNode) ChaseCamera(com.jme3.input.ChaseCamera) MotionPath(com.jme3.cinematic.MotionPath) MotionEvent(com.jme3.cinematic.events.MotionEvent)

Example 62 with Point

use of com.jme3.scene.plugins.blender.meshes.Point in project jmonkeyengine by jMonkeyEngine.

the class TestConeVSFrustum method simpleUpdate.

@Override
public void simpleUpdate(float tpf) {
    TempVars vars = TempVars.get();
    boolean intersect = spotLight.intersectsFrustum(frustumCam, vars);
    if (intersect) {
        geom.getMaterial().setColor("Diffuse", ColorRGBA.Green);
    } else {
        geom.getMaterial().setColor("Diffuse", ColorRGBA.White);
    }
    Vector3f farPoint = vars.vect1.set(spotLight.getPosition()).addLocal(vars.vect2.set(spotLight.getDirection()).multLocal(spotLight.getSpotRange()));
    //computing the radius of the base disc
    float farRadius = (spotLight.getSpotRange() / FastMath.cos(spotLight.getSpotOuterAngle())) * FastMath.sin(spotLight.getSpotOuterAngle());
    //computing the projection direction : perpendicular to the light direction and coplanar with the direction vector and the normal vector
    Vector3f perpDirection = vars.vect2.set(spotLight.getDirection()).crossLocal(frustumCam.getWorldPlane(3).getNormal()).normalizeLocal().crossLocal(spotLight.getDirection());
    //projecting the far point on the base disc perimeter
    Vector3f projectedPoint = vars.vect3.set(farPoint).addLocal(perpDirection.multLocal(farRadius));
    vars.release();
//        boxGeo.setLocalTranslation(spotLight.getPosition());
//  boxGeo.setLocalTranslation(projectedPoint);
}
Also used : TempVars(com.jme3.util.TempVars)

Example 63 with Point

use of com.jme3.scene.plugins.blender.meshes.Point in project jmonkeyengine by jMonkeyEngine.

the class SceneLoader method parseLight.

private void parseLight(Attributes attribs) throws SAXException {
    if (node == null || node.getParent() == null) {
        throw new SAXException("dotScene parse error: light can only appear under a node");
    }
    checkTopNode("node");
    String lightType = parseString(attribs.getValue("type"), "point");
    if (lightType.equals("point")) {
        light = new PointLight();
    } else if (lightType.equals("directional") || lightType.equals("sun")) {
        light = new DirectionalLight();
        // Assuming "normal" property is not provided
        ((DirectionalLight) light).setDirection(Vector3f.UNIT_Z);
    } else if (lightType.equals("spotLight") || lightType.equals("spot")) {
        light = new SpotLight();
    } else if (lightType.equals("omni")) {
        // XXX: It doesn't seem any exporters actually emit this type?
        light = new AmbientLight();
    } else {
        logger.log(Level.WARNING, "No matching jME3 LightType found for OGRE LightType: {0}", lightType);
    }
    logger.log(Level.FINEST, "{0} created.", light);
    if (!parseBool(attribs.getValue("visible"), true)) {
    // set to disabled
    }
    // "attach" it to the parent of this node
    if (light != null) {
        node.getParent().addLight(light);
    }
}
Also used : DirectionalLight(com.jme3.light.DirectionalLight) PointLight(com.jme3.light.PointLight) SpotLight(com.jme3.light.SpotLight) AmbientLight(com.jme3.light.AmbientLight) SAXException(org.xml.sax.SAXException)

Example 64 with Point

use of com.jme3.scene.plugins.blender.meshes.Point in project jmonkeyengine by jMonkeyEngine.

the class TerrainQuad method getHeightmapHeight.

/**
     * This will just get the heightmap value at the supplied point,
     * not an interpolated (actual) height value.
     */
protected float getHeightmapHeight(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).getHeightmapHeight(col, row);
                } else if (spat instanceof TerrainPatch) {
                    return ((TerrainPatch) spat).getHeightmapHeight(col, row);
                }
            }
        }
    }
    return Float.NaN;
}
Also used : Spatial(com.jme3.scene.Spatial)

Example 65 with Point

use of com.jme3.scene.plugins.blender.meshes.Point in project jmonkeyengine by jMonkeyEngine.

the class BresenhamYUpGridTracer method startWalk.

public void startWalk(final Ray walkRay) {
    // store ray
    this.walkRay.set(walkRay);
    // simplify access to direction
    Vector3f direction = this.walkRay.getDirection();
    // Move start point to grid space
    Vector3f start = this.walkRay.getOrigin().subtract(gridOrigin);
    gridLocation.x = (int) (start.x / gridSpacing.x);
    gridLocation.y = (int) (start.z / gridSpacing.z);
    Vector3f ooDirection = new Vector3f(1.0f / direction.x, 1, 1.0f / direction.z);
    // Check which direction on the X world axis we are moving.
    if (direction.x > TOLERANCE) {
        distToNextXIntersection = ((gridLocation.x + 1) * gridSpacing.x - start.x) * ooDirection.x;
        distBetweenXIntersections = gridSpacing.x * ooDirection.x;
        stepXDirection = 1;
    } else if (direction.x < -TOLERANCE) {
        distToNextXIntersection = (start.x - (gridLocation.x * gridSpacing.x)) * -direction.x;
        distBetweenXIntersections = -gridSpacing.x * ooDirection.x;
        stepXDirection = -1;
    } else {
        distToNextXIntersection = Float.MAX_VALUE;
        distBetweenXIntersections = Float.MAX_VALUE;
        stepXDirection = 0;
    }
    // Check which direction on the Z world axis we are moving.
    if (direction.z > TOLERANCE) {
        distToNextZIntersection = ((gridLocation.y + 1) * gridSpacing.z - start.z) * ooDirection.z;
        distBetweenZIntersections = gridSpacing.z * ooDirection.z;
        stepZDirection = 1;
    } else if (direction.z < -TOLERANCE) {
        distToNextZIntersection = (start.z - (gridLocation.y * gridSpacing.z)) * -direction.z;
        distBetweenZIntersections = -gridSpacing.z * ooDirection.z;
        stepZDirection = -1;
    } else {
        distToNextZIntersection = Float.MAX_VALUE;
        distBetweenZIntersections = Float.MAX_VALUE;
        stepZDirection = 0;
    }
    // Reset some variables
    rayLocation.set(start);
    rayLength = 0.0f;
    stepDirection = Direction.None;
}
Also used : Vector3f(com.jme3.math.Vector3f)

Aggregations

Vector3f (com.jme3.math.Vector3f)27 TempVars (com.jme3.util.TempVars)19 FloatBuffer (java.nio.FloatBuffer)6 ColorRGBA (com.jme3.math.ColorRGBA)5 DirectionalLight (com.jme3.light.DirectionalLight)4 PointLight (com.jme3.light.PointLight)4 SpotLight (com.jme3.light.SpotLight)4 Quaternion (com.jme3.math.Quaternion)4 Spatial (com.jme3.scene.Spatial)4 ArrayList (java.util.ArrayList)4 CollisionResult (com.jme3.collision.CollisionResult)3 Light (com.jme3.light.Light)3 Triangle (com.jme3.math.Triangle)3 Vector2f (com.jme3.math.Vector2f)3 Geometry (com.jme3.scene.Geometry)3 Mesh (com.jme3.scene.Mesh)3 BoundingSphere (com.jme3.bounding.BoundingSphere)2 MotionPath (com.jme3.cinematic.MotionPath)2 MotionPathListener (com.jme3.cinematic.MotionPathListener)2 MotionEvent (com.jme3.cinematic.events.MotionEvent)2