aboutsummaryrefslogtreecommitdiff
path: root/includes/js/dojox/gfx3d/tests/test_rotate.html
blob: 53c212f55170942cd9fa7408cfc790ad6ba2c03c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" >
<head>
<title>Rotate test of dojox.gfx3d.</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style type="text/css">
	@import "../../../dojo/resources/dojo.css";
	@import "../../../dijit/tests/css/dijitTests.css";
	@import "../../../dijit/themes/tundra/tundra.css";
</style>
<script type="text/javascript" src="../../../dojo/dojo.js" djConfig="isDebug: true"></script>
<script type="text/javascript">

dojo.require("dojox.gfx3d");

var angles = {x: 0, y: 0, z: 0};
var cube = null;
var view = null;

rotate = function(){
	var m = dojox.gfx3d.matrix;

	if(dojo.byId('rx').checked){
		angles.x += 10;
	}
	if(dojo.byId('ry').checked){
		angles.y += 10;
	}
	if(dojo.byId('rz').checked){
		angles.z += 10;
	}
	var t = m.normalize([
		m.cameraRotateXg(angles.x), 
		m.cameraRotateYg(angles.y), 
		m.cameraRotateZg(angles.z), 
	]);
	cube.setTransform(t);
	cube.invalidate();
	view.render();
}

makeObjects = function(){
	var surface = dojox.gfx.createSurface("test", 500, 500);
	view = surface.createViewport();
	var c = {bottom: {x: 0, y: 0, z: 0}, top: {x: 100, y: 100, z: 100}};
	var xaxis = [
		{x: 0, y: 0, z: 0}, 
		{x: 200, y: 0, z: 0}
	];

	var yaxis = [
		{x: 0, y: 0, z: 0}, 
		{x: 0, y: 200, z: 0}
	];
	
	var zaxis = [
		{x: 0, y: 0, z: 0}, 
		{x: 0, y: 0, z: 200}
	];

	var m = dojox.gfx3d.matrix;

	view.createEdges(xaxis).setStroke({color: "red",   width: 1});
	view.createEdges(yaxis).setStroke({color: "green", width: 1});
	view.createEdges(zaxis).setStroke({color: "blue",  width: 1});

	cube = view.createCube(c).setStroke({color: "lime", width: 1});

	var camera = dojox.gfx3d.matrix.normalize([
		m.cameraRotateXg(20), 
		m.cameraRotateYg(30),
		m.cameraTranslate(-100, -100, 0)
	]);

	view.applyCameraTransform(camera);
	view.render();
	window.setInterval(rotate, 200);

	// add the click event handler
	dojo.connect(dojo.byId("conservative"), "onclick", drawWithConservative);
	dojo.connect(dojo.byId("chart"), "onclick", drawWithChart);
};

draw = function(title, drawer){
	dojo.byId("drawer").innerHTML = title;
	view.setDrawer(drawer);
};

drawWithConservative = function(){
	draw("Conservative", dojox.gfx3d.drawer.conservative);
};

drawWithChart = function(){
	draw("Chart", dojox.gfx3d.drawer.chart);
};

dojo.addOnLoad(makeObjects);

</script>
</head>
<body class="tundra">
	<h1>Pilot Test</h1>
	<p>There are two drawers(well, the name is quite misleading, it means draw-er) in dojox.gfx3d, conservative and chart:</p>
	<ul>
		<li><em>conservative</em> drawer is a pessimist, it assumes that the movement, transformation of objects would take a big fat impact to the viewport, so it not only render the modified objects, but also reorder all the underlying 2D shapes and redraw them.</li>
		<li> <em>chart</em> drawer is an optimist, it assumes the change of the objects does not take effect on the z-order, this is most likely true in chart application. It only render and then draw the modified objects.</li>
	</ul>
	<p>The cube is in the center (0, 0, 0): The color of X, Y, Z axes are red, green, blue as the reference. The cube would rotate around X, Y, Z or their combination, it is up to you.</p>
	<p>Current Drawer: <strong id="drawer">Conservative</strong></p>
<form>
	<input id="conservative" type="button" value="Draw with conservative"/>
	<input id="chart" type="button" value="Draw with chart"/><br />
	<input id="rx" type="checkbox" name="rotateX" checked="true" value="on"/> 
	<label for="rx"> Rotate around X-axis</label> <br/>
	<input id="ry" type="checkbox" name="rotateY" checked="false" value="off"/> 
	<label for="ry"> Rotate around Y-axis</label> <br/>
	<input id="rz" type="checkbox" name="rotateZ" checked="false" value="off"/> 
	<label for="rz"> Rotate around Z-axis</label> <br/>
</form>

<div id="test" style="width: 500px; height: 500px;"></div>
<p>That's all Folks!</p>
</body>
</html>