package com.ericsson.tic.vi; import java.util.TimerTask; import java.util.Timer; /** * Performs and schedules updates to the world state. * * @author Sami Matilainen * @version 1.0 (2008-12-04) */ public class WorldTimer extends TimerTask { /** The renderer that this timer is associated with. */ private Renderer r; /** The camera which is associated with the renderer. */ private Camera camera; /** The viewpanel which is the parent of the renderer. */ private ViewPanel pv; /** * Creates a timer. */ public WorldTimer(Renderer r, Camera camera, ViewPanel pv) { this.r = r; this.camera = camera; this.pv = pv; Timer t = new Timer(true); t.schedule(this, 25, 25); } /** * Schedules calls to the update function at regular intervalls. */ public void run() { updateWorld(); } /** * Updates the world state. */ public void updateWorld() { camera.update(); if (pv.transitionStateOn) { // transition state if (pv.globePhasingOut) { r.globeRadius = r.globeRadius - 0.1f; if (r.globeRadius <= 0.0f) { r.globeRadius = 0.0f; pv.globePhasingOut = false; } if (r.globeRadius <= 0.3f) { pv.nodesMovingToPlaneTarget = true; pv.updateNodeTargets(); pv.updateLabelTargets(); } } else if (pv.globePhasingIn) { r.globeRadius = r.globeRadius + 0.1f; if (r.globeRadius >= 1.0f) { r.globeRadius = 1.0f; if (!pv.nodesMovingToGlobeTarget) { pv.globePhasingIn = false; pv.globeViewOn = true; pv.transitionStateOn = false; } } } if (pv.planePhasingOut) { r.planeScale = r.planeScale - 0.1f; if (r.planeScale <= 0.0f) { r.planeScale = 0.0f; pv.planePhasingOut = false; } if (r.planeScale <= 0.3f) { pv.nodesMovingToGlobeTarget = true; pv.updateNodeTargets(); pv.updateLabelTargets(); } } else if (pv.planePhasingIn) { r.planeScale = r.planeScale + 0.1f; if (r.planeScale >= 1.0f) { r.planeScale = 1.0f; if (!pv.nodesMovingToPlaneTarget) { pv.planePhasingIn = false; pv.planeViewOn = true; pv.transitionStateOn = false; } } } if (pv.nodesMovingToPlaneTarget) { r.nodeMoveCounter++; if (r.nodeMoveCounter == 10) { pv.planePhasingIn = true; } if (r.nodeMoveCounter >= 30) { r.nodeMoveCounter = 0; pv.nodesMovingToPlaneTarget = false; } } else if (pv.nodesMovingToGlobeTarget) { r.nodeMoveCounter++; if (r.nodeMoveCounter == 10) { pv.globePhasingIn = true; } if (r.nodeMoveCounter >= 30) { r.nodeMoveCounter = 0; pv.nodesMovingToGlobeTarget = false; } } } for (int i = 0; i < pv.nodeRelArr.length; i++) { pv.nodeRelArr[i].moveTowardsTargets(); } for (int i = 0; i < pv.nodeArr.length; i++) { pv.nodeArr[i].moveTowardsTarget(); pv.nodeArr[i].label.moveTowardsTarget(); } } }