Created
June 24, 2013 14:36
-
-
Save skrat/5850508 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
return class Sun extends require('events') | |
constructor: (gui, @bounds, @orientation=104, @elevation=60) -> | |
gui.remember @ | |
super() | |
folder = gui.addFolder('Sun') | |
folder.add(@, 'orientation', 0, 360).onChange(@update) | |
folder.add(@, 'elevation', 0, 90).onChange(@update) | |
@size = @bounds.size.length | |
@center = @bounds.min.add(@bounds.size.div 2, new Vec3) | |
@near = -1 | |
@far = 100 | |
@updateProjection() | |
@view = new Mat4() | |
@rot = new Mat3() | |
@update(true) | |
update: (clipping) => | |
@view.identity() | |
.translateVal3(0, 0, -@size) | |
.rotatex(@elevation) | |
.rotatey(@orientation) | |
.translateVal3([email protected], [email protected], [email protected]) | |
.toMat3 @rot.identity() | |
if clipping | |
@updateClipping() | |
@updateProjection() | |
@update(false) | |
@trigger('change') | |
return @ | |
updateClipping: -> | |
vertices = @bounds.vertices | |
view_inv = @view.invert(new Mat4()) | |
for v in vertices | |
@view.mulVec3(v) | |
z = vertices.map (v) -> v.z | |
@near = Math.min.apply(0, z) | |
@far = Math.max.apply(0, z) | |
console.log(@near, @far) | |
updateProjection: -> | |
@proj = new Mat4().ortho(@near, @far, @size/1.5, -@size/1.5, -@size/1.5, @size/1.5) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment