Anders and Briegel in Python
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

91 lines
2.6KB

  1. var gui = {};
  2. gui.prepare = function() {
  3. gui.renderer = new THREE.WebGLRenderer({
  4. "antialias": true
  5. });
  6. gui.renderer.setSize(window.innerWidth, window.innerHeight);
  7. gui.renderer.setClearColor(0xffffff, 1);
  8. document.querySelector("body").appendChild(gui.renderer.domElement);
  9. window.addEventListener("resize", gui.onWindowResize, false);
  10. gui.makeScene();
  11. gui.camera = new THREE.PerspectiveCamera(45, window.innerWidth / window.innerHeight, 0.3, 1000);
  12. gui.controls = new THREE.OrbitControls(gui.camera);
  13. gui.controls.addEventListener("change", gui.render);
  14. gui.controls.center.set(0, 0, 0);
  15. gui.controls.target.set(0, 0, 0);
  16. gui.controls.rotateSpeed = 0.2;
  17. gui.controls.userPanSpeed = 0.1;
  18. gui.camera.position.set(0, 0, 10);
  19. };
  20. // Someone resized the window
  21. gui.onWindowResize = function(evt) {
  22. gui.camera.aspect = window.innerWidth / window.innerHeight;
  23. gui.camera.updateProjectionMatrix();
  24. gui.renderer.setSize(window.innerWidth, window.innerHeight);
  25. gui.render();
  26. };
  27. // Render the current frame to the screen
  28. gui.render = function() {
  29. requestAnimationFrame(function() {
  30. gui.renderer.render(gui.scene, gui.camera);
  31. });
  32. };
  33. // Make the extra bits of gui
  34. gui.makeScene = function() {
  35. gui.scene = new THREE.Scene();
  36. };
  37. // Put an HTML message to the screen
  38. // TODO: write a generic messaging class?
  39. gui.serverMessage = function(msgtext, persist) {
  40. if (persist === undefined) {persist = false;}
  41. server_info.innerHTML = msgtext;
  42. server_info.className = "visible";
  43. clearInterval(gui.ki);
  44. if (!persist){
  45. gui.ki = setInterval(function(){server_info.className="hidden";}, 3000);
  46. }
  47. };
  48. gui.nodeMessage = function(msgtext) {
  49. node_info.innerHTML = msgtext;
  50. node_info.className = "visible";
  51. };
  52. gui.hideNodeMessage = function(){
  53. node_info.className = "hidden";
  54. };
  55. // Set the position of the info popup
  56. gui.setInfoPosition = function(position){
  57. w = node_info.offsetWidth;
  58. h = node_info.offsetHeight;
  59. node_info.style.left = position.x - w/2 + "px";
  60. node_info.style.top = position.y - h -10 + "px";
  61. };
  62. // The main loop
  63. gui.loop = function() {
  64. gui.controls.update();
  65. editor.update();
  66. requestAnimationFrame(gui.loop);
  67. };
  68. // Try to add a qubit at the current mouse position
  69. gui.addQubitAtMouse = function(event) {
  70. this.raycaster.setFromCamera(mouse, camera);
  71. var intersection = this.raycaster.ray.intersectPlane(this.plane);
  72. intersection.x = Math.round(intersection.x);
  73. intersection.y = Math.round(intersection.y);
  74. abj.add_node(Object.keys(vops).length, {
  75. "position": intersection
  76. });
  77. graph.update();
  78. };