Search in sources :

Example 51 with Box

use of com.jme3.scene.shape.Box in project jmonkeyengine by jMonkeyEngine.

the class TestBrickWall method simpleInitApp.

@Override
public void simpleInitApp() {
    bulletAppState = new BulletAppState();
    bulletAppState.setThreadingType(BulletAppState.ThreadingType.PARALLEL);
    stateManager.attach(bulletAppState);
    bullet = new Sphere(32, 32, 0.4f, true, false);
    bullet.setTextureMode(TextureMode.Projected);
    bulletCollisionShape = new SphereCollisionShape(0.4f);
    brick = new Box(bLength, bHeight, bWidth);
    brick.scaleTextureCoordinates(new Vector2f(1f, .5f));
    initMaterial();
    initWall();
    initFloor();
    initCrossHairs();
    this.cam.setLocation(new Vector3f(0, 6f, 6f));
    cam.lookAt(Vector3f.ZERO, new Vector3f(0, 1, 0));
    cam.setFrustumFar(15);
    inputManager.addMapping("shoot", new MouseButtonTrigger(MouseInput.BUTTON_LEFT));
    inputManager.addListener(actionListener, "shoot");
    inputManager.addMapping("gc", new KeyTrigger(KeyInput.KEY_X));
    inputManager.addListener(actionListener, "gc");
    rootNode.setShadowMode(ShadowMode.Off);
    bsr = new BasicShadowRenderer(assetManager, 256);
    bsr.setDirection(new Vector3f(-1, -1, -1).normalizeLocal());
    viewPort.addProcessor(bsr);
}
Also used : Sphere(com.jme3.scene.shape.Sphere) SphereCollisionShape(com.jme3.bullet.collision.shapes.SphereCollisionShape) Vector2f(com.jme3.math.Vector2f) BulletAppState(com.jme3.bullet.BulletAppState) Vector3f(com.jme3.math.Vector3f) KeyTrigger(com.jme3.input.controls.KeyTrigger) Box(com.jme3.scene.shape.Box) MouseButtonTrigger(com.jme3.input.controls.MouseButtonTrigger) BasicShadowRenderer(com.jme3.shadow.BasicShadowRenderer)

Example 52 with Box

use of com.jme3.scene.shape.Box in project jmonkeyengine by jMonkeyEngine.

the class TestCollisionShapeFactory method attachRandomGeometry.

private void attachRandomGeometry(Node node, Material mat) {
    Box box = new Box(0.25f, 0.25f, 0.25f);
    Torus torus = new Torus(16, 16, 0.2f, 0.8f);
    Geometry[] boxes = new Geometry[] { new Geometry("box1", box), new Geometry("box2", box), new Geometry("box3", box), new Geometry("torus1", torus), new Geometry("torus2", torus), new Geometry("torus3", torus) };
    for (int i = 0; i < boxes.length; i++) {
        Geometry geometry = boxes[i];
        geometry.setLocalTranslation((float) Math.random() * 10 - 10, (float) Math.random() * 10 - 10, (float) Math.random() * 10 - 10);
        geometry.setLocalRotation(new Quaternion().fromAngles((float) Math.random() * FastMath.PI, (float) Math.random() * FastMath.PI, (float) Math.random() * FastMath.PI));
        geometry.setLocalScale((float) Math.random() * 10 - 10, (float) Math.random() * 10 - 10, (float) Math.random() * 10 - 10);
        geometry.setMaterial(mat);
        node.attachChild(geometry);
    }
}
Also used : Geometry(com.jme3.scene.Geometry) Quaternion(com.jme3.math.Quaternion) Torus(com.jme3.scene.shape.Torus) Box(com.jme3.scene.shape.Box)

Example 53 with Box

use of com.jme3.scene.shape.Box in project jmonkeyengine by jMonkeyEngine.

the class TestFancyCar method findGeom.

//    public void setupFloor() {
//        Material mat = assetManager.loadMaterial("Textures/Terrain/BrickWall/BrickWall.j3m");
//        mat.getTextureParam("DiffuseMap").getTextureValue().setWrap(WrapMode.Repeat);
////        mat.getTextureParam("NormalMap").getTextureValue().setWrap(WrapMode.Repeat);
////        mat.getTextureParam("ParallaxMap").getTextureValue().setWrap(WrapMode.Repeat);
//
//        Box floor = new Box(Vector3f.ZERO, 140, 1f, 140);
//        floor.scaleTextureCoordinates(new Vector2f(112.0f, 112.0f));
//        Geometry floorGeom = new Geometry("Floor", floor);
//        floorGeom.setShadowMode(ShadowMode.Receive);
//        floorGeom.setMaterial(mat);
//
//        PhysicsNode tb = new PhysicsNode(floorGeom, new MeshCollisionShape(floorGeom.getMesh()), 0);
//        tb.setLocalTranslation(new Vector3f(0f, -6, 0f));
////        tb.attachDebugShape(assetManager);
//        rootNode.attachChild(tb);
//        getPhysicsSpace().add(tb);
//    }
private Geometry findGeom(Spatial spatial, String name) {
    if (spatial instanceof Node) {
        Node node = (Node) spatial;
        for (int i = 0; i < node.getQuantity(); i++) {
            Spatial child = node.getChild(i);
            Geometry result = findGeom(child, name);
            if (result != null) {
                return result;
            }
        }
    } else if (spatial instanceof Geometry) {
        if (spatial.getName().startsWith(name)) {
            return (Geometry) spatial;
        }
    }
    return null;
}
Also used : Geometry(com.jme3.scene.Geometry) Spatial(com.jme3.scene.Spatial) Node(com.jme3.scene.Node)

Example 54 with Box

use of com.jme3.scene.shape.Box in project jmonkeyengine by jMonkeyEngine.

the class TestFancyCar method buildPlayer.

private void buildPlayer() {
    //200=f1 car
    float stiffness = 120.0f;
    //(lower than damp!)
    float compValue = 0.2f;
    float dampValue = 0.3f;
    final float mass = 400;
    //Load model and get chassis Geometry
    carNode = (Node) assetManager.loadModel("Models/Ferrari/Car.scene");
    carNode.setShadowMode(ShadowMode.Cast);
    Geometry chasis = findGeom(carNode, "Car");
    BoundingBox box = (BoundingBox) chasis.getModelBound();
    //Create a hull collision shape for the chassis
    CollisionShape carHull = CollisionShapeFactory.createDynamicMeshShape(chasis);
    //Create a vehicle control
    player = new VehicleControl(carHull, mass);
    carNode.addControl(player);
    //Setting default values for wheels
    player.setSuspensionCompression(compValue * 2.0f * FastMath.sqrt(stiffness));
    player.setSuspensionDamping(dampValue * 2.0f * FastMath.sqrt(stiffness));
    player.setSuspensionStiffness(stiffness);
    player.setMaxSuspensionForce(10000);
    //Create four wheels and add them at their locations
    //note that our fancy car actually goes backwards..
    Vector3f wheelDirection = new Vector3f(0, -1, 0);
    Vector3f wheelAxle = new Vector3f(-1, 0, 0);
    Geometry wheel_fr = findGeom(carNode, "WheelFrontRight");
    wheel_fr.center();
    box = (BoundingBox) wheel_fr.getModelBound();
    wheelRadius = box.getYExtent();
    float back_wheel_h = (wheelRadius * 1.7f) - 1f;
    float front_wheel_h = (wheelRadius * 1.9f) - 1f;
    player.addWheel(wheel_fr.getParent(), box.getCenter().add(0, -front_wheel_h, 0), wheelDirection, wheelAxle, 0.2f, wheelRadius, true);
    Geometry wheel_fl = findGeom(carNode, "WheelFrontLeft");
    wheel_fl.center();
    box = (BoundingBox) wheel_fl.getModelBound();
    player.addWheel(wheel_fl.getParent(), box.getCenter().add(0, -front_wheel_h, 0), wheelDirection, wheelAxle, 0.2f, wheelRadius, true);
    Geometry wheel_br = findGeom(carNode, "WheelBackRight");
    wheel_br.center();
    box = (BoundingBox) wheel_br.getModelBound();
    player.addWheel(wheel_br.getParent(), box.getCenter().add(0, -back_wheel_h, 0), wheelDirection, wheelAxle, 0.2f, wheelRadius, false);
    Geometry wheel_bl = findGeom(carNode, "WheelBackLeft");
    wheel_bl.center();
    box = (BoundingBox) wheel_bl.getModelBound();
    player.addWheel(wheel_bl.getParent(), box.getCenter().add(0, -back_wheel_h, 0), wheelDirection, wheelAxle, 0.2f, wheelRadius, false);
    player.getWheel(2).setFrictionSlip(4);
    player.getWheel(3).setFrictionSlip(4);
    rootNode.attachChild(carNode);
    getPhysicsSpace().add(player);
}
Also used : Geometry(com.jme3.scene.Geometry) CollisionShape(com.jme3.bullet.collision.shapes.CollisionShape) BoundingBox(com.jme3.bounding.BoundingBox) Vector3f(com.jme3.math.Vector3f) VehicleControl(com.jme3.bullet.control.VehicleControl)

Example 55 with Box

use of com.jme3.scene.shape.Box in project jmonkeyengine by jMonkeyEngine.

the class TestBatchNodeCluster method randomGenerator.

public void randomGenerator() {
    for (int i = startAt; i < maxCubes - 1; i++) {
        randomize();
        Geometry box = new Geometry("Box" + i, new Box(1, 1, 1));
        box.setLocalTranslation(new Vector3f(xPosition.get(xPosition.size() - 1), yPosition.get(yPosition.size() - 1), zPosition.get(zPosition.size() - 1)));
        batchNode.attachChild(box);
        if (i < 500) {
            box.setMaterial(mat1);
        } else if (i < 1000) {
            box.setMaterial(mat2);
        } else if (i < 1500) {
            box.setMaterial(mat3);
        } else {
            box.setMaterial(mat4);
        }
    }
}
Also used : Vector3f(com.jme3.math.Vector3f) Box(com.jme3.scene.shape.Box)

Aggregations

Geometry (com.jme3.scene.Geometry)106 Box (com.jme3.scene.shape.Box)99 Material (com.jme3.material.Material)83 Vector3f (com.jme3.math.Vector3f)77 Node (com.jme3.scene.Node)31 DirectionalLight (com.jme3.light.DirectionalLight)27 Sphere (com.jme3.scene.shape.Sphere)23 Quaternion (com.jme3.math.Quaternion)20 RigidBodyControl (com.jme3.bullet.control.RigidBodyControl)19 Spatial (com.jme3.scene.Spatial)19 BoundingBox (com.jme3.bounding.BoundingBox)17 Vector2f (com.jme3.math.Vector2f)15 Texture (com.jme3.texture.Texture)15 AmbientLight (com.jme3.light.AmbientLight)13 TempVars (com.jme3.util.TempVars)12 BulletAppState (com.jme3.bullet.BulletAppState)11 KeyTrigger (com.jme3.input.controls.KeyTrigger)11 FilterPostProcessor (com.jme3.post.FilterPostProcessor)11 BoundingSphere (com.jme3.bounding.BoundingSphere)8 BoxCollisionShape (com.jme3.bullet.collision.shapes.BoxCollisionShape)8