Created
February 9, 2014 21:44
-
-
Save cubicleDowns/8906426 to your computer and use it in GitHub Desktop.
Example of using an AngularJS directive to interact with a THREEjs factory.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"use strict"; | |
tttApp.directive("selectcube", function(ThreeEnv){ | |
return { | |
restrict: "A", | |
link: function(scope, element){ | |
var offsetLeft = element[0].offsetLeft, | |
offsetTop = element[0].offsetTop, | |
mouseDown = {x: null, y:null}; | |
element.bind('mousedown', function(event){ | |
// normalizing X/Y mousedown positions WRT the canvas position. | |
mouseDown.x = ((event.clientX - event.currentTarget.offsetLeft) / event.currentTarget.width) * 2 - 1; | |
mouseDown.y = -((event.clientY - event.currentTarget.offsetTop) / event.currentTarget.height) * 2 + 1; | |
ThreeEnv.makeSelection(mouseDown); | |
}); | |
} | |
}; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment