Java Code Examples for com.jme3.math.Quaternion

The following examples show how to use com.jme3.math.Quaternion. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
public synchronized void applyWheelTransform() {
    if (wheelSpatial == null) {
        return;
    }
    Quaternion localRotationQuat = wheelSpatial.getLocalRotation();
    Vector3f localLocation = wheelSpatial.getLocalTranslation();
    if (!applyLocal && wheelSpatial.getParent() != null) {
        localLocation.set(wheelWorldLocation).subtractLocal(wheelSpatial.getParent().getWorldTranslation());
        localLocation.divideLocal(wheelSpatial.getParent().getWorldScale());
        tmp_inverseWorldRotation.set(wheelSpatial.getParent().getWorldRotation()).inverseLocal().multLocal(localLocation);

        localRotationQuat.set(wheelWorldRotation);
        tmp_inverseWorldRotation.set(wheelSpatial.getParent().getWorldRotation()).inverseLocal().mult(localRotationQuat, localRotationQuat);

        wheelSpatial.setLocalTranslation(localLocation);
        wheelSpatial.setLocalRotation(localRotationQuat);
    } else {
        wheelSpatial.setLocalTranslation(wheelWorldLocation);
        wheelSpatial.setLocalRotation(wheelWorldRotation);
    }
}
 
Example 2
public void onAction(String name, boolean value, float tpf) {
    if (!value) {
        return;
    }

    if (name.equals(INPUT_MAPPING_EXIT)) {
        stop();
    } else if (name.equals(INPUT_MAPPING_CAMERA_POS)) {
        if (cam != null) {
            Vector3f loc = cam.getLocation();
            Quaternion rot = cam.getRotation();
            System.out.println("Camera Position: ("
                    + loc.x + ", " + loc.y + ", " + loc.z + ")");
            System.out.println("Camera Rotation: " + rot);
            System.out.println("Camera Direction: " + cam.getDirection());
        }
    } else if (name.equals(INPUT_MAPPING_MEMORY)) {
        BufferUtils.printCurrentDirectMemory(null);
    }else if (name.equals(INPUT_MAPPING_HIDE_STATS)){
        boolean show = showFps;
        setDisplayFps(!show);
        setDisplayStatView(!show);
    }
}
 
Example 3
Source Project: OpenRTS   Source File: OpenRTSApplication.java    License: MIT License 6 votes vote down vote up
@Override
public void onAction(String name, boolean value, float tpf) {
	if (!value) {
		return;
	}

	if (name.equals("SIMPLEAPP_Exit")) {
		stop();
	} else if (name.equals("SIMPLEAPP_CameraPos")) {
		if (cam != null) {
			Vector3f loc = cam.getLocation();
			Quaternion rot = cam.getRotation();
			System.out.println("Camera Position: (" + loc.x + ", " + loc.y + ", " + loc.z + ")");
			System.out.println("Camera Rotation: " + rot);
			System.out.println("Camera Direction: " + cam.getDirection());
		}
	} else if (name.equals("SIMPLEAPP_Memory")) {
		BufferUtils.printCurrentDirectMemory(null);
	}
}
 
Example 4
/**
 * Set the translations and rotations for this bone track
 *
 * @param times the time of each frame, measured from the start of the track
 * (not null, length>0)
 * @param translations the translation of the bone for each frame (not null,
 * same length as times)
 * @param rotations the rotation of the bone for each frame (not null, same
 * length as times)
 */
public void setKeyframes(float[] times, Vector3f[] translations, Quaternion[] rotations) {
    if (times.length == 0) {
        throw new RuntimeException("BoneTrack with no keyframes!");
    }

    assert translations != null;
    assert times.length == translations.length;
    assert rotations != null;
    assert times.length == rotations.length;

    this.times = times;
    this.translations = new CompactVector3Array();
    this.translations.add(translations);
    this.translations.freeze();
    this.rotations = new CompactQuaternionArray();
    this.rotations.add(rotations);
    this.rotations.freeze();
}
 
Example 5
Source Project: jmonkeybuilder   Source File: LevelTerrainToolControl.java    License: Apache License 2.0 6 votes vote down vote up
@Override
@JmeThread
public void finishPainting(@NotNull Quaternion brushRotation, @NotNull Vector3f contactPoint) {
    super.finishPainting(brushRotation, contactPoint);

    switch (notNull(getCurrentInput())) {
        case MOUSE_PRIMARY: {
            modifyHeight(contactPoint);
            commitChanges();
            break;
        }
        case MOUSE_SECONDARY: {
            levelMarker.setLocalTranslation(contactPoint);
            break;
        }
    }
}
 
Example 6
@Override
public void simpleInitApp() {
    createFlame();
    createFlash();
    createSpark();
    createRoundSpark();
    createSmokeTrail();
    createDebris();
    createShockwave();
    explosionEffect.setLocalScale(0.5f);
    renderManager.preloadScene(explosionEffect);

    cam.setLocation(new Vector3f(0, 3.5135868f, 10));
    cam.setRotation(new Quaternion(1.5714673E-4f, 0.98696727f, -0.16091813f, 9.6381607E-4f));

    rootNode.attachChild(explosionEffect);
}
 
Example 7
@Override
public boolean init() {
	
	logger.config("Initialize OpenVR input.");
	
    for(int i=0;i<JOpenVRLibrary.k_unMaxTrackedDeviceCount;i++) {
        rotStore[i] = new Quaternion();
        posStore[i] = new Vector3f();
        cStates[i] = new VRControllerState_t();
        cStates[i].setAutoSynch(false);
        cStates[i].setAutoRead(false);
        cStates[i].setAutoWrite(false);
        lastCallAxis[i] = new Vector2f();
        needsNewVelocity[i] = true;
        needsNewAngVelocity[i] = true;
        logger.config("  Input "+(i+1)+"/"+JOpenVRLibrary.k_unMaxTrackedDeviceCount+" binded.");
    }        
    
    return true;
}
 
Example 8
@Override
public void simpleUpdate(float tpf) {
    Joint j = skinningControl.getArmature().getJoint("spinehigh");
    Joint j2 = skinningControl.getArmature().getJoint("uparm.left");

    angle += tpf * rate;
    if (angle > FastMath.HALF_PI / 2f) {
        angle = FastMath.HALF_PI / 2f;
        rate = -1;
    } else if (angle < -FastMath.HALF_PI / 2f) {
        angle = -FastMath.HALF_PI / 2f;
        rate = 1;
    }

    Quaternion q = new Quaternion();
    q.fromAngles(0, angle, 0);

    j.setLocalRotation(j.getInitialTransform().getRotation().mult(q));
    j2.setLocalScale(j.getInitialTransform().getScale().mult(new Vector3f(1 + angle, 1 + angle, 1 + angle)));
}
 
Example 9
@FxThread
private void build(@NotNull final ChildCollisionShape shape, @NotNull final VBox container,
                   @NotNull final ModelChangeConsumer changeConsumer) {

    final Vector3f location = shape.location;
    final Matrix3f rotation = shape.rotation;

    final DefaultSinglePropertyControl<ModelChangeConsumer, ChildCollisionShape, Vector3f> locationControl =
            new DefaultSinglePropertyControl<>(location, Messages.MODEL_PROPERTY_LOCATION, changeConsumer);

    locationControl.setSyncHandler(collisionShape -> collisionShape.location);
    locationControl.setToStringFunction(Vector3f::toString);
    locationControl.setEditObject(shape);

    final DefaultSinglePropertyControl<ModelChangeConsumer, ChildCollisionShape, Matrix3f> rotationControl =
            new DefaultSinglePropertyControl<>(rotation, Messages.MODEL_PROPERTY_ROTATION, changeConsumer);

    rotationControl.setSyncHandler(collisionShape -> collisionShape.rotation);
    rotationControl.setToStringFunction(matrix3f -> new Quaternion().fromRotationMatrix(matrix3f).toString());
    rotationControl.setEditObject(shape);
    rotationControl.reload();

    FXUtils.addToPane(locationControl, container);
    FXUtils.addToPane(rotationControl, container);
}
 
Example 10
@Override
    public void simpleInitApp() {
        cam.setLocation(new Vector3f(-32.295086f, 54.80136f, 79.59805f));
        cam.setRotation(new Quaternion(0.074364014f, 0.92519957f, -0.24794696f, 0.27748522f));
        cam.update();

        cam.setFrustumFar(300);
        flyCam.setMoveSpeed(30);

        rootNode.setCullHint(CullHint.Never);

        setupBasicShadow();
        setupHdr();

        setupLighting();
        setupSkyBox();

//        setupTerrain();
        setupFloor();
//        setupRobotGuy();
        setupSignpost();

        
    }
 
Example 11
/**
 * Sets the transform for the given frame.
 * 
 * @param frameIndex
 *            the frame for which the transform will be set
 * @param transform
 *            the transformation to be set
 */
public void setTransform(int frameIndex, Transform transform) {
    if (translations == null) {
        translations = this.createList(Vector3f.ZERO, frameIndex);
    }
    this.append(translations, Vector3f.ZERO, frameIndex - translations.size());
    translations.add(transform.getTranslation().clone());

    if (rotations == null) {
        rotations = this.createList(Quaternion.IDENTITY, frameIndex);
    }
    this.append(rotations, Quaternion.IDENTITY, frameIndex - rotations.size());
    rotations.add(transform.getRotation().clone());

    if (scales == null) {
        scales = this.createList(Vector3f.UNIT_XYZ, frameIndex);
    }
    this.append(scales, Vector3f.UNIT_XYZ, frameIndex - scales.size());
    scales.add(transform.getScale().clone());
}
 
Example 12
@Override
public void simpleInitApp() {
    maxAniso = renderer.getLimits().get(Limits.TextureAnisotropy);

    flyCam.setDragToRotate(true);
    flyCam.setMoveSpeed(100);
    cam.setLocation(new Vector3f(197.02617f, 4.6769195f, -194.89545f));
    cam.setRotation(new Quaternion(0.07921988f, 0.8992258f, -0.18292196f, 0.38943136f));
    Quad q = new Quad(1000, 1000);
    q.scaleTextureCoordinates(new Vector2f(1000, 1000));
    Geometry geom = new Geometry("quad", q);
    geom.rotate(-FastMath.HALF_PI, 0, 0);
    geom.setMaterial(createCheckerBoardMaterial(assetManager));
    rootNode.attachChild(geom);

    inputManager.addMapping("higher", new KeyTrigger(KeyInput.KEY_1));
    inputManager.addMapping("lower", new KeyTrigger(KeyInput.KEY_2));
    inputManager.addListener(this, "higher");
    inputManager.addListener(this, "lower");
}
 
Example 13
@Override
public void simpleInitApp() {
    viewPort.setBackgroundColor(ColorRGBA.Gray);

    cam.setLocation(new Vector3f(-5.6310086f, 5.0892987f, -13.000479f));
    cam.setRotation(new Quaternion(0.1779095f, 0.20036356f, -0.03702727f, 0.96272093f));
    cam.update();

    cam.setFrustumFar(300);
    flyCam.setMoveSpeed(30);

    rootNode.setCullHint(CullHint.Never);

    setupLighting();
    setupModel();
    setupFilters();
}
 
Example 14
public void updateCamera() {
    rootNode.updateGeometricState();

    Vector3f pos = spaceCraft.getWorldTranslation().clone();
    Quaternion rot = spaceCraft.getWorldRotation();
    Vector3f dir = rot.getRotationColumn(2);

    // make it XZ only
    Vector3f camPos = new Vector3f(dir);
    camPos.setY(0);
    camPos.normalizeLocal();

    // negate and multiply by distance from object
    camPos.negateLocal();
    camPos.multLocal(15);

    // add Y distance
    camPos.setY(2);
    camPos.addLocal(pos);
    cam.setLocation(camPos);

    Vector3f lookAt = new Vector3f(dir);
    lookAt.multLocal(7); // look at dist
    lookAt.addLocal(pos);
    cam.lookAt(lookAt, Vector3f.UNIT_Y);
}
 
Example 15
Source Project: MikuMikuStudio   Source File: BoneTrack.java    License: BSD 2-Clause "Simplified" License 6 votes vote down vote up
/**
 * Set the translations and rotations for this bone track
 * @param times a float array with the time of each frame
 * @param translations the translation of the bone for each frame
 * @param rotations the rotation of the bone for each frame
 */
public void setKeyframes(float[] times, Vector3f[] translations, Quaternion[] rotations) {
    if (times.length == 0) {
        throw new RuntimeException("BoneTrack with no keyframes!");
    }

    assert times.length == translations.length && times.length == rotations.length;

    this.times = times;
    this.translations = new CompactVector3Array();
    this.translations.add(translations);
    this.translations.freeze();
    this.rotations = new CompactQuaternionArray();
    this.rotations.add(rotations);
    this.rotations.freeze();
}
 
Example 16
Source Project: MikuMikuStudio   Source File: TestShadow.java    License: BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
    public void simpleInitApp() {
        // put the camera in a bad position
        cam.setLocation(new Vector3f(0.7804813f, 1.7502685f, -2.1556435f));
        cam.setRotation(new Quaternion(0.1961598f, -0.7213164f, 0.2266092f, 0.6243975f));
        cam.setFrustumFar(10);

        Material mat = assetManager.loadMaterial("Common/Materials/WhiteColor.j3m");
        rootNode.setShadowMode(ShadowMode.Off);
        Box floor = new Box(Vector3f.ZERO, 3, 0.1f, 3);
        Geometry floorGeom = new Geometry("Floor", floor);
        floorGeom.setMaterial(mat);
        floorGeom.setLocalTranslation(0,-0.2f,0);
        floorGeom.setShadowMode(ShadowMode.Receive);
        rootNode.attachChild(floorGeom);

        teapot = assetManager.loadModel("Models/Teapot/Teapot.obj");
        teapot.setLocalScale(2f);
        teapot.setMaterial(mat);
        teapot.setShadowMode(ShadowMode.CastAndReceive);
        rootNode.attachChild(teapot);
//        lightMdl = new Geometry("Light", new Sphere(10, 10, 0.1f));
//        lightMdl.setMaterial(mat);
//        // disable shadowing for light representation
//        lightMdl.setShadowMode(ShadowMode.Off);
//        rootNode.attachChild(lightMdl);

        bsr = new BasicShadowRenderer(assetManager, 512);
        bsr.setDirection(new Vector3f(-1, -1, -1).normalizeLocal());
        viewPort.addProcessor(bsr);

        frustum = new WireFrustum(bsr.getPoints());
        frustumMdl = new Geometry("f", frustum);
        frustumMdl.setCullHint(Spatial.CullHint.Never);
        frustumMdl.setShadowMode(ShadowMode.Off);
        frustumMdl.setMaterial(new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md"));
        frustumMdl.getMaterial().getAdditionalRenderState().setWireframe(true);
        frustumMdl.getMaterial().setColor("Color", ColorRGBA.Red);
        rootNode.attachChild(frustumMdl);
    }
 
Example 17
Source Project: jmonkeybuilder   Source File: EditorTransformSupport.java    License: Apache License 2.0 5 votes vote down vote up
@Override
@JmeThread
public void prepareToMove(@NotNull final Node parent, @NotNull final Node child,
                          @NotNull final Transform transform, @NotNull final Camera camera) {
    parent.setLocalRotation(camera.getRotation());
    parent.setLocalTranslation(transform.getTranslation());
    child.setLocalTranslation(Vector3f.ZERO);
    child.setLocalRotation(Quaternion.IDENTITY);
}
 
Example 18
@Override
public void simpleUpdate(float tpf) {
    // 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);

    // ViewDirection is local to characters physics system!
    // The final world rotation depends on the gravity and on the state of
    // 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);
    }
}
 
Example 19
/**
 * Set the translations, rotations and scales for this track.
 * 
 * @param times
 *            a float array with the time of each frame
 * @param translations
 *            the translation of the bone for each frame
 * @param rotations
 *            the rotation of the bone for each frame
 * @param scales
 *            the scale of the bone for each frame
 */
public void setKeyframes(float[] times, Vector3f[] translations,
                         Quaternion[] rotations, Vector3f[] scales) {
    if (times.length == 0) {
        throw new RuntimeException("BoneTrack with no keyframes!");
    }

    this.times = times;
    if (translations != null) {
        assert times.length == translations.length;
        this.translations = new CompactVector3Array();
        this.translations.add(translations);
        this.translations.freeze();
    }
    if (rotations != null) {
        assert times.length == rotations.length;
        this.rotations = new CompactQuaternionArray();
        this.rotations.add(rotations);
        this.rotations.freeze();
    }
    if (scales != null) {
        assert times.length == scales.length;
        this.scales = new CompactVector3Array();
        this.scales.add(scales);
        this.scales.freeze();
    }
}
 
Example 20
Source Project: jmonkeybuilder   Source File: RoughTerrainToolControl.java    License: Apache License 2.0 5 votes vote down vote up
@Override
@JmeThread
public void updatePainting(@NotNull final Quaternion brushRotation, @NotNull final Vector3f contactPoint,
                           final float tpf) {

    final PaintingInput input = notNull(getCurrentInput());

    switch (input) {
        case MOUSE_PRIMARY: {
            modifyHeight(contactPoint);
        }
    }
}
 
Example 21
@Test
public void testCompactQuaternionArrayDoubleArrayIntArray() {
	int[] indexArray = new int[] {0, 1, 2, 1, 0};
	float[] dataArray = new float[] {1, 0, 1, 1, 1, 1, 1, 0, 0, 1, 1, 0};
	Quaternion[] objArray = new Quaternion[] {
			new Quaternion(1, 0, 1, 1),	
			new Quaternion(1, 1, 1, 0),	
			new Quaternion(0, 1, 1, 0),	
			new Quaternion(1, 1, 1, 0),	
			new Quaternion(1, 0, 1, 1),	
	};
	CompactQuaternionArray compact = new CompactQuaternionArray(dataArray, indexArray);
	assertTrue(Arrays.deepEquals(compact.toObjectArray(), objArray));
}
 
Example 22
@Override
public void simpleUpdate(float tpf){
    Quaternion q = new Quaternion();
 
    angle += tpf;
    angle %= FastMath.TWO_PI;
    q.fromAngles(angle, 0, angle);

    offBox.setLocalRotation(q);
    offBox.updateLogicalState(tpf);
    offBox.updateGeometricState();
}
 
Example 23
Source Project: jmonkeybuilder   Source File: SmoothTerrainToolControl.java    License: Apache License 2.0 5 votes vote down vote up
@Override
@JmeThread
public void finishPainting(@NotNull final Quaternion brushRotation, @NotNull final Vector3f contactPoint) {
    super.finishPainting(brushRotation, contactPoint);

    final PaintingInput input = notNull(getCurrentInput());

    switch (input) {
        case MOUSE_PRIMARY: {
            modifyHeight(contactPoint);
            commitChanges();
        }
    }
}
 
Example 24
/**
 * This method transforms the first line of the bevel points positioning it
 * on the first point of the curve.
 * 
 * @param startingLinePoints
 *            the vbevel shape points
 * @param firstCurvePoint
 *            the first curve's point
 * @param secondCurvePoint
 *            the second curve's point
 * @return points of transformed bevel
 */
private Vector3f[] transformToFirstLineOfBevelPoints(Vector3f[] startingLinePoints, Vector3f firstCurvePoint, Vector3f secondCurvePoint) {
    Vector3f planeNormal = secondCurvePoint.subtract(firstCurvePoint).normalizeLocal();

    float angle = FastMath.acos(planeNormal.dot(Vector3f.UNIT_Y));
    planeNormal.crossLocal(Vector3f.UNIT_Y).normalizeLocal();// planeNormal is the rotation axis now
    Quaternion pointRotation = new Quaternion();
    pointRotation.fromAngleAxis(angle, planeNormal);

    Matrix4f m = new Matrix4f();
    m.setRotationQuaternion(pointRotation);
    m.setTranslation(firstCurvePoint);

    float[] temp = new float[] { 0, 0, 0, 1 };
    Vector3f[] verts = new Vector3f[startingLinePoints.length];
    for (int j = 0; j < verts.length; ++j) {
        temp[0] = startingLinePoints[j].x;
        temp[1] = startingLinePoints[j].y;
        temp[2] = startingLinePoints[j].z;
        temp = m.mult(temp);// the result is stored in the array
        if (fixUpAxis) {
            verts[j] = new Vector3f(temp[0], -temp[2], temp[1]);
        } else {
            verts[j] = new Vector3f(temp[0], temp[1], temp[2]);
        }
    }
    return verts;
}
 
Example 25
/**
 * Access whichever spatial rotation corresponds to the physics rotation.
 *
 * @return the pre-existing quaternion (in physics-space coordinates, not
 * null)
 */
protected Quaternion getSpatialRotation() {
    if (applyLocal) {
        return spatial.getLocalRotation();
    }
    return spatial.getWorldRotation();
}
 
Example 26
/**
 * This constructor parses the given blender version and stores the result. Some functionalities may differ in different blender
 * versions.
 * @param blenderVersion
 *            the version read from the blend file
 * @param blenderContext
 *            the blender context
 */
public AbstractBlenderHelper(String blenderVersion, BlenderContext blenderContext) {
    this.blenderVersion = Integer.parseInt(blenderVersion);
    this.blenderContext = blenderContext;
    this.fixUpAxis = blenderContext.getBlenderKey().isFixUpAxis();
    if (fixUpAxis) {
        upAxisRotationQuaternion = new Quaternion().fromAngles(-FastMath.HALF_PI, 0, 0);
    }
}
 
Example 27
Source Project: MikuMikuStudio   Source File: BoneTrack.java    License: BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Set the translations, rotations and scales for this bone track
 * @param times a float array with the time of each frame
 * @param translations the translation of the bone for each frame
 * @param rotations the rotation of the bone for each frame
 * @param scales the scale of the bone for each frame
 */
public void setKeyframes(float[] times, Vector3f[] translations, Quaternion[] rotations, Vector3f[] scales) {
    this.setKeyframes(times, translations, rotations);
    assert times.length == scales.length;
    if (scales != null) {
        this.scales = new CompactVector3Array();
        this.scales.add(scales);
        this.scales.freeze();
    }
}
 
Example 28
@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));


}
 
Example 29
public void simpleInitApp() {
//        inputManager.registerKeyBinding("USELOD", KeyInput.KEY_L);

        DirectionalLight dl = new DirectionalLight();
        dl.setDirection(new Vector3f(-1, -1, -1).normalizeLocal());
        rootNode.addLight(dl);

        Node teapotNode = (Node) assetManager.loadModel("Models/Teapot/Teapot.mesh.xml");
        Geometry teapot = (Geometry) teapotNode.getChild(0);

        Material mat = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
        mat.setFloat("Shininess", 16f);
        mat.setBoolean("VertexLighting", true);
        teapot.setMaterial(mat);

        // show normals as material
        //Material mat = new Material(assetManager, "Common/MatDefs/Misc/ShowNormals.j3md");
        flyCam.setMoveSpeed(5);
        for (int y = -5; y < 5; y++) {
            for (int x = -5; x < 5; x++) {
                Geometry clonePot = teapot.clone();

                //clonePot.setMaterial(mat);
                clonePot.setLocalTranslation(x * .5f, 0, y * .5f);
                clonePot.setLocalScale(.15f);
                clonePot.setMaterial(mat);
                rootNode.attachChild(clonePot);
            }
        }
        GeometryBatchFactory.optimize(rootNode, true);
        LodControl control = new LodControl();
        rootNode.getChild(0).addControl(control);
        cam.setLocation(new Vector3f(-1.0748308f, 1.35778f, -1.5380064f));
        cam.setRotation(new Quaternion(0.18343268f, 0.34531063f, -0.069015436f, 0.9177962f));

    }
 
Example 30
@Override
public void simpleInitApp() {
    flyCam.setMoveSpeed(10f);
    cam.setLocation(new Vector3f(6.4013605f, 7.488437f, 12.843031f));
    cam.setRotation(new Quaternion(-0.060740203f, 0.93925786f, -0.2398315f, -0.2378785f));

    DirectionalLight dl = new DirectionalLight();
    dl.setDirection(new Vector3f(-0.1f, -0.7f, -1).normalizeLocal());
    dl.setColor(new ColorRGBA(1f, 1f, 1f, 1.0f));
    rootNode.addLight(dl);

    Spatial model = (Spatial) assetManager.loadModel("Models/Oto/Oto.mesh.xml");
    model.center();

    control = model.getControl(AnimControl.class);
    control.addListener(this);
    channel = control.createChannel();

    for (String anim : control.getAnimationNames())
        System.out.println(anim);

    channel.setAnim("stand");

    SkeletonControl skeletonControl = model.getControl(SkeletonControl.class);

    Box b = new Box(.25f,3f,.25f);
    Geometry item = new Geometry("Item", b);
    item.move(0, 1.5f, 0);
    item.setMaterial(assetManager.loadMaterial("Common/Materials/RedColor.j3m"));
    Node n = skeletonControl.getAttachmentsNode("hand.right");
    n.attachChild(item);

    rootNode.attachChild(model);

    inputManager.addListener(this, "Attack");
    inputManager.addMapping("Attack", new KeyTrigger(KeyInput.KEY_SPACE));
}