Search in sources :

Example 86 with Box

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

the class TestCollisionGroups method simpleInitApp.

@Override
public void simpleInitApp() {
    bulletAppState = new BulletAppState();
    stateManager.attach(bulletAppState);
    bulletAppState.setDebugEnabled(true);
    // Add a physics sphere to the world
    Node physicsSphere = PhysicsTestHelper.createPhysicsTestNode(assetManager, new SphereCollisionShape(1), 1);
    physicsSphere.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(3, 6, 0));
    rootNode.attachChild(physicsSphere);
    getPhysicsSpace().add(physicsSphere);
    // Add a physics sphere to the world
    Node physicsSphere2 = PhysicsTestHelper.createPhysicsTestNode(assetManager, new SphereCollisionShape(1), 1);
    physicsSphere2.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(4, 8, 0));
    physicsSphere2.getControl(RigidBodyControl.class).addCollideWithGroup(PhysicsCollisionObject.COLLISION_GROUP_02);
    rootNode.attachChild(physicsSphere2);
    getPhysicsSpace().add(physicsSphere2);
    // an obstacle mesh, does not move (mass=0)
    Node node2 = PhysicsTestHelper.createPhysicsTestNode(assetManager, new MeshCollisionShape(new Sphere(16, 16, 1.2f)), 0);
    node2.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(2.5f, -4, 0f));
    node2.getControl(RigidBodyControl.class).setCollisionGroup(PhysicsCollisionObject.COLLISION_GROUP_02);
    node2.getControl(RigidBodyControl.class).setCollideWithGroups(PhysicsCollisionObject.COLLISION_GROUP_02);
    rootNode.attachChild(node2);
    getPhysicsSpace().add(node2);
    // the floor, does not move (mass=0)
    Node node3 = PhysicsTestHelper.createPhysicsTestNode(assetManager, new MeshCollisionShape(new Box(100f, 0.2f, 100f)), 0);
    node3.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(0f, -6, 0f));
    rootNode.attachChild(node3);
    getPhysicsSpace().add(node3);
}
Also used : MeshCollisionShape(com.jme3.bullet.collision.shapes.MeshCollisionShape) Sphere(com.jme3.scene.shape.Sphere) SphereCollisionShape(com.jme3.bullet.collision.shapes.SphereCollisionShape) BulletAppState(com.jme3.bullet.BulletAppState) Node(com.jme3.scene.Node) Vector3f(com.jme3.math.Vector3f) Box(com.jme3.scene.shape.Box) RigidBodyControl(com.jme3.bullet.control.RigidBodyControl)

Example 87 with Box

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

the class TestGhostObject method simpleInitApp.

@Override
public void simpleInitApp() {
    bulletAppState = new BulletAppState();
    stateManager.attach(bulletAppState);
    bulletAppState.setDebugEnabled(true);
    // Mesh to be shared across several boxes.
    Box boxGeom = new Box(1f, 1f, 1f);
    // CollisionShape to be shared across several boxes.
    CollisionShape shape = new BoxCollisionShape(new Vector3f(1, 1, 1));
    Node physicsBox = PhysicsTestHelper.createPhysicsTestNode(assetManager, shape, 1);
    physicsBox.setName("box0");
    physicsBox.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(.6f, 4, .5f));
    rootNode.attachChild(physicsBox);
    getPhysicsSpace().add(physicsBox);
    Node physicsBox1 = PhysicsTestHelper.createPhysicsTestNode(assetManager, shape, 1);
    physicsBox1.setName("box1");
    physicsBox1.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(0, 40, 0));
    rootNode.attachChild(physicsBox1);
    getPhysicsSpace().add(physicsBox1);
    Node physicsBox2 = PhysicsTestHelper.createPhysicsTestNode(assetManager, new BoxCollisionShape(new Vector3f(1, 1, 1)), 1);
    physicsBox2.setName("box0");
    physicsBox2.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(.5f, 80, -.8f));
    rootNode.attachChild(physicsBox2);
    getPhysicsSpace().add(physicsBox2);
    // the floor, does not move (mass=0)
    Node node = PhysicsTestHelper.createPhysicsTestNode(assetManager, new BoxCollisionShape(new Vector3f(100, 1, 100)), 0);
    node.setName("floor");
    node.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(0f, -6, 0f));
    rootNode.attachChild(node);
    getPhysicsSpace().add(node);
    initGhostObject();
}
Also used : BoxCollisionShape(com.jme3.bullet.collision.shapes.BoxCollisionShape) CollisionShape(com.jme3.bullet.collision.shapes.CollisionShape) BulletAppState(com.jme3.bullet.BulletAppState) Vector3f(com.jme3.math.Vector3f) Node(com.jme3.scene.Node) Box(com.jme3.scene.shape.Box) BoxCollisionShape(com.jme3.bullet.collision.shapes.BoxCollisionShape) RigidBodyControl(com.jme3.bullet.control.RigidBodyControl)

Example 88 with Box

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

the class TestAndroidResources method simpleInitApp.

@Override
public void simpleInitApp() {
    // Create boxes with textures that are stored in the Android Resources Folders
    // Images are stored in multiple Drawable and Mipmap directories.  Android picks the ones that
    // match the device size and density.
    Box box1Mesh = new Box(1, 1, 1);
    Geometry box1 = new Geometry("Monkey Box 1", box1Mesh);
    Material mat1 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    mat1.setTexture("ColorMap", assetManager.loadTexture("drawable_monkey.png"));
    box1.setMaterial(mat1);
    box1.setLocalTranslation(-2, 0, 0);
    rootNode.attachChild(box1);
    Box box2Mesh = new Box(1, 1, 1);
    Geometry box2 = new Geometry("Monkey Box 2", box2Mesh);
    Material mat2 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    mat2.setTexture("ColorMap", assetManager.loadTexture("mipmap_monkey.png"));
    box2.setMaterial(mat2);
    box2.setLocalTranslation(2, 0, 0);
    rootNode.attachChild(box2);
}
Also used : Geometry(com.jme3.scene.Geometry) Box(com.jme3.scene.shape.Box) Material(com.jme3.material.Material)

Example 89 with Box

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

the class TestAndroidSensors method simpleInitApp.

@Override
public void simpleInitApp() {
    if (enableFlyByCameraRotation) {
        flyCam.setEnabled(true);
    } else {
        flyCam.setEnabled(false);
    }
    Mesh lineX = new Line(Vector3f.ZERO, Vector3f.ZERO.add(Vector3f.UNIT_X.mult(3)));
    Mesh lineY = new Line(Vector3f.ZERO, Vector3f.ZERO.add(Vector3f.UNIT_Y.mult(3)));
    Mesh lineZ = new Line(Vector3f.ZERO, Vector3f.ZERO.add(Vector3f.UNIT_Z.mult(3)));
    Geometry geoX = new Geometry("X", lineX);
    Material matX = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    matX.setColor("Color", ColorRGBA.Red);
    matX.getAdditionalRenderState().setLineWidth(30);
    geoX.setMaterial(matX);
    rootNode.attachChild(geoX);
    Geometry geoY = new Geometry("Y", lineY);
    Material matY = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    matY.setColor("Color", ColorRGBA.Green);
    matY.getAdditionalRenderState().setLineWidth(30);
    geoY.setMaterial(matY);
    rootNode.attachChild(geoY);
    Geometry geoZ = new Geometry("Z", lineZ);
    Material matZ = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    matZ.setColor("Color", ColorRGBA.Blue);
    matZ.getAdditionalRenderState().setLineWidth(30);
    geoZ.setMaterial(matZ);
    rootNode.attachChild(geoZ);
    Box b = new Box(1, 1, 1);
    geomZero = new Geometry("Box", b);
    Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    mat.setColor("Color", ColorRGBA.Yellow);
    Texture tex_ml = assetManager.loadTexture("Interface/Logo/Monkey.jpg");
    mat.setTexture("ColorMap", tex_ml);
    geomZero.setMaterial(mat);
    geomZero.setLocalTranslation(Vector3f.ZERO);
    geomZero.setLocalRotation(Quaternion.IDENTITY);
    rootNode.attachChild(geomZero);
    // Touch (aka MouseInput.BUTTON_LEFT) is used to record the starting
    // orientation when using absolute rotations
    inputManager.addMapping("MouseClick", new MouseButtonTrigger(MouseInput.BUTTON_LEFT));
    inputManager.addListener(this, "MouseClick");
    Joystick[] joysticks = inputManager.getJoysticks();
    if (joysticks == null || joysticks.length < 1) {
        logger.log(Level.INFO, "Cannot find any joysticks!");
    } else {
        // Joysticks return a value of 0 to 1 based on how far the stick is
        // push on the axis. This value is then scaled based on how long
        // during the frame the joystick axis has been in that position.
        // If the joystick is push all the way for the whole frame,
        // then the value in onAnalog is equal to tpf.
        // If the joystick is push 1/2 way for the entire frame, then the
        // onAnalog value is 1/2 tpf.
        // Similarly, if the joystick is pushed to the maximum during a frame
        // the value in onAnalog will also be scaled.
        // For Android sensors, rotating the device 90deg is the same as
        // pushing an actual joystick axis to the maximum.
        logger.log(Level.INFO, "Number of joysticks: {0}", joysticks.length);
        JoystickAxis axis;
        for (Joystick joystick : joysticks) {
            // Get and display all axes in joystick.
            List<JoystickAxis> axes = joystick.getAxes();
            for (JoystickAxis joystickAxis : axes) {
                logger.log(Level.INFO, "{0} axis scan Name: {1}, LogicalId: {2}, AxisId: {3}", new Object[] { joystick.getName(), joystickAxis.getName(), joystickAxis.getLogicalId(), joystickAxis.getAxisId() });
            }
            // Get specific axis based on LogicalId of the JoystickAxis
            // If found, map axis
            axis = joystick.getAxis(SensorJoystickAxis.ORIENTATION_X);
            if (axis != null) {
                axis.assignAxis(ORIENTATION_X_PLUS, ORIENTATION_X_MINUS);
                inputManager.addListener(this, ORIENTATION_X_PLUS, ORIENTATION_X_MINUS);
                logger.log(Level.INFO, "Found {0} Joystick, assigning mapping for X axis: {1}, with max value: {2}", new Object[] { joystick.toString(), axis.toString(), ((SensorJoystickAxis) axis).getMaxRawValue() });
            }
            axis = joystick.getAxis(SensorJoystickAxis.ORIENTATION_Y);
            if (axis != null) {
                axis.assignAxis(ORIENTATION_Y_PLUS, ORIENTATION_Y_MINUS);
                inputManager.addListener(this, ORIENTATION_Y_PLUS, ORIENTATION_Y_MINUS);
                logger.log(Level.INFO, "Found {0} Joystick, assigning mapping for Y axis: {1}, with max value: {2}", new Object[] { joystick.toString(), axis.toString(), ((SensorJoystickAxis) axis).getMaxRawValue() });
            }
            axis = joystick.getAxis(SensorJoystickAxis.ORIENTATION_Z);
            if (axis != null) {
                axis.assignAxis(ORIENTATION_Z_PLUS, ORIENTATION_Z_MINUS);
                inputManager.addListener(this, ORIENTATION_Z_PLUS, ORIENTATION_Z_MINUS);
                logger.log(Level.INFO, "Found {0} Joystick, assigning mapping for Z axis: {1}, with max value: {2}", new Object[] { joystick.toString(), axis.toString(), ((SensorJoystickAxis) axis).getMaxRawValue() });
            }
            joystickMap.put(joystick.getJoyId(), joystick);
        }
    }
}
Also used : Line(com.jme3.scene.shape.Line) Geometry(com.jme3.scene.Geometry) Joystick(com.jme3.input.Joystick) Mesh(com.jme3.scene.Mesh) Material(com.jme3.material.Material) Box(com.jme3.scene.shape.Box) MouseButtonTrigger(com.jme3.input.controls.MouseButtonTrigger) SensorJoystickAxis(com.jme3.input.SensorJoystickAxis) JoystickAxis(com.jme3.input.JoystickAxis) Texture(com.jme3.texture.Texture)

Example 90 with Box

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

the class AndroidHarness method initialize.

public void initialize() {
    app.initialize();
    if (handleExitHook) {
        // AndroidHarness can produce the exit app dialog box.
        if (app.getInputManager().hasMapping(SimpleApplication.INPUT_MAPPING_EXIT)) {
            app.getInputManager().deleteMapping(SimpleApplication.INPUT_MAPPING_EXIT);
        }
        app.getInputManager().addMapping(ESCAPE_EVENT, new TouchTrigger(TouchInput.KEYCODE_BACK));
        app.getInputManager().addListener(this, new String[] { ESCAPE_EVENT });
    }
}
Also used : TouchTrigger(com.jme3.input.controls.TouchTrigger)

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