Last active
August 29, 2015 14:10
-
-
Save lazd/65043426c8b01b2bdd4c to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| var boxMaterial = new THREE.LineBasicMaterial({ | |
| color: new THREE.Color('red') | |
| }); | |
| // Create the lines for the "2D box" | |
| var boxGeometry = new THREE.Geometry(); | |
| boxGeometry.vertices.push(new THREE.Vector3(-1, 0, 0)); | |
| boxGeometry.vertices.push(new THREE.Vector3( 0, 1, 0)); | |
| boxGeometry.vertices.push(new THREE.Vector3( 1, 0, 0)); | |
| boxGeometry.vertices.push(new THREE.Vector3( 0, -1, 0)); | |
| boxGeometry.vertices.push(new THREE.Vector3(-1, 0, 0)); | |
| var box = new THREE.Line(boxGeometry, boxMaterial); | |
| box.position.z = -100; | |
| camera.add(box); | |
| // Position the box over an arbitrary point elsewhere in space | |
| var ratio = window.innerWidth/window.innerHeight; | |
| var verticalFov = this.game.camera.fov; | |
| var horizontalFov = Math.toDegrees(2 * Math.atan(Math.tan(Math.toRadians(verticalFov)/2) * (ratio))); | |
| // Project to NDC | |
| var pos = targetMesh.position.project(this.game.camera); | |
| // Sorta project back? | |
| box.position.x = pos.x * ratio * verticalFov; | |
| box.position.y = pos.y * 1/ratio * horizontalFov; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment