plugins/org.symbian.tools.tmw.previewer/preview/script/accelerometer.js
author Eugene Ostroukhov <eugeneo@symbian.org>
Thu, 19 Aug 2010 17:48:04 -0700
changeset 470 d4809db37847
parent 416 org.symbian.tools.wrttools.previewer/preview/script/accelerometer.js@461da1f79f43
child 485 df4f55e8569e
permissions -rw-r--r--
Changed repository layout and renamed project files. This revision is untested and may not run.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
402
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
     1
function RotationSupport(accelerationCallback) {
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
     2
	this.controls = new RotationControls(accelerationCallback);
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
     3
}
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
     4
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
     5
function RotationControls(accelCallback) {
407
c7c8bde493b1 Orientation controls were updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 403
diff changeset
     6
	this.angleX = 0;
c7c8bde493b1 Orientation controls were updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 403
diff changeset
     7
	this.angleY = 0;
c7c8bde493b1 Orientation controls were updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 403
diff changeset
     8
	this.angleZ = 0;
403
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
     9
	var control = this;
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
    10
	this.accelerationCallback = accelCallback;
402
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    11
407
c7c8bde493b1 Orientation controls were updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 403
diff changeset
    12
	setupListeners("xaxis", "xleft", "xright", updateAngleX, this.angleX);
c7c8bde493b1 Orientation controls were updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 403
diff changeset
    13
	setupListeners("yaxis", "yleft", "yright", updateAngleY, this.angleY);
c7c8bde493b1 Orientation controls were updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 403
diff changeset
    14
	setupListeners("zaxis", "zleft", "zright", updateAngleZ, this.angleZ);
c7c8bde493b1 Orientation controls were updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 403
diff changeset
    15
c7c8bde493b1 Orientation controls were updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 403
diff changeset
    16
	window.setTimeout(function() {
412
72448215f517 Bug 2785 - Orientation and Resolution Controls Placements
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 410
diff changeset
    17
		control.paint(true);
407
c7c8bde493b1 Orientation controls were updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 403
diff changeset
    18
	}, 50);
c7c8bde493b1 Orientation controls were updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 403
diff changeset
    19
c7c8bde493b1 Orientation controls were updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 403
diff changeset
    20
	function setupListeners(inputId, leftArrow, rightArrow, fn, initial) {
c7c8bde493b1 Orientation controls were updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 403
diff changeset
    21
		var input = $("#" + inputId);
c7c8bde493b1 Orientation controls were updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 403
diff changeset
    22
		input.numeric();
c7c8bde493b1 Orientation controls were updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 403
diff changeset
    23
		input.val(initial);
c7c8bde493b1 Orientation controls were updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 403
diff changeset
    24
		input.change(function() {
c7c8bde493b1 Orientation controls were updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 403
diff changeset
    25
			adjust(input, fn, 0);
c7c8bde493b1 Orientation controls were updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 403
diff changeset
    26
		});
c7c8bde493b1 Orientation controls were updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 403
diff changeset
    27
		handleButton(leftArrow, input, fn, -1);
c7c8bde493b1 Orientation controls were updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 403
diff changeset
    28
		handleButton(rightArrow, input, fn, 1);
c7c8bde493b1 Orientation controls were updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 403
diff changeset
    29
	}
403
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
    30
407
c7c8bde493b1 Orientation controls were updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 403
diff changeset
    31
	function handleButton(buttonId, input, fn, increment) {
c7c8bde493b1 Orientation controls were updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 403
diff changeset
    32
		var id = false;
c7c8bde493b1 Orientation controls were updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 403
diff changeset
    33
		var timeout = false;
c7c8bde493b1 Orientation controls were updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 403
diff changeset
    34
		var stop = function() {
c7c8bde493b1 Orientation controls were updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 403
diff changeset
    35
			if (timeout) {
c7c8bde493b1 Orientation controls were updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 403
diff changeset
    36
				window.clearTimeout(timeout);
c7c8bde493b1 Orientation controls were updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 403
diff changeset
    37
				timeout = false;
c7c8bde493b1 Orientation controls were updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 403
diff changeset
    38
				adjust(input, fn, increment);
c7c8bde493b1 Orientation controls were updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 403
diff changeset
    39
			}
c7c8bde493b1 Orientation controls were updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 403
diff changeset
    40
			if (id) {
c7c8bde493b1 Orientation controls were updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 403
diff changeset
    41
				window.clearInterval(id);
c7c8bde493b1 Orientation controls were updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 403
diff changeset
    42
				id = false;
c7c8bde493b1 Orientation controls were updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 403
diff changeset
    43
			}
c7c8bde493b1 Orientation controls were updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 403
diff changeset
    44
		};
c7c8bde493b1 Orientation controls were updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 403
diff changeset
    45
c7c8bde493b1 Orientation controls were updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 403
diff changeset
    46
		$("#" + buttonId).mousedown(function() {
413
817cf8083ab8 Bug 3136 - Preview - infinity loop on accelerometer
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 412
diff changeset
    47
			if (!timeout && !id) {
817cf8083ab8 Bug 3136 - Preview - infinity loop on accelerometer
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 412
diff changeset
    48
				timeout = window.setTimeout(function() {
817cf8083ab8 Bug 3136 - Preview - infinity loop on accelerometer
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 412
diff changeset
    49
					id = window.setInterval(function() {
817cf8083ab8 Bug 3136 - Preview - infinity loop on accelerometer
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 412
diff changeset
    50
						timeout = false;
817cf8083ab8 Bug 3136 - Preview - infinity loop on accelerometer
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 412
diff changeset
    51
						adjust(input, fn, increment);
817cf8083ab8 Bug 3136 - Preview - infinity loop on accelerometer
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 412
diff changeset
    52
					}, 10);
817cf8083ab8 Bug 3136 - Preview - infinity loop on accelerometer
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 412
diff changeset
    53
				}, 250);
817cf8083ab8 Bug 3136 - Preview - infinity loop on accelerometer
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 412
diff changeset
    54
			}
817cf8083ab8 Bug 3136 - Preview - infinity loop on accelerometer
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 412
diff changeset
    55
		}).mouseup(stop).focusout(stop).blur(stop).mouseleave(stop).dblclick(
817cf8083ab8 Bug 3136 - Preview - infinity loop on accelerometer
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 412
diff changeset
    56
				stop);
407
c7c8bde493b1 Orientation controls were updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 403
diff changeset
    57
	}
c7c8bde493b1 Orientation controls were updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 403
diff changeset
    58
c7c8bde493b1 Orientation controls were updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 403
diff changeset
    59
	function adjust(input, callback, increment) {
c7c8bde493b1 Orientation controls were updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 403
diff changeset
    60
		var n = parseInt(input.val());
c7c8bde493b1 Orientation controls were updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 403
diff changeset
    61
		if (isNaN(n)) {
c7c8bde493b1 Orientation controls were updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 403
diff changeset
    62
			n = 0;
c7c8bde493b1 Orientation controls were updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 403
diff changeset
    63
		}
c7c8bde493b1 Orientation controls were updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 403
diff changeset
    64
		var val = fix(n + increment);
c7c8bde493b1 Orientation controls were updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 403
diff changeset
    65
		input.val(val);
c7c8bde493b1 Orientation controls were updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 403
diff changeset
    66
		callback(val);
c7c8bde493b1 Orientation controls were updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 403
diff changeset
    67
	}
c7c8bde493b1 Orientation controls were updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 403
diff changeset
    68
c7c8bde493b1 Orientation controls were updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 403
diff changeset
    69
	function fix(n) {
c7c8bde493b1 Orientation controls were updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 403
diff changeset
    70
		while (n < -180) {
c7c8bde493b1 Orientation controls were updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 403
diff changeset
    71
			n = n + 360;
c7c8bde493b1 Orientation controls were updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 403
diff changeset
    72
		}
c7c8bde493b1 Orientation controls were updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 403
diff changeset
    73
		while (n >= 180) {
c7c8bde493b1 Orientation controls were updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 403
diff changeset
    74
			n = n - 360;
c7c8bde493b1 Orientation controls were updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 403
diff changeset
    75
		}
c7c8bde493b1 Orientation controls were updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 403
diff changeset
    76
		return n;
c7c8bde493b1 Orientation controls were updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 403
diff changeset
    77
	}
c7c8bde493b1 Orientation controls were updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 403
diff changeset
    78
c7c8bde493b1 Orientation controls were updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 403
diff changeset
    79
	function updateAngleX(angle) {
c7c8bde493b1 Orientation controls were updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 403
diff changeset
    80
		control.angleX = angle;
403
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
    81
		control.paint();
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
    82
	}
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
    83
407
c7c8bde493b1 Orientation controls were updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 403
diff changeset
    84
	function updateAngleY(angle) {
c7c8bde493b1 Orientation controls were updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 403
diff changeset
    85
		control.angleY = angle;
403
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
    86
		control.paint();
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
    87
	}
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
    88
407
c7c8bde493b1 Orientation controls were updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 403
diff changeset
    89
	function updateAngleZ(angle) {
c7c8bde493b1 Orientation controls were updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 403
diff changeset
    90
		control.angleZ = angle;
403
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
    91
		control.paint();
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
    92
	}
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
    93
}
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
    94
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
    95
RotationControls.prototype.paint = function(ignoreListeners) {
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
    96
	var width = 50, height = 100, depth = 10;
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
    97
	var margin = 5, bottomMargin = 15;
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
    98
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
    99
	var canvas = document.getElementById("phoneposition");
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
   100
	var ctx = canvas.getContext("2d");
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
   101
	ctx.clearRect(0, 0, canvas.width, canvas.height);
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
   102
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
   103
	var r = 62;
402
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   104
412
72448215f517 Bug 2785 - Orientation and Resolution Controls Placements
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 410
diff changeset
   105
	var xy = (180 - this.angleX) * Math.PI / 180;
403
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
   106
	var yz = (this.angleY - 180) * Math.PI / 180;
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
   107
	var xz = (180 - this.angleZ) * Math.PI / 180 + Math.PI / 2;
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
   108
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
   109
	var back = translateBack(xy, xz, yz);
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
   110
	if ((back[0].z + back[2].z) / 2 < 0) {
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
   111
		paint(canvas, ctx, back);
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
   112
	} else {
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
   113
		paint(canvas, ctx, translateFace(xy, xz, yz));
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
   114
		paintScreen(canvas, ctx, translateScreen(xy, xz, yz));
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
   115
	}
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
   116
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
   117
	var dz = 0;
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
   118
	if (back[0].z > back[3].z) {
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
   119
		var bottom = translateBottom(xy, xz, yz);
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
   120
		paint(canvas, ctx, bottom);
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
   121
		dz = bottom[1].y - bottom[0].y;
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
   122
	} else if (back[0].z != back[3].z) {
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
   123
		var top = translateTop(xy, xz, yz);
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
   124
		paint(canvas, ctx, top);
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
   125
		dz = top[1].y - top[0].y;
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
   126
	}
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
   127
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
   128
	if (back[1].z > back[0].z) {
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
   129
		paint(canvas, ctx, translateLeft(xy, xz, yz));
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
   130
	} else if (back[1].z != back[0].z) {
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
   131
		paint(canvas, ctx, translateRight(xy, xz, yz));
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
   132
	}
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
   133
	if (!ignoreListeners) {
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
   134
		var accelX = (back[1].y - back[0].y) / width;
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
   135
		var accelY = (back[0].y - back[3].y) / height;
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
   136
		var accelZ = dz / depth;
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
   137
		notifyAcceleration(accelX, accelY, accelZ);
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
   138
	}
402
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   139
	function translateFace(xy, xz, yz) {
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   140
		var px = width / 2;
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   141
		var py = height / 2;
403
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
   142
		var pz = depth / 2;
402
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   143
		var points = [ {
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   144
			x : px,
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   145
			y : py,
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   146
			z : pz
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   147
		}, {
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   148
			x : px,
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   149
			y : -py,
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   150
			z : pz
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   151
		}, {
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   152
			x : -px,
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   153
			y : -py,
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   154
			z : pz
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   155
		}, {
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   156
			x : -px,
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   157
			y : py,
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   158
			z : pz
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   159
		} ];
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   160
		return rotate(points, xy, xz, yz);
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   161
	}
403
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
   162
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
   163
	function translateScreen(xy, xz, yz) {
402
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   164
		var px = width / 2;
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   165
		var py = height / 2;
403
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
   166
		var pz = depth / 2;
402
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   167
		var points = [ {
403
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
   168
			x : px - margin,
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
   169
			y : py - bottomMargin,
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
   170
			z : pz
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
   171
		}, {
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
   172
			x : px - margin,
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
   173
			y : -py + bottomMargin,
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
   174
			z : pz
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
   175
		}, {
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
   176
			x : -px + margin,
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
   177
			y : -py + margin,
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
   178
			z : pz
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
   179
		}, {
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
   180
			x : -px + margin,
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
   181
			y : py - margin,
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
   182
			z : pz
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
   183
		} ];
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
   184
		return rotate(points, xy, xz, yz);
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
   185
	}
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
   186
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
   187
	function translateBack(xy, xz, yz) {
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
   188
		var px = width / 2;
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
   189
		var py = height / 2;
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
   190
		var pz = -depth / 2;
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
   191
		var points = [ {
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
   192
			x : px,
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
   193
			y : py,
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
   194
			z : pz
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
   195
		}, {
402
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   196
			x : px,
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   197
			y : -py,
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   198
			z : pz
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   199
		}, {
403
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
   200
			x : -px,
402
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   201
			y : -py,
403
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
   202
			z : pz
402
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   203
		}, {
403
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
   204
			x : -px,
402
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   205
			y : py,
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   206
			z : pz
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   207
		} ];
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   208
		return rotate(points, xy, xz, yz);
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   209
	}
403
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
   210
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
   211
	function translateTop(xy, xz, yz) {
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
   212
		var px = width / 2;
402
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   213
		var py = height / 2;
403
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
   214
		var pz = depth / 2;
402
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   215
		var points = [ {
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   216
			x : px,
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   217
			y : -py,
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   218
			z : pz
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   219
		}, {
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   220
			x : px,
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   221
			y : -py,
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   222
			z : -pz
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   223
		}, {
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   224
			x : px,
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   225
			y : py,
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   226
			z : -pz
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   227
		}, {
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   228
			x : px,
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   229
			y : py,
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   230
			z : pz
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   231
		} ];
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   232
		return rotate(points, xy, xz, yz);
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   233
	}
403
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
   234
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
   235
	function translateBottom(xy, xz, yz) {
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
   236
		var px = -width / 2;
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
   237
		var py = height / 2;
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
   238
		var pz = depth / 2;
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
   239
		var points = [ {
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
   240
			x : px,
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
   241
			y : -py,
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
   242
			z : pz
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
   243
		}, {
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
   244
			x : px,
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
   245
			y : -py,
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
   246
			z : -pz
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
   247
		}, {
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
   248
			x : px,
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
   249
			y : py,
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
   250
			z : -pz
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
   251
		}, {
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
   252
			x : px,
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
   253
			y : py,
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
   254
			z : pz
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
   255
		} ];
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
   256
		return rotate(points, xy, xz, yz);
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
   257
	}
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
   258
402
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   259
	function translateLeft(xy, xz, yz) {
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   260
		var px = width / 2;
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   261
		var py = height / 2;
403
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
   262
		var pz = depth / 2;
402
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   263
		var points = [ {
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   264
			x : px,
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   265
			y : py,
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   266
			z : pz
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   267
		}, {
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   268
			x : px,
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   269
			y : py,
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   270
			z : -pz
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   271
		}, {
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   272
			x : -px,
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   273
			y : py,
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   274
			z : -pz
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   275
		}, {
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   276
			x : -px,
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   277
			y : py,
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   278
			z : pz
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   279
		} ];
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   280
		return rotate(points, xy, xz, yz);
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   281
	}
403
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
   282
402
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   283
	function translateRight(xy, xz, yz) {
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   284
		var px = width / 2;
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   285
		var py = -height / 2;
403
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
   286
		var pz = depth / 2;
402
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   287
		var points = [ {
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   288
			x : px,
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   289
			y : py,
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   290
			z : pz
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   291
		}, {
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   292
			x : px,
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   293
			y : py,
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   294
			z : -pz
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   295
		}, {
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   296
			x : -px,
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   297
			y : py,
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   298
			z : -pz
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   299
		}, {
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   300
			x : -px,
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   301
			y : py,
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   302
			z : pz
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   303
		} ];
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   304
		return rotate(points, xy, xz, yz);
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   305
	}
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   306
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   307
	function rotate(points, xy, xz, yz) {
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   308
		var res = new Array();
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   309
		for ( var p in points) {
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   310
			var px = points[p].x;
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   311
			var py = points[p].y;
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   312
			var pz = points[p].z;
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   313
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   314
			var rx = Math.sqrt(px * px + py * py);
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   315
			var angXY = Math.atan(px / py) + (px < 0 ? Math.PI : 0);
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   316
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   317
			px = rx * Math.sin(angXY + xy);
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   318
			py = rx * Math.cos(angXY + xy);
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   319
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   320
			var rz = Math.sqrt(px * px + pz * pz);
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   321
			var angXZ = (px == 0 ? 0 : Math.atan(pz / px))
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   322
					+ (px < 0 ? Math.PI : 0);
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   323
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   324
			px = rz * Math.sin(angXZ + xz);
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   325
			pz = rz * Math.cos(angXZ + xz);
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   326
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   327
			var ry = Math.sqrt(py * py + pz * pz);
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   328
			var angYZ = (pz == 0 ? 0 : Math.atan(py / pz))
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   329
					+ (pz < 0 ? Math.PI : 0);
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   330
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   331
			py = ry * Math.sin(angYZ + yz);
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   332
			pz = ry * Math.cos(angYZ + yz);
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   333
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   334
			res.push( {
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   335
				x : px,
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   336
				y : py,
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   337
				z : pz
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   338
			});
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   339
		}
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   340
		return res;
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   341
	}
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   342
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   343
	function paint(canvas, ctx, points) {
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   344
		var xcoord = canvas.width / 2;
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   345
		var ycoord = canvas.height / 2;
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   346
416
461da1f79f43 Bug 3137 - If console is blank, provide usage instructions
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 413
diff changeset
   347
		ctx.fillStyle = "#FAC82F";
402
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   348
		ctx.strokeStyle = "black";
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   349
		ctx.beginPath();
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   350
		ctx.moveTo(xcoord + points[3].x, ycoord + points[3].y);
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   351
		for (point in points) {
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   352
			ctx.lineTo(xcoord + points[point].x, ycoord + points[point].y);
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   353
		}
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   354
		ctx.fill();
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   355
		ctx.beginPath();
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   356
		ctx.moveTo(xcoord + points[3].x, ycoord + points[3].y);
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   357
		for (point in points) {
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   358
			ctx.lineTo(xcoord + points[point].x, ycoord + points[point].y);
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   359
		}
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   360
		ctx.stroke();
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   361
	}
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   362
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   363
	function paintScreen(canvas, ctx, screen) {
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   364
		var xcoord = canvas.width / 2;
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   365
		var ycoord = canvas.height / 2;
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   366
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   367
		ctx.fillStyle = "grey";
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   368
		ctx.beginPath();
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   369
		ctx.moveTo(xcoord + screen[3].x, ycoord + screen[3].y);
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   370
		for (point in screen) {
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   371
			ctx.lineTo(xcoord + screen[point].x, ycoord + screen[point].y);
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   372
		}
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   373
		ctx.fill();
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   374
	}
403
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
   375
402
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   376
	function notifyAcceleration(x, y, z) {
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   377
		accelerationCallback(x, y, z);
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   378
	}
403
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
   379
};
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
   380
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
   381
RotationSupport.prototype.setAngles = function(x, y, z) {
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
   382
	this.controls.angleX = x;
407
c7c8bde493b1 Orientation controls were updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 403
diff changeset
   383
	this.controls.angleY = z; // It is extremly messy - this UI was developed
c7c8bde493b1 Orientation controls were updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 403
diff changeset
   384
	// separately from the rest and follows
403
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
   385
	this.controls.angleZ = y; // different conventions
407
c7c8bde493b1 Orientation controls were updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 403
diff changeset
   386
c7c8bde493b1 Orientation controls were updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 403
diff changeset
   387
	$("#xaxis").val(this.controls.angleX);
c7c8bde493b1 Orientation controls were updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 403
diff changeset
   388
	$("#yaxis").val(this.controls.angleY);
c7c8bde493b1 Orientation controls were updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 403
diff changeset
   389
	$("#zaxis").val(this.controls.angleZ);
c7c8bde493b1 Orientation controls were updated
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 403
diff changeset
   390
403
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
   391
	this.controls.paint(true);
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
   392
};