Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 5.3

JS API - updates required

...

Code Block
themeRDark
languagejavascript
linenumberstrue
function whatever(elapsedTime, originalVal, delta, duration) {
	// elapsedTime = number of ms since tween started
	// originalVal = value at start of twean
	// delta = targetValue-originalValue
	//         ...where targetValue is what you want at the end of the tween
	//         The C++ code only needs to calculate the delta once at start of tween
	// duration = total duration of the tween in ms
 
	var valAtCurrentTime = // some math
	return valAtCurrentTime;
}

(This would also mean other things could use those easing functions - such as setSunIntensity() and setSunPosition(). You could even have an AI that tweens it's aggression from A to B during the first 10 mins of the game.)

Demos of the various algorithms can be seen here, and BSD-licensed source code (in actionscript) is available here – very easy to port to JS. Functions requiring additional params can be curried.

...

  • getCameraPosition() – returns current position of camera (POINT object)
  • cameraPosition([walk[, crab[, float[, duration[, easing]]]]]) – a combination of the 3 functions below, specify null for any of walk/crab/float if you don't want to alter. Call function without any params to stop all position transitions.
    • cameraWalk(distance[, duration[, easing]]) – like ↑ and ↓ keyboard shortcuts in-game, +ve distance = forward, -ve = backwards, 0 = stop
    • cameraCrab(distance[, duration[, easing]]) – like ← and → keyboard shortcuts in-game, -ve distance = left, +ve distance = right, 0 = stop
    • cameraFloat(distance[, duration[, easing]]) – lift or drop the height of the camera, +ve distance = move up, -ve distance = move down, 0 = stop
  • centreView(x, y) – the camera instantly moves to look at an x,y location (ie. no transition or easing) [does this also change lens pan/tilt?]
  • cameraSlide(x, y[, duration[, easing]]) – the camera slides over terrain to specified position – can we add 'duration' and 'easing' params, with duration defaulting to whatever current duration is?
  • eventCameraPosition(beforeChange) – triggered just before a position change, or just after a position transition ends

...

Is it worth ditching the individual functions for walk, crab and float to reduce number of functions?

(The events are important in the case of "recording" manual camera moves in a cut-scene editor.)

Camera lens:

Note: As it's a virtual camera, I've treated roll as if it's an attribute of the lens (whereas in real-life you actually roll the entire camera). Roll just seemed to fit better here, as it doesn't change the POINT position of the camera.

  • getCameraLens() – return object with pan, tilt, roll, zoom properties
  • cameraLens([pan[, tilt[, roll[, zoom[, duration[, easing]]]]]]) – a combination of the 4 functions below, specify null for any of pan/tilt/roll/zoom if you don't want to alter. call function without any params to stop all lens transitions.
    • cameraPan(angle[, duration[, easing]]) – look left (-ve angle) or right (+ve angle), in relation to north, like Ctrl + Left/Right mouse-drag in-game
    • cameraTilt(angle[, duration[, easing]]) – look up (+ve angle) or down (-ve angle), in relation to horizon, like Ctrl + Up/Down mouse-drag in-game
    • cameraRoll(angle[, duration[, easing]]) – like tilting your head to the side, +ve angle to the right, -ve angle to the left, 0º for no tilt (horizontal camera).
    • cameraZoom() – add optional 'easing' parameter, could 'time' param be renamed to 'duration'?
  • eventCameraLens(beforeChange) – triggered just before a lens change occurs, or just after a lens transition ends

...