com.jme3.math.Quaternion Java Examples

The following examples show how to use com.jme3.math.Quaternion. 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
Source File: VirtualTrack.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/**
 * 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 #2
Source File: LevelTerrainToolControl.java    From jmonkeybuilder with 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 #3
Source File: BoneTrack.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * 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 #4
Source File: OpenVRInput.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@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 #5
Source File: TestAnisotropicFilter.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@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 #6
Source File: TestExplosionEffect.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@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
Source File: TestCartoonEdge.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@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 #8
Source File: TestHoveringTank.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
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 #9
Source File: TestOgreComplexAnim.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@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 #10
Source File: BoneTrack.java    From MikuMikuStudio with 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 #11
Source File: CollisionShapePropertyBuilder.java    From jmonkeybuilder with Apache License 2.0 6 votes vote down vote up
@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 #12
Source File: OpenRTSApplication.java    From OpenRTS with 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 #13
Source File: VehicleWheel.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
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 #14
Source File: TestEverything.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@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 #15
Source File: SimpleApplication.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
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 #16
Source File: TestBetterCharacter.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@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 #17
Source File: LWJGLOpenVRViewManager.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
/**
 * updatePose can be called here because appstates are always called before the main renderer. This way we get the latest pose close to when it's supposed to render
 */
public void render() {
    if (environment != null) {
        // grab the observer
        Object obs = environment.getObserver();
        Quaternion objRot;
        Vector3f objPos;
        if (obs instanceof Camera) {
            objRot = ((Camera) obs).getRotation();
            objPos = ((Camera) obs).getLocation();
        } else {
            objRot = ((Spatial) obs).getWorldRotation();
            objPos = ((Spatial) obs).getWorldTranslation();
        }
        // grab the hardware handle
        VRAPI dev = environment.getVRHardware();
        if (dev != null) {

            // update the HMD's position & orientation
            dev.updatePose();
            dev.getPositionAndOrientation(hmdPos, hmdRot);

            if (obs != null) {
                // update hmdPos based on obs rotation
                finalRotation.set(objRot);
                finalRotation.mult(hmdPos, hmdPos);
                finalRotation.multLocal(hmdRot);
}

            finalizeCamera(dev.getHMDVectorPoseLeftEye(), objPos, getLeftCamera());
            finalizeCamera(dev.getHMDVectorPoseRightEye(), objPos, getRightCamera());
        } else {
            getLeftCamera().setFrame(objPos, objRot);
            getRightCamera().setFrame(objPos, objRot);
        }
    }
}
 
Example #18
Source File: SmoothTerrainToolControl.java    From jmonkeybuilder with 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 #19
Source File: SpatialTrack.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * 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 File: SpatialTweens.java    From Lemur with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public RotateSpatial( Spatial target, Quaternion from, Quaternion to, double length ) {
    super(length);
    this.target = target;
    this.from = from.clone();
    this.to = to.clone();
    this.value = from.clone();
}
 
Example #21
Source File: CurvesHelper.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * 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 #22
Source File: TestRenderToCubemap.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@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 File: CameraTweens.java    From Lemur with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public RotateCamera( Camera target, Quaternion from, Quaternion to, double length ) {
    super(length);
    this.target = target;
    this.from = from.clone();
    this.to = to.clone();
    this.value = from.clone();
}
 
Example #24
Source File: CameraMovementState.java    From Lemur with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public void setRotation( Quaternion rotation ) {
    // Do our best
    float[] angle = rotation.toAngles(null);
    this.pitch = angle[0];
    this.yaw = angle[1];
    updateFacing();
}
 
Example #25
Source File: AbstractPhysicsControl.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * 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
Source File: AbstractBlenderHelper.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * 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 File: BoneTrack.java    From MikuMikuStudio with 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
Source File: TestBatchNodeCluster.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@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
Source File: TestBatchLod.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
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
Source File: TestOgreAnim.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@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));
}