diff options
Diffstat (limited to 'Master/texmf-dist/doc/latex/movie15/dice.js')
-rw-r--r-- | Master/texmf-dist/doc/latex/movie15/dice.js | 193 |
1 files changed, 107 insertions, 86 deletions
diff --git a/Master/texmf-dist/doc/latex/movie15/dice.js b/Master/texmf-dist/doc/latex/movie15/dice.js index e5561194c32..2050fbcf536 100644 --- a/Master/texmf-dist/doc/latex/movie15/dice.js +++ b/Master/texmf-dist/doc/latex/movie15/dice.js @@ -1,98 +1,119 @@ -////////////////////////// -// add our own lights -////////////////////////// +//////////////////////////////////////////////////////////////////////// +// +// This JavaScript file is a simple concatenation of the files +// `lights.js' and `turntable.js' from the `doc/javascript' directory. +// +//////////////////////////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////////////////// +// +// lights.js +// +// example JavaScript for use with `3Djscript' option of \includemovie +// +// * Adds light sources around the object for better illumination. +// +//////////////////////////////////////////////////////////////////////// + //first remove any scene lights for (var i = scene.lights.count - 1; i >= 0; i--) { scene.lights.removeByIndex(i); } -lights = new Object(); -lights.init = function() { - //from left - l1 = scene.createLight(); - l1.color.set3(1,1,1); - l1.brightness = .4; - l1.direction.set3(1,0,0); //NB: direction, not source! - - //from right - l2 = scene.createLight(); - l2.color.set3(1,1,1); - l2.brightness = .4; - l2.direction.set3(-1,0,0); - - //from bottom - l3 = scene.createLight(); - l3.color.set3(1,1,1); - l3.brightness = .4; - l3.direction.set3(0,0,1); - - //from top - l4 = scene.createLight(); - l4.color.set3(1,1,1); - l4.brightness = .4; - l4.direction.set3(0,0,-1); - - //from front - l5 = scene.createLight(); - l5.color.set3(1,1,1); - l5.brightness = .4; - l5.direction.set3(0,1,0); - - //from back - l6 = scene.createLight(); - l6.color.set3(1,1,1); - l6.brightness = .4; - l6.direction.set3(0,-1,0); -} +//new lights +//from left +l1 = scene.createLight(); +l1.color.set(1,1,1); +l1.brightness = .4; +l1.direction.set(1,0,0); -lights.init(); +//from right +l2 = scene.createLight(); +l2.color.set(1,1,1); +l2.brightness = .4; +l2.direction.set(-1,0,0); -//////////////////////////////////////////////////////////////////////// -// get rid of Gimbal rotation; as a result the z-axis will always be up; -// this part of the script should work off the shelf with _any_ 3D model -//////////////////////////////////////////////////////////////////////// -var max_theta = 88; // maximum pitch (degrees from horizontal) of the camera -var sin_max_theta = Math.sin(max_theta * Math.PI/180); -var tan_max_theta = Math.tan(max_theta * Math.PI/180); +//from bottom +l3 = scene.createLight(); +l3.color.set(1,1,1); +l3.brightness = .4; +l3.direction.set(0,0,1); + +//from top +l4 = scene.createLight(); +l4.color.set(1,1,1); +l4.brightness = .4; +l4.direction.set(0,0,-1); + +//from front +l5 = scene.createLight(); +l5.color.set(1,1,1); +l5.brightness = .4; +l5.direction.set(0,1,0); -mouseEventHandler = new MouseEventHandler(); +//from back +l6 = scene.createLight(); +l6.color.set(1,1,1); +l6.brightness = .4; +l6.direction.set(0,-1,0); + +///////////////////////////////////////////////////////////////////// +// +// turntable.js +// +// JavaScript for use with `3Djscript' option of \includemovie +// +// * Greatly improves the rotational behaviour of the 3D object, +// prevents it from tilting to the side while dragging the mouse. +// This is achieved by suppressing the rolling of the camera about +// its optical axis. +// +///////////////////////////////////////////////////////////////////// + +// maximum pitch (degrees from horizontal) of the camera +var max_alpha = 88; +var min_beta = 90 - max_alpha; // the complement +var cos_min_beta = Math.cos(min_beta * Math.PI/180); +var tan_min_beta = Math.tan(min_beta * Math.PI/180); + +var camera = scene.cameras.getByIndex(0); + +//updates the vertical axis of rotation whenever a predefined view +//is selected from the drop down list in the 3D toolbar +var cameraEventHandler = new CameraEventHandler(); +cameraEventHandler.onEvent = function (e) { + camera.axis_up = camera.up.subtract(camera.position); + camera.axis_up.normalize(); +} +runtime.addEventHandler(cameraEventHandler); + +//suppresses camera rolling and limits camera pitch +var mouseEventHandler = new MouseEventHandler(); mouseEventHandler.onMouseMove = true; -mouseEventHandler.onEvent = function(event) { - if(event.currentTool == runtime.TOOL_NAME_ROTATE) { - var camera = scene.cameras.getByIndex(0); - var c2c = camera.position.subtract(camera.targetPosition); - var roo = c2c.length; - - try { - var sin_theta = c2c.z / roo; - if(sin_theta == 1) {//top view - c2c.z = roo * sin_max_theta; - c2c.y = -c2c.z / tan_max_theta; - c2c.x = 0 - } - else if(sin_theta == -1) {//bottom view - c2c.z = -roo * sin_max_theta; - c2c.y = c2c.z / tan_max_theta; - c2c.x = 0 - } - else if(sin_max_theta < sin_theta){//camera too high - c2c.z = Math.sqrt(c2c.x * c2c.x + c2c.y * c2c.y) * tan_max_theta; - c2c.normalize(); - c2c.scaleInPlace(roo); - } - else if(sin_theta < -sin_max_theta){//camera too low - c2c.z = -Math.sqrt(c2c.x * c2c.x + c2c.y * c2c.y) * tan_max_theta; - c2c.normalize(); - c2c.scaleInPlace(roo); - } - - //corrected camera position - camera.position.set(camera.targetPosition.add(c2c)); - } - catch(e) {} - - camera.roll=0; //z-axis always up +mouseEventHandler.onEvent = function (e) { + var c2c = camera.position.subtract(camera.targetPosition); + var roo = c2c.length; + c2c.normalize(); + cos_beta = c2c.dot(camera.axis_up); //cos of enclosed angle + + //correct the camera position if it is too high or too low + if(Math.abs(cos_beta) > cos_min_beta) { + //auxiliary vectors a & b + var a = camera.axis_up.scale(cos_beta); + var b = c2c.subtract(a); + b.normalize(); + b.scaleInPlace(tan_min_beta * a.length); + + c2c.set(a.add(b)); + c2c.normalize(); + + camera.position.set(camera.targetPosition.add(c2c.scale(roo))); + cos_beta = c2c.dot(camera.axis_up); } -} + //suppress rolling + camera.up.set( + camera.position.add(camera.axis_up).add(c2c.scale(-cos_beta)) + ); +}; runtime.addEventHandler(mouseEventHandler); |