org.symbian.tools.wrttools.previewer/preview/script/accelerometer.js
author Eugene Ostroukhov <eugeneo@symbian.org>
Tue, 29 Jun 2010 17:21:51 -0700
changeset 403 ba20dd5983c7
parent 402 f943a50b6689
child 407 c7c8bde493b1
permissions -rw-r--r--
Acceleration and orientation sensors support
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) {
403
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
     6
	this.angleX = 180;
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
     7
	this.angleY = 180;
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
     8
	this.angleZ = 180;
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
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    12
	$("#sliderX").slider( {
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    13
		slide : updateAngleX,
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    14
		animate : true,
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    15
		max : 360,
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    16
		min : 0,
403
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
    17
		value : this.angleX
402
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    18
	});
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    19
	$("#sliderY").slider( {
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    20
		slide : updateAngleY,
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    21
		animate : true,
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    22
		max : 360,
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    23
		min : 0,
403
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
    24
		value : this.angleY
402
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    25
	});
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    26
	$("#sliderZ").slider( {
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    27
		slide : updateAngleZ,
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    28
		animate : true,
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    29
		max : 360,
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    30
		min : 0,
403
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
    31
		value : this.angleZ
402
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    32
	});
403
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
    33
	this.paint();
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
    34
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
    35
	function updateAngleX(event, ui) {
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
    36
		control.angleX = ui.value;
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
    37
		control.paint();
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
    38
	}
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
    39
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
    40
	function updateAngleY(event, ui) {
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
    41
		control.angleY = ui.value;
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
    42
		control.paint();
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
    43
	}
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
    44
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
    45
	function updateAngleZ(event, ui) {
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
    46
		control.angleZ = ui.value;
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
    47
		control.paint();
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
    48
	}
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
    49
}
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
    50
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
    51
RotationControls.prototype.paint = function(ignoreListeners) {
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
    52
	var width = 50, height = 100, depth = 10;
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
    53
	var margin = 5, bottomMargin = 15;
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
    54
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
    55
	var canvas = document.getElementById("phoneposition");
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
    56
	var ctx = canvas.getContext("2d");
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
    57
	ctx.clearRect(0, 0, canvas.width, canvas.height);
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
    58
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
    59
	var r = 62;
402
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    60
403
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
    61
	var xy = (180 - this.angleX) * Math.PI / 180;
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
    62
	var yz = (this.angleY - 180) * Math.PI / 180;
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
    63
	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
    64
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
    65
	var back = translateBack(xy, xz, yz);
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
    66
	if ((back[0].z + back[2].z) / 2 < 0) {
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
    67
		paint(canvas, ctx, back);
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
    68
	} else {
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
    69
		paint(canvas, ctx, translateFace(xy, xz, yz));
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
    70
		paintScreen(canvas, ctx, translateScreen(xy, xz, yz));
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
    71
	}
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
    72
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
    73
	var dz = 0;
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
    74
	if (back[0].z > back[3].z) {
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
    75
		var bottom = translateBottom(xy, xz, yz);
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
    76
		paint(canvas, ctx, bottom);
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
    77
		dz = bottom[1].y - bottom[0].y;
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
    78
	} else if (back[0].z != back[3].z) {
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
    79
		var top = translateTop(xy, xz, yz);
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
    80
		paint(canvas, ctx, top);
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
    81
		dz = top[1].y - top[0].y;
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
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
    84
	if (back[1].z > back[0].z) {
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
    85
		paint(canvas, ctx, translateLeft(xy, xz, yz));
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
    86
	} else if (back[1].z != back[0].z) {
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
    87
		paint(canvas, ctx, translateRight(xy, xz, yz));
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
    88
	}
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
    89
	if (!ignoreListeners) {
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
    90
		var accelX = (back[1].y - back[0].y) / width;
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
    91
		var accelY = (back[0].y - back[3].y) / height;
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
    92
		var accelZ = dz / depth;
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
    93
		notifyAcceleration(accelX, accelY, accelZ);
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
    94
	}
402
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    95
	function translateFace(xy, xz, yz) {
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    96
		var px = width / 2;
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    97
		var py = height / 2;
403
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
    98
		var pz = depth / 2;
402
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    99
		var points = [ {
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   100
			x : px,
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   101
			y : py,
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   102
			z : pz
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   103
		}, {
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   104
			x : px,
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   105
			y : -py,
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   106
			z : pz
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   107
		}, {
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   108
			x : -px,
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   109
			y : -py,
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   110
			z : pz
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   111
		}, {
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   112
			x : -px,
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   113
			y : py,
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   114
			z : pz
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   115
		} ];
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   116
		return rotate(points, xy, xz, yz);
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   117
	}
403
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
   118
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
   119
	function translateScreen(xy, xz, yz) {
402
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   120
		var px = width / 2;
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   121
		var py = height / 2;
403
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
   122
		var pz = depth / 2;
402
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   123
		var points = [ {
403
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
   124
			x : px - margin,
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
   125
			y : py - bottomMargin,
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
   126
			z : pz
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
			x : px - margin,
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
   129
			y : -py + bottomMargin,
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
   130
			z : pz
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
   131
		}, {
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
   132
			x : -px + margin,
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
   133
			y : -py + margin,
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
   134
			z : pz
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
   135
		}, {
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
   136
			x : -px + margin,
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
   137
			y : py - margin,
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
   138
			z : pz
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
   139
		} ];
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
   140
		return rotate(points, xy, xz, yz);
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
   141
	}
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
   142
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
   143
	function translateBack(xy, xz, yz) {
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
   144
		var px = width / 2;
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
   145
		var py = height / 2;
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
   146
		var pz = -depth / 2;
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
   147
		var points = [ {
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
   148
			x : px,
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
   149
			y : py,
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
   150
			z : pz
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
   151
		}, {
402
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
		}, {
403
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
   156
			x : -px,
402
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   157
			y : -py,
403
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
   158
			z : pz
402
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   159
		}, {
403
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
   160
			x : -px,
402
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   161
			y : py,
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   162
			z : pz
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   163
		} ];
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   164
		return rotate(points, xy, xz, yz);
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   165
	}
403
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
   166
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
   167
	function translateTop(xy, xz, yz) {
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
   168
		var px = width / 2;
402
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   169
		var py = height / 2;
403
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
   170
		var pz = depth / 2;
402
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   171
		var points = [ {
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   172
			x : px,
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   173
			y : -py,
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   174
			z : pz
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   175
		}, {
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   176
			x : px,
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   177
			y : -py,
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   178
			z : -pz
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   179
		}, {
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   180
			x : px,
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   181
			y : py,
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   182
			z : -pz
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   183
		}, {
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   184
			x : px,
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   185
			y : py,
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   186
			z : pz
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   187
		} ];
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   188
		return rotate(points, xy, xz, yz);
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   189
	}
403
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
   190
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
   191
	function translateBottom(xy, xz, yz) {
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
   192
		var px = -width / 2;
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
   193
		var py = height / 2;
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
   194
		var pz = depth / 2;
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
   195
		var points = [ {
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
   196
			x : px,
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
   197
			y : -py,
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
   198
			z : pz
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
   199
		}, {
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
   200
			x : px,
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
   201
			y : -py,
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
   202
			z : -pz
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
   203
		}, {
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
   204
			x : px,
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
   205
			y : py,
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
   206
			z : -pz
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
   207
		}, {
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
   208
			x : px,
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
   209
			y : py,
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
   210
			z : pz
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
   211
		} ];
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
   212
		return rotate(points, xy, xz, yz);
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
   213
	}
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
   214
402
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   215
	function translateLeft(xy, xz, yz) {
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   216
		var px = width / 2;
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   217
		var py = height / 2;
403
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
   218
		var pz = depth / 2;
402
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   219
		var points = [ {
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
			x : -px,
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   233
			y : py,
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   234
			z : pz
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   235
		} ];
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   236
		return rotate(points, xy, xz, yz);
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   237
	}
403
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
   238
402
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   239
	function translateRight(xy, xz, yz) {
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   240
		var px = width / 2;
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   241
		var py = -height / 2;
403
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
   242
		var pz = depth / 2;
402
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   243
		var points = [ {
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   244
			x : px,
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   245
			y : py,
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   246
			z : pz
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   247
		}, {
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   248
			x : px,
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   249
			y : py,
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   250
			z : -pz
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   251
		}, {
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   252
			x : -px,
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   253
			y : py,
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   254
			z : -pz
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   255
		}, {
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   256
			x : -px,
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   257
			y : py,
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   258
			z : pz
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   259
		} ];
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   260
		return rotate(points, xy, xz, yz);
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   261
	}
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   262
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   263
	function rotate(points, xy, xz, yz) {
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   264
		var res = new Array();
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   265
		for ( var p in points) {
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   266
			var px = points[p].x;
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   267
			var py = points[p].y;
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   268
			var pz = points[p].z;
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   269
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   270
			var rx = Math.sqrt(px * px + py * py);
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   271
			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
   272
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   273
			px = rx * Math.sin(angXY + xy);
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   274
			py = rx * Math.cos(angXY + xy);
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
			var rz = Math.sqrt(px * px + pz * pz);
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   277
			var angXZ = (px == 0 ? 0 : Math.atan(pz / px))
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   278
					+ (px < 0 ? Math.PI : 0);
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
			px = rz * Math.sin(angXZ + xz);
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   281
			pz = rz * Math.cos(angXZ + xz);
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   282
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   283
			var ry = Math.sqrt(py * py + pz * pz);
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   284
			var angYZ = (pz == 0 ? 0 : Math.atan(py / pz))
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   285
					+ (pz < 0 ? Math.PI : 0);
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   286
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   287
			py = ry * Math.sin(angYZ + yz);
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   288
			pz = ry * Math.cos(angYZ + yz);
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   289
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   290
			res.push( {
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   291
				x : px,
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   292
				y : py,
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   293
				z : pz
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   294
			});
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
		return res;
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   297
	}
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   298
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   299
	function paint(canvas, ctx, points) {
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   300
		var xcoord = canvas.width / 2;
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   301
		var ycoord = canvas.height / 2;
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   302
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   303
		ctx.fillStyle = "yellow";
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   304
		ctx.strokeStyle = "black";
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   305
		ctx.beginPath();
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   306
		ctx.moveTo(xcoord + points[3].x, ycoord + points[3].y);
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   307
		for (point in points) {
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   308
			ctx.lineTo(xcoord + points[point].x, ycoord + points[point].y);
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   309
		}
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   310
		ctx.fill();
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   311
		ctx.beginPath();
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   312
		ctx.moveTo(xcoord + points[3].x, ycoord + points[3].y);
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   313
		for (point in points) {
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   314
			ctx.lineTo(xcoord + points[point].x, ycoord + points[point].y);
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   315
		}
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   316
		ctx.stroke();
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   317
	}
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   318
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   319
	function paintScreen(canvas, ctx, screen) {
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   320
		var xcoord = canvas.width / 2;
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   321
		var ycoord = canvas.height / 2;
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   322
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   323
		ctx.fillStyle = "grey";
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   324
		ctx.beginPath();
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   325
		ctx.moveTo(xcoord + screen[3].x, ycoord + screen[3].y);
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   326
		for (point in screen) {
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   327
			ctx.lineTo(xcoord + screen[point].x, ycoord + screen[point].y);
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   328
		}
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   329
		ctx.fill();
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   330
	}
403
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
   331
402
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   332
	function notifyAcceleration(x, y, z) {
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   333
		accelerationCallback(x, y, z);
f943a50b6689 Acceleration and orientation - initial cut
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   334
	}
403
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
   335
};
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
   336
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
   337
RotationSupport.prototype.setAngles = function(x, y, z) {
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
   338
	this.controls.angleX = x;
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
   339
	this.controls.angleY = z; // It is extremly messy - this UI was developed separately from the rest and follows 
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
   340
	this.controls.angleZ = y; // different conventions
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
   341
	$("#sliderX").slider( {
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
   342
		value : x
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
   343
	});
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
   344
	$("#sliderY").slider( {
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
   345
		value : z
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
   346
	});
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
   347
	$("#sliderZ").slider( {
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
   348
		value : y
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
   349
	});
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
   350
	this.controls.paint(true);
ba20dd5983c7 Acceleration and orientation sensors support
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 402
diff changeset
   351
};