Search in sources :

Example 21 with Direction

use of com.jme3.terrain.geomipmap.picking.BresenhamYUpGridTracer.Direction in project jmonkeyengine by jMonkeyEngine.

the class TestWalkingChar method createLight.

private void createLight() {
    Vector3f direction = new Vector3f(-0.1f, -0.7f, -1).normalizeLocal();
    DirectionalLight dl = new DirectionalLight();
    dl.setDirection(direction);
    dl.setColor(new ColorRGBA(1f, 1f, 1f, 1.0f));
    rootNode.addLight(dl);
}
Also used : ColorRGBA(com.jme3.math.ColorRGBA) Vector3f(com.jme3.math.Vector3f) DirectionalLight(com.jme3.light.DirectionalLight)

Example 22 with Direction

use of com.jme3.terrain.geomipmap.picking.BresenhamYUpGridTracer.Direction in project jmonkeyengine by jMonkeyEngine.

the class TestMousePick method simpleUpdate.

@Override
public void simpleUpdate(float tpf) {
    Vector3f origin = cam.getWorldCoordinates(inputManager.getCursorPosition(), 0.0f);
    Vector3f direction = cam.getWorldCoordinates(inputManager.getCursorPosition(), 0.3f);
    direction.subtractLocal(origin).normalizeLocal();
    Ray ray = new Ray(origin, direction);
    CollisionResults results = new CollisionResults();
    shootables.collideWith(ray, results);
    //        }
    if (results.size() > 0) {
        CollisionResult closest = results.getClosestCollision();
        mark.setLocalTranslation(closest.getContactPoint());
        Quaternion q = new Quaternion();
        q.lookAt(closest.getContactNormal(), Vector3f.UNIT_Y);
        mark.setLocalRotation(q);
        rootNode.attachChild(mark);
    } else {
        rootNode.detachChild(mark);
    }
}
Also used : CollisionResult(com.jme3.collision.CollisionResult) CollisionResults(com.jme3.collision.CollisionResults) Quaternion(com.jme3.math.Quaternion) Vector3f(com.jme3.math.Vector3f) Ray(com.jme3.math.Ray)

Example 23 with Direction

use of com.jme3.terrain.geomipmap.picking.BresenhamYUpGridTracer.Direction in project jmonkeyengine by jMonkeyEngine.

the class SceneLoader method startElement.

@Override
public void startElement(String uri, String localName, String qName, Attributes attribs) throws SAXException {
    if (qName.equals("scene")) {
        if (elementStack.size() != 0) {
            throw new SAXException("dotScene parse error: 'scene' element must be the root XML element");
        }
        String version = attribs.getValue("formatVersion");
        if (version == null || (!version.equals("1.0.0") && !version.equals("1.0.1"))) {
            logger.log(Level.WARNING, "Unrecognized version number" + " in dotScene file: {0}", version);
        }
    } else if (qName.equals("nodes")) {
        if (root != null) {
            throw new SAXException("dotScene parse error: nodes element was specified twice");
        }
        if (sceneName == null) {
            root = new com.jme3.scene.Node("OgreDotScene" + (++sceneIdx));
        } else {
            root = new com.jme3.scene.Node(sceneName + "-scene_node");
        }
        node = root;
    } else if (qName.equals("externals")) {
        checkTopNode("scene");
    } else if (qName.equals("item")) {
        checkTopNode("externals");
    } else if (qName.equals("file")) {
        checkTopNode("item");
    // NOTE: This part of the file is ignored, it is parsed
    // by SceneMaterialLoader in the first pass.
    } else if (qName.equals("node")) {
        String curElement = elementStack.peek();
        if (!curElement.equals("node") && !curElement.equals("nodes")) {
            throw new SAXException("dotScene parse error: " + "node element can only appear under 'node' or 'nodes'");
        }
        parseNode(attribs);
    } else if (qName.equals("property")) {
        if (node != null) {
            String type = attribs.getValue("type");
            String name = attribs.getValue("name");
            String data = attribs.getValue("data");
            if (type.equals("BOOL")) {
                node.setUserData(name, Boolean.parseBoolean(data) || data.equals("1"));
            } else if (type.equals("FLOAT")) {
                node.setUserData(name, Float.parseFloat(data));
            } else if (type.equals("STRING")) {
                node.setUserData(name, data);
            } else if (type.equals("INT")) {
                node.setUserData(name, Integer.parseInt(data));
            }
        }
    } else if (qName.equals("entity")) {
        checkTopNode("node");
        parseEntity(attribs);
    } else if (qName.equals("camera")) {
        checkTopNode("node");
        parseCamera(attribs);
    } else if (qName.equals("clipping")) {
        checkTopNode("camera");
        parseCameraClipping(attribs);
    } else if (qName.equals("position")) {
        if (elementStack.peek().equals("node")) {
            node.setLocalTranslation(SAXUtil.parseVector3(attribs));
        } else if (elementStack.peek().equals("camera")) {
            cameraNode.setLocalTranslation(SAXUtil.parseVector3(attribs));
        }
    } else if (qName.equals("quaternion") || qName.equals("rotation")) {
        node.setLocalRotation(parseQuat(attribs));
    } else if (qName.equals("scale")) {
        node.setLocalScale(SAXUtil.parseVector3(attribs));
    } else if (qName.equals("light")) {
        parseLight(attribs);
    } else if (qName.equals("colourDiffuse") || qName.equals("colorDiffuse")) {
        if (elementStack.peek().equals("light")) {
            if (light != null) {
                light.setColor(parseColor(attribs));
            }
        } else {
            checkTopNode("environment");
        }
    } else if (qName.equals("colourAmbient") || qName.equals("colorAmbient")) {
        if (elementStack.peek().equals("environment")) {
            ColorRGBA color = parseColor(attribs);
            if (!color.equals(ColorRGBA.Black) && !color.equals(ColorRGBA.BlackNoAlpha)) {
                // Lets add an ambient light to the scene.
                AmbientLight al = new AmbientLight();
                al.setColor(color);
                root.addLight(al);
            }
        }
    } else if (qName.equals("normal") || qName.equals("direction")) {
        checkTopNode("light");
        parseLightNormal(attribs);
    } else if (qName.equals("lightAttenuation")) {
        parseLightAttenuation(attribs);
    } else if (qName.equals("spotLightRange") || qName.equals("lightRange")) {
        parseLightSpotLightRange(attribs);
    }
    elementStack.push(qName);
}
Also used : ColorRGBA(com.jme3.math.ColorRGBA) LightNode(com.jme3.scene.LightNode) CameraNode(com.jme3.scene.CameraNode) AmbientLight(com.jme3.light.AmbientLight) SAXException(org.xml.sax.SAXException)

Example 24 with Direction

use of com.jme3.terrain.geomipmap.picking.BresenhamYUpGridTracer.Direction in project jmonkeyengine by jMonkeyEngine.

the class BulletVehicleDebugControl method createVehicle.

private void createVehicle() {
    suspensionNode.detachAllChildren();
    for (int i = 0; i < body.getNumWheels(); i++) {
        VehicleWheel physicsVehicleWheel = body.getWheel(i);
        Vector3f location = physicsVehicleWheel.getLocation().clone();
        Vector3f direction = physicsVehicleWheel.getDirection().clone();
        Vector3f axle = physicsVehicleWheel.getAxle().clone();
        float restLength = physicsVehicleWheel.getRestLength();
        float radius = physicsVehicleWheel.getRadius();
        Arrow locArrow = new Arrow(location);
        Arrow axleArrow = new Arrow(axle.normalizeLocal().multLocal(0.3f));
        Arrow wheelArrow = new Arrow(direction.normalizeLocal().multLocal(radius));
        Arrow dirArrow = new Arrow(direction.normalizeLocal().multLocal(restLength));
        Geometry locGeom = new Geometry("WheelLocationDebugShape" + i, locArrow);
        Geometry dirGeom = new Geometry("WheelDirectionDebugShape" + i, dirArrow);
        Geometry axleGeom = new Geometry("WheelAxleDebugShape" + i, axleArrow);
        Geometry wheelGeom = new Geometry("WheelRadiusDebugShape" + i, wheelArrow);
        dirGeom.setLocalTranslation(location);
        axleGeom.setLocalTranslation(location.add(direction));
        wheelGeom.setLocalTranslation(location.add(direction));
        locGeom.setMaterial(debugAppState.DEBUG_MAGENTA);
        dirGeom.setMaterial(debugAppState.DEBUG_MAGENTA);
        axleGeom.setMaterial(debugAppState.DEBUG_MAGENTA);
        wheelGeom.setMaterial(debugAppState.DEBUG_MAGENTA);
        suspensionNode.attachChild(locGeom);
        suspensionNode.attachChild(dirGeom);
        suspensionNode.attachChild(axleGeom);
        suspensionNode.attachChild(wheelGeom);
    }
}
Also used : Arrow(com.jme3.scene.debug.Arrow) Geometry(com.jme3.scene.Geometry) VehicleWheel(com.jme3.bullet.objects.VehicleWheel) Vector3f(com.jme3.math.Vector3f)

Example 25 with Direction

use of com.jme3.terrain.geomipmap.picking.BresenhamYUpGridTracer.Direction 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)

Aggregations

Vector3f (com.jme3.math.Vector3f)26 TempVars (com.jme3.util.TempVars)19 CollisionResult (com.jme3.collision.CollisionResult)6 ColorRGBA (com.jme3.math.ColorRGBA)6 Quaternion (com.jme3.math.Quaternion)6 Geometry (com.jme3.scene.Geometry)4 CollisionResults (com.jme3.collision.CollisionResults)3 DirectionalLight (com.jme3.light.DirectionalLight)3 Ray (com.jme3.math.Ray)3 Vector2f (com.jme3.math.Vector2f)3 Renderer (com.jme3.renderer.Renderer)3 CameraNode (com.jme3.scene.CameraNode)3 Node (com.jme3.scene.Node)3 BoundingSphere (com.jme3.bounding.BoundingSphere)2 VehicleWheel (com.jme3.bullet.objects.VehicleWheel)2 InputCapsule (com.jme3.export.InputCapsule)2 OutputCapsule (com.jme3.export.OutputCapsule)2 AmbientLight (com.jme3.light.AmbientLight)2 Light (com.jme3.light.Light)2 PointLight (com.jme3.light.PointLight)2