Search in sources :

Example 1 with Timing

use of net.drewke.tdme.engine.Timing in project tdme by andreasdr.

the class LevelEditorView method display.

/**
	 * Renders the scene 
	 */
public void display(GLAutoDrawable drawable) {
    // camera
    Camera cam = engine.getCamera();
    // reload entity library
    if (reloadEntityLibrary == true) {
        LevelEditorEntityLibrary entityLibrary = TDMELevelEditor.getInstance().getEntityLibrary();
        for (int i = 0; i < entityLibrary.getEntityCount(); i++) {
            selectedEntity = entityLibrary.getEntityAt(i);
            Tools.oseThumbnail(drawable, selectedEntity);
        }
        reloadEntityLibrary = false;
        TDMELevelEditor.getInstance().getLevelEditorEntityLibraryScreenController().setEntityLibrary();
    }
    // do camera rotation by middle mouse button
    if (mouseRotationX != MOUSE_ROTATION_NONE) {
        camLookRotationY.setAngle(camLookRotationY.getAngle() + mouseRotationX);
        camLookRotationY.update();
        mouseRotationX = 0;
    }
    if (mouseRotationY != MOUSE_ROTATION_NONE) {
        camLookRotationX.setAngle(camLookRotationX.getAngle() + mouseRotationY);
        camLookRotationX.update();
        mouseRotationY = 0;
    }
    // 	transfer keyboard inputs to rotations
    if (keyA)
        camLookRotationY.setAngle(camLookRotationY.getAngle() + 1.0f);
    if (keyD)
        camLookRotationY.setAngle(camLookRotationY.getAngle() - 1.0f);
    if (keyW)
        camLookRotationX.setAngle(camLookRotationX.getAngle() + 1.0f);
    if (keyS)
        camLookRotationX.setAngle(camLookRotationX.getAngle() - 1.0f);
    if (keyMinus)
        camScale += 0.05f;
    if (keyPlus)
        camScale -= 0.05f;
    if (camScale < camScaleMin)
        camScale = camScaleMin;
    if (camScale > camScaleMax)
        camScale = camScaleMax;
    if (keyR) {
        camLookRotationX.setAngle(-45.0f);
        camLookRotationX.update();
        camLookRotationY.setAngle(0.0f);
        camLookRotationY.update();
        cam.getLookAt().set(level.computeCenter());
        camScale = 1.0f;
    }
    // update cam look from rotations if changed
    if (keyA || keyD)
        camLookRotationY.update();
    if (keyW || keyS) {
        if (camLookRotationX.getAngle() > 89.99f)
            camLookRotationX.setAngle(89.99f);
        if (camLookRotationX.getAngle() < -89.99f)
            camLookRotationX.setAngle(-89.99f);
        camLookRotationX.update();
    }
    // look at -> look to vector
    camLookRotationX.getQuaternion().multiply(FORWARD_VECTOR, tmpVector3);
    camLookRotationY.getQuaternion().multiply(tmpVector3, tmpVector3);
    // apply look from rotations
    camLookAtToFromVector.set(tmpVector3).scale(camScale * 10.0f);
    // timing
    Timing timing = engine.getTiming();
    // do camera movement with arrow keys
    camLookRotationY.getQuaternion().multiply(FORWARD_VECTOR, camForwardVector).scale(timing.getDeltaTime() / 1000f * 60f);
    camLookRotationY.getQuaternion().multiply(SIDE_VECTOR, camSideVector).scale(timing.getDeltaTime() / 1000f * 60f);
    if (keyUp)
        cam.getLookAt().sub(tmpVector3.set(camForwardVector).scale(0.1f));
    if (keyDown)
        cam.getLookAt().add(tmpVector3.set(camForwardVector).scale(0.1f));
    if (keyLeft)
        cam.getLookAt().sub(tmpVector3.set(camSideVector).scale(0.1f));
    if (keyRight)
        cam.getLookAt().add(tmpVector3.set(camSideVector).scale(0.1f));
    // mouse panning
    if (mousePanningForward != MOUSE_PANNING_NONE) {
        cam.getLookAt().sub(tmpVector3.set(camForwardVector).scale(mousePanningForward / 30f * camScale));
        mousePanningForward = MOUSE_PANNING_NONE;
    }
    if (mousePanningSide != MOUSE_PANNING_NONE) {
        cam.getLookAt().sub(tmpVector3.set(camSideVector).scale(mousePanningSide / 30f * camScale));
        mousePanningSide = MOUSE_PANNING_NONE;
    }
    // look from with rotations
    cam.getLookFrom().set(cam.getLookAt()).add(camLookAtToFromVector);
    // up vector
    cam.computeUpVector(cam.getLookFrom(), cam.getLookAt(), cam.getUpVector());
    // update grid
    gridCenter.set(cam.getLookAt());
    updateGrid();
    // do GUI
    engine.getGUI().render();
    engine.getGUI().handleEvents();
}
Also used : LevelEditorEntityLibrary(net.drewke.tdme.tools.shared.model.LevelEditorEntityLibrary) Camera(net.drewke.tdme.engine.Camera) Timing(net.drewke.tdme.engine.Timing)

Example 2 with Timing

use of net.drewke.tdme.engine.Timing in project tdme by andreasdr.

the class Object3DBase method computeTransformations.

/**
	 * Pre render step, computes transformations
	 */
public void computeTransformations() {
    // do transformations if we have a animation
    if (baseAnimation.setup != null) {
        Engine engine = Engine.getInstance();
        // animation timing
        Timing timing = engine.getTiming();
        baseAnimation.lastAtTime = baseAnimation.currentAtTime;
        long currentFrameAtTime = timing.getCurrentFrameAtTime();
        long lastFrameAtTime = timing.getLastFrameAtTime();
        // do progress of base animation
        baseAnimation.lastAtTime = baseAnimation.currentAtTime;
        if (lastFrameAtTime != Timing.UNDEFINED) {
            baseAnimation.currentAtTime += currentFrameAtTime - lastFrameAtTime;
        }
        // do progress of overlay animations
        for (AnimationState overlayAnimationState : overlayAnimationsById.getValuesIterator()) {
            overlayAnimationState.lastAtTime = overlayAnimationState.currentAtTime;
            if (lastFrameAtTime != Timing.UNDEFINED) {
                overlayAnimationState.currentAtTime += currentFrameAtTime - lastFrameAtTime;
            }
        }
        // set up parent transformations matrix
        parentTransformationsMatrix.set(model.getImportTransformationsMatrix());
        if (animationProcessingTarget == Engine.AnimationProcessingTarget.CPU_NORENDERING) {
            parentTransformationsMatrix.multiply(transformationsMatrix);
        }
        // calculate transformations matrices
        computeTransformationsMatrices(model.getSubGroups(), parentTransformationsMatrix, baseAnimation, 0);
        // do transformations in group render data
        Object3DGroup.computeTransformations(object3dGroups, transformationsMatrices);
    } else if (animationProcessingTarget == Engine.AnimationProcessingTarget.CPU_NORENDERING) {
        // set up parent transformations matrix
        parentTransformationsMatrix.set(model.getImportTransformationsMatrix());
        if (animationProcessingTarget == Engine.AnimationProcessingTarget.CPU_NORENDERING) {
            parentTransformationsMatrix.multiply(transformationsMatrix);
        }
        // calculate transformations matrices
        computeTransformationsMatrices(model.getSubGroups(), parentTransformationsMatrix, baseAnimation, 0);
        // do transformations in group render data
        Object3DGroup.computeTransformations(object3dGroups, transformationsMatrices);
    }
}
Also used : Timing(net.drewke.tdme.engine.Timing) Engine(net.drewke.tdme.engine.Engine)

Aggregations

Timing (net.drewke.tdme.engine.Timing)2 Camera (net.drewke.tdme.engine.Camera)1 Engine (net.drewke.tdme.engine.Engine)1 LevelEditorEntityLibrary (net.drewke.tdme.tools.shared.model.LevelEditorEntityLibrary)1