Search in sources :

Example 56 with Quaternion

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

the class TestBetterCharacter method simpleUpdate.

@Override
public void simpleUpdate(float tpf) {
    // Apply planet gravity to character if close enough (see below)
    checkPlanetGravity();
    // Get current forward and left vectors of model by using its rotation
    // to rotate the unit vectors
    Vector3f modelForwardDir = characterNode.getWorldRotation().mult(Vector3f.UNIT_Z);
    Vector3f modelLeftDir = characterNode.getWorldRotation().mult(Vector3f.UNIT_X);
    // WalkDirection is global!
    // You *can* make your character fly with this.
    walkDirection.set(0, 0, 0);
    if (leftStrafe) {
        walkDirection.addLocal(modelLeftDir.mult(3));
    } else if (rightStrafe) {
        walkDirection.addLocal(modelLeftDir.negate().multLocal(3));
    }
    if (forward) {
        walkDirection.addLocal(modelForwardDir.mult(3));
    } else if (backward) {
        walkDirection.addLocal(modelForwardDir.negate().multLocal(3));
    }
    physicsCharacter.setWalkDirection(walkDirection);
    // setApplyPhysicsLocal()
    if (leftRotate) {
        Quaternion rotateL = new Quaternion().fromAngleAxis(FastMath.PI * tpf, Vector3f.UNIT_Y);
        rotateL.multLocal(viewDirection);
    } else if (rightRotate) {
        Quaternion rotateR = new Quaternion().fromAngleAxis(-FastMath.PI * tpf, Vector3f.UNIT_Y);
        rotateR.multLocal(viewDirection);
    }
    physicsCharacter.setViewDirection(viewDirection);
    fpsText.setText("Touch da ground = " + physicsCharacter.isOnGround());
    if (!lockView) {
        cam.lookAt(characterNode.getWorldTranslation().add(new Vector3f(0, 2, 0)), Vector3f.UNIT_Y);
    }
}
Also used : Quaternion(com.jme3.math.Quaternion) Vector3f(com.jme3.math.Vector3f)

Example 57 with Quaternion

use of com.jme3.math.Quaternion 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 58 with Quaternion

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

the class TestBatchNodeCluster method simpleUpdate.

@Override
public void simpleUpdate(float tpf) {
    time += tpf;
    int random = rand.nextInt(2000);
    float mult1 = 1.0f;
    float mult2 = 1.0f;
    if (random < 500) {
        mult1 = 1.0f;
        mult2 = 1.0f;
    } else if (random < 1000) {
        mult1 = -1.0f;
        mult2 = 1.0f;
    } else if (random < 1500) {
        mult1 = 1.0f;
        mult2 = -1.0f;
    } else if (random <= 2000) {
        mult1 = -1.0f;
        mult2 = -1.0f;
    }
    box = batchNode.getChild("Box" + random);
    if (box != null) {
        Vector3f v = box.getLocalTranslation();
        box.setLocalTranslation(v.x + FastMath.sin(time * mult1) * 20, v.y + (FastMath.sin(time * mult1) * FastMath.cos(time * mult1) * 20), v.z + FastMath.cos(time * mult2) * 20);
    }
    terrain.setLocalRotation(new Quaternion().fromAngleAxis(time, Vector3f.UNIT_Y));
}
Also used : Quaternion(com.jme3.math.Quaternion) Vector3f(com.jme3.math.Vector3f)

Example 59 with Quaternion

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

the class TestHoveringTank method makeMissile.

public void makeMissile() {
    Vector3f pos = spaceCraft.getWorldTranslation().clone();
    Quaternion rot = spaceCraft.getWorldRotation();
    Vector3f dir = rot.getRotationColumn(2);
    Spatial missile = assetManager.loadModel("Models/SpaceCraft/Rocket.mesh.xml");
    missile.scale(0.5f);
    missile.rotate(0, FastMath.PI, 0);
    missile.updateGeometricState();
    BoundingBox box = (BoundingBox) missile.getWorldBound();
    final Vector3f extent = box.getExtent(null);
    BoxCollisionShape boxShape = new BoxCollisionShape(extent);
    missile.setName("Missile");
    missile.rotate(rot);
    missile.setLocalTranslation(pos.addLocal(0, extent.y * 4.5f, 0));
    missile.setLocalRotation(hoverControl.getPhysicsRotation());
    missile.setShadowMode(ShadowMode.Cast);
    RigidBodyControl control = new BombControl(assetManager, boxShape, 20);
    control.setLinearVelocity(dir.mult(100));
    control.setCollisionGroup(PhysicsCollisionObject.COLLISION_GROUP_03);
    missile.addControl(control);
    rootNode.attachChild(missile);
    getPhysicsSpace().add(missile);
}
Also used : Spatial(com.jme3.scene.Spatial) BoundingBox(com.jme3.bounding.BoundingBox) BoxCollisionShape(com.jme3.bullet.collision.shapes.BoxCollisionShape) RigidBodyControl(com.jme3.bullet.control.RigidBodyControl)

Example 60 with Quaternion

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

the class PhysicsGhostObject method getPhysicsRotation.

/**
     * @return the physicsLocation
     */
public Quaternion getPhysicsRotation(Quaternion rot) {
    if (rot == null) {
        rot = new Quaternion();
    }
    gObject.getWorldTransform(tempTrans);
    Converter.convert(tempTrans.getRotation(tempRot), physicsLocation.getRotation());
    return rot.set(physicsLocation.getRotation());
}
Also used : Quaternion(com.jme3.math.Quaternion)

Aggregations

Quaternion (com.jme3.math.Quaternion)115 Vector3f (com.jme3.math.Vector3f)100 Geometry (com.jme3.scene.Geometry)42 DirectionalLight (com.jme3.light.DirectionalLight)37 Material (com.jme3.material.Material)36 Node (com.jme3.scene.Node)30 FilterPostProcessor (com.jme3.post.FilterPostProcessor)26 Spatial (com.jme3.scene.Spatial)26 KeyTrigger (com.jme3.input.controls.KeyTrigger)22 Box (com.jme3.scene.shape.Box)21 TempVars (com.jme3.util.TempVars)16 ActionListener (com.jme3.input.controls.ActionListener)15 ColorRGBA (com.jme3.math.ColorRGBA)15 Quad (com.jme3.scene.shape.Quad)15 AmbientLight (com.jme3.light.AmbientLight)14 Sphere (com.jme3.scene.shape.Sphere)11 Bone (com.jme3.animation.Bone)9 PointLight (com.jme3.light.PointLight)8 AnimControl (com.jme3.animation.AnimControl)7 SpotLight (com.jme3.light.SpotLight)7