Search in sources :

Example 11 with Plane

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

the class PhysicsTestHelper method createPhysicsTestWorldSoccer.

public static void createPhysicsTestWorldSoccer(Node rootNode, AssetManager assetManager, PhysicsSpace space) {
    AmbientLight light = new AmbientLight();
    light.setColor(ColorRGBA.LightGray);
    rootNode.addLight(light);
    Material material = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    material.setTexture("ColorMap", assetManager.loadTexture("Interface/Logo/Monkey.jpg"));
    Box floorBox = new Box(20, 0.25f, 20);
    Geometry floorGeometry = new Geometry("Floor", floorBox);
    floorGeometry.setMaterial(material);
    floorGeometry.setLocalTranslation(0, -0.25f, 0);
    //        Plane plane = new Plane();
    //        plane.setOriginNormal(new Vector3f(0, 0.25f, 0), Vector3f.UNIT_Y);
    //        floorGeometry.addControl(new RigidBodyControl(new PlaneCollisionShape(plane), 0));
    floorGeometry.addControl(new RigidBodyControl(0));
    rootNode.attachChild(floorGeometry);
    space.add(floorGeometry);
    //movable spheres
    for (int i = 0; i < 5; i++) {
        Sphere sphere = new Sphere(16, 16, .5f);
        Geometry ballGeometry = new Geometry("Soccer ball", sphere);
        ballGeometry.setMaterial(material);
        ballGeometry.setLocalTranslation(i, 2, -3);
        //RigidBodyControl automatically uses Sphere collision shapes when attached to single geometry with sphere mesh
        ballGeometry.addControl(new RigidBodyControl(.001f));
        ballGeometry.getControl(RigidBodyControl.class).setRestitution(1);
        rootNode.attachChild(ballGeometry);
        space.add(ballGeometry);
    }
    {
        //immovable Box with mesh collision shape
        Box box = new Box(1, 1, 1);
        Geometry boxGeometry = new Geometry("Box", box);
        boxGeometry.setMaterial(material);
        boxGeometry.setLocalTranslation(4, 1, 2);
        boxGeometry.addControl(new RigidBodyControl(new MeshCollisionShape(box), 0));
        rootNode.attachChild(boxGeometry);
        space.add(boxGeometry);
    }
    {
        //immovable Box with mesh collision shape
        Box box = new Box(1, 1, 1);
        Geometry boxGeometry = new Geometry("Box", box);
        boxGeometry.setMaterial(material);
        boxGeometry.setLocalTranslation(4, 3, 4);
        boxGeometry.addControl(new RigidBodyControl(new MeshCollisionShape(box), 0));
        rootNode.attachChild(boxGeometry);
        space.add(boxGeometry);
    }
}
Also used : Geometry(com.jme3.scene.Geometry) Sphere(com.jme3.scene.shape.Sphere) MeshCollisionShape(com.jme3.bullet.collision.shapes.MeshCollisionShape) Material(com.jme3.material.Material) Box(com.jme3.scene.shape.Box) RigidBodyControl(com.jme3.bullet.control.RigidBodyControl) AmbientLight(com.jme3.light.AmbientLight)

Example 12 with Plane

use of com.jme3.math.Plane in project chordatlas by twak.

the class Tweed method getSurfaceSelected.

private Vector3f getSurfaceSelected(float dist) {
    CollisionResult cr = getClicked();
    Vector3f pos = null;
    if (cr != null)
        pos = cr.getContactPoint();
    if (pos == null) {
        Vector3f dir = cam.getWorldCoordinates(getInputManager().getCursorPosition(), -dist);
        dir.subtractLocal(cam.getLocation());
        new Ray(cam.getLocation(), dir).intersectsWherePlane(new Plane(Jme3z.UP, 0), pos = new Vector3f());
    }
    return pos;
}
Also used : CollisionResult(com.jme3.collision.CollisionResult) Plane(com.jme3.math.Plane) Vector3f(com.jme3.math.Vector3f) Ray(com.jme3.math.Ray)

Example 13 with Plane

use of com.jme3.math.Plane in project chordatlas by twak.

the class PlaneTool method dragStart.

@Override
public void dragStart(Geometry target, Vector2f screen, Vector3f d3) {
    plane = new Plane(Color.white);
    plane.a = new Vector3f(d3.x, 0, d3.z);
    plane.b = null;
}
Also used : Plane(org.twak.tweed.gen.PlanesGen.Plane) Vector3f(com.jme3.math.Vector3f)

Example 14 with Plane

use of com.jme3.math.Plane in project chordatlas by twak.

the class PlanesGen method calculate.

@Override
public void calculate() {
    for (Spatial s : gNode.getChildren()) s.removeFromParent();
    for (Plane p : planes) {
        p.color = color;
        Spatial s = p.render(tweed);
        if (s == null)
            continue;
        s.setUserData(ClickMe.class.getSimpleName(), new Object[] { new ClickMe() {

            @Override
            public void clicked(Object data) {
                selected(p);
            }
        } });
        gNode.attachChild(s);
    }
    super.calculate();
}
Also used : ClickMe(org.twak.tweed.ClickMe) Spatial(com.jme3.scene.Spatial)

Example 15 with Plane

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

the class BoneEnvelope method isInEnvelope.

/**
     * The method verifies if the given point is inside the envelope.
     * @param point
     *            the point in 3D space (MUST be in a world coordinate space)
     * @return <b>true</b> if the point is inside the envelope and <b>false</b> otherwise
     */
public boolean isInEnvelope(Vector3f point) {
    Vector3f v = tail.subtract(head);
    float boneLength = v.length();
    v.normalizeLocal();
    // computing a plane that contains 'point' and v is its normal vector
    // the plane's equation is: Ax + By + Cz + D = 0, where v = [A, B, C]
    float D = -v.dot(point);
    // computing a point where a line that contains head and tail crosses the plane
    float temp = -(v.dot(head) + D) / v.dot(v);
    Vector3f p = head.add(v.x * temp, v.y * temp, v.z * temp);
    // determining if the point p is on the same or other side of head than the tail point
    Vector3f headToPointOnLineVector = p.subtract(head);
    float headToPointLength = headToPointOnLineVector.length();
    // the length of v is already = 1; cosinus should be either 1, 0 or -1
    float cosinus = headToPointOnLineVector.dot(v) / headToPointLength;
    if (cosinus < 0 && headToPointLength > boneHeadRadius || headToPointLength > boneLength + boneTailRadius) {
        // the point is outside the anvelope
        return false;
    }
    // now check if the point is inside and envelope
    float pointDistanceFromLine = point.subtract(p).length(), maximumDistance = 0;
    if (cosinus < 0) {
        // checking if the distance from p to point is inside the half sphere defined by head envelope
        // compute the distance from the line to the half sphere border
        maximumDistance = boneHeadRadius;
    } else if (headToPointLength < boneLength) {
        // compute the maximum available distance
        if (boneTailRadius > boneHeadRadius) {
            // compute the distance from head to p
            float headToPDistance = p.subtract(head).length();
            // from tangens function we have
            float x = headToPDistance * ((boneTailRadius - boneHeadRadius) / boneLength);
            maximumDistance = x + boneHeadRadius;
        } else if (boneTailRadius < boneHeadRadius) {
            // compute the distance from head to p
            float tailToPDistance = p.subtract(tail).length();
            // from tangens function we have
            float x = tailToPDistance * ((boneHeadRadius - boneTailRadius) / boneLength);
            maximumDistance = x + boneTailRadius;
        } else {
            maximumDistance = boneTailRadius;
        }
    } else {
        // checking if the distance from p to point is inside the half sphere defined by tail envelope
        maximumDistance = boneTailRadius;
    }
    return pointDistanceFromLine <= maximumDistance + distance;
}
Also used : Vector3f(com.jme3.math.Vector3f)

Aggregations

Vector3f (com.jme3.math.Vector3f)20 Plane (com.jme3.math.Plane)9 Sphere (com.jme3.scene.shape.Sphere)7 TempVars (com.jme3.util.TempVars)7 RigidBodyControl (com.jme3.bullet.control.RigidBodyControl)6 Material (com.jme3.material.Material)6 Geometry (com.jme3.scene.Geometry)6 Node (com.jme3.scene.Node)6 BulletAppState (com.jme3.bullet.BulletAppState)4 Quad (com.jme3.scene.shape.Quad)4 MeshCollisionShape (com.jme3.bullet.collision.shapes.MeshCollisionShape)3 Box (com.jme3.scene.shape.Box)3 CollisionResult (com.jme3.collision.CollisionResult)2 AmbientLight (com.jme3.light.AmbientLight)2 DirectionalLight (com.jme3.light.DirectionalLight)2 Triangle (com.jme3.math.Triangle)2 Camera (com.jme3.renderer.Camera)2 Spatial (com.jme3.scene.Spatial)2 Structure (com.jme3.scene.plugins.blender.file.Structure)2 Texture (com.jme3.texture.Texture)2