Transparency

This commit is contained in:
Thomas FORGIONE 2015-04-23 11:42:36 +02:00
parent 1667488f93
commit 36e4e5b916
1 changed files with 16 additions and 9 deletions

25
prototype/js/main.js vendored
View File

@ -204,7 +204,8 @@ function init() {
window.addEventListener('resize', onWindowResize, false); window.addEventListener('resize', onWindowResize, false);
container.addEventListener('mousedown', function(event) { if (event.which == 1) click(event); }, false); container.addEventListener('mousedown', function(event) { if (event.which == 1) click(event); }, false);
container.addEventListener('mousemove', mouseMove, false); container.addEventListener('mousemove', updateMouse, false);
// container.addEventListener('keydown', updateMouse, false);
camera1.collidableObjects = collidableObjects; camera1.collidableObjects = collidableObjects;
@ -234,6 +235,8 @@ function loadScene() {
} }
function render() { function render() {
updateMouse();
var transform = showArrows ? show : hide; var transform = showArrows ? show : hide;
cameras.map(function(camera) { cameras.map(function(camera) {
if (camera instanceof FixedCamera) { if (camera instanceof FixedCamera) {
@ -312,12 +315,18 @@ function show(object) {
object.traverse(function(object) {object.visible = true;}); object.traverse(function(object) {object.visible = true;});
} }
function mouseMove(event) { function updateMouse(event) {
if (event !== undefined && event.clientX !== undefined) {
mouse.x = event.clientX - renderer.domElement.offsetLeft;
mouse.y = container.offsetHeight - (event.clientY - renderer.domElement.offsetTop);
}
var hovered = pointedCamera(event); var hovered = pointedCamera(event);
if (hovered !== undefined) { if (hovered !== undefined) {
prev.x = event.clientX - renderer.domElement.offsetLeft; prev.x = mouse.x;
prev.y = container.offsetHeight - (event.clientY - renderer.domElement.offsetTop); prev.y = mouse.y;
prev.camera = hovered; prev.camera = hovered;
prev.go = true; prev.go = true;
} else { } else {
@ -334,14 +343,12 @@ function click(event) {
function pointedCamera(event) { function pointedCamera(event) {
var returnCamera; var returnCamera;
var mouse = { var x = (mouse.x / renderer.domElement.width ) * 2 - 1;
x: ((event.clientX - renderer.domElement.offsetLeft) / renderer.domElement.width ) * 2 - 1, var y = - ((container.offsetHeight - mouse.y) / renderer.domElement.height) * 2 + 1;
y: - ((event.clientY - renderer.domElement.offsetTop) / renderer.domElement.height) * 2 + 1
}
var camera = cameras.mainCamera(); var camera = cameras.mainCamera();
var vector = new THREE.Vector3(mouse.x, mouse.y, 0.5); var vector = new THREE.Vector3(x, y, 0.5);
vector.unproject(camera); vector.unproject(camera);
raycaster.set(camera.position, vector.sub(camera.position).normalize()); raycaster.set(camera.position, vector.sub(camera.position).normalize());