| 1 | <html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" > |
| 2 | <head> |
| 3 | <title>Camera rotate of dojox.gfx3d.</title> |
| 4 | <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> |
| 5 | <style type="text/css"> |
| 6 | @import "../../../dojo/resources/dojo.css"; |
| 7 | @import "../../../dijit/tests/css/dijitTests.css"; |
| 8 | @import "../../../dijit/themes/tundra/tundra.css"; |
| 9 | </style> |
| 10 | <script type="text/javascript" src="../../../dojo/dojo.js" data-dojo-config="isDebug: false"></script> |
| 11 | <script type="text/javascript"> |
| 12 | |
| 13 | dojo.require("dojox.gfx3d"); |
| 14 | |
| 15 | var angles = {x: 30, y: 30, z: 0}; |
| 16 | var cube = null; |
| 17 | var view = null; |
| 18 | |
| 19 | rotate = function() { |
| 20 | var m = dojox.gfx3d.matrix; |
| 21 | |
| 22 | if(dojo.byId('rx').checked){ |
| 23 | angles.x += 1; |
| 24 | } |
| 25 | if(dojo.byId('ry').checked){ |
| 26 | angles.y += 1; |
| 27 | } |
| 28 | if(dojo.byId('rz').checked){ |
| 29 | angles.z += 1; |
| 30 | } |
| 31 | var t = m.normalize([ |
| 32 | m.cameraTranslate(-300, -200, 0), |
| 33 | m.cameraRotateXg(angles.x), |
| 34 | m.cameraRotateYg(angles.y), |
| 35 | m.cameraRotateZg(angles.z) |
| 36 | ]); |
| 37 | // console.debug(t); |
| 38 | view.setCameraTransform(t); |
| 39 | view.render(); |
| 40 | } |
| 41 | |
| 42 | makeObjects = function(){ |
| 43 | var surface = dojox.gfx.createSurface("test", 500, 500); |
| 44 | view = surface.createViewport(); |
| 45 | |
| 46 | view.setLights([ |
| 47 | { direction: { x: -10, y: -5, z: 5 }, color: "white"} |
| 48 | ], |
| 49 | { color:"white", intensity: 2 }, |
| 50 | "white" |
| 51 | ); |
| 52 | |
| 53 | var c = {bottom: {x: 0, y: 0, z: 0}, top :{x: 100, y: 100, z: 100}}; |
| 54 | var xaxis = [{x: 0, y: 0, z: 0}, {x: 200, y: 0, z: 0}]; |
| 55 | var yaxis = [{x: 0, y: 0, z: 0}, {x: 0, y: 200, z: 0}]; |
| 56 | var zaxis = [{x: 0, y: 0, z: 0}, {x: 0, y: 0, z: 200}]; |
| 57 | |
| 58 | var m = dojox.gfx3d.matrix; |
| 59 | |
| 60 | view.createEdges(xaxis).setStroke({color: "red", width: 1}); |
| 61 | view.createEdges(yaxis).setStroke({color: "green", width: 1}); |
| 62 | view.createEdges(zaxis).setStroke({color: "blue", width: 1}); |
| 63 | |
| 64 | // setStroke({color: "lime", width: 1}). |
| 65 | cube = view.createCube(c).setFill({ type: "plastic", finish: "dull", color: "lime" }); |
| 66 | |
| 67 | var camera = dojox.gfx3d.matrix.normalize([ |
| 68 | m.cameraTranslate(-300, -200, 0), |
| 69 | m.cameraRotateXg(angles.x), |
| 70 | m.cameraRotateYg(angles.y), |
| 71 | m.cameraRotateZg(angles.z) |
| 72 | ]); |
| 73 | |
| 74 | view.applyCameraTransform(camera); |
| 75 | view.render(); |
| 76 | setInterval(rotate, 50); |
| 77 | }; |
| 78 | |
| 79 | dojo.addOnLoad(makeObjects); |
| 80 | |
| 81 | </script> |
| 82 | </head> |
| 83 | <body class="tundra"> |
| 84 | <h1>Camera rotate</h1> |
| 85 | <p>The cube is in the center (0, 0, 0): The color of X, Y, Z axes are red, green, blue. The view renders all the objects |
| 86 | in each frame, the <em>conservative</em> drawer is used.</p> |
| 87 | <form> |
| 88 | <input id="rx" type="checkbox" name="rotateX" checked="true" value="on"/> |
| 89 | <label for="rx"> Rotate around X-axis</label> <br/> |
| 90 | <input id="ry" type="checkbox" name="rotateY" checked="false" value="off"/> |
| 91 | <label for="ry"> Rotate around Y-axis</label> <br/> |
| 92 | <input id="rz" type="checkbox" name="rotateZ" checked="false" value="off"/> |
| 93 | <label for="rz"> Rotate around Z-axis</label> <br/> |
| 94 | </form> |
| 95 | |
| 96 | <div id="test" style="width: 500px; height: 500px;"></div> |
| 97 | <p>That's all Folks!</p> |
| 98 | </body> |
| 99 | </html> |