Created
July 2, 2013 15:49
-
-
Save javisantana/5910475 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
function vec3(xx, yy, zz) { | |
this.x = xx || 0; | |
this.y = yy || 0; | |
this.z = zz || 0; | |
this.translate = function (d) { return new vec3(this.x+d[0], this.y+d[1],this.z+d[2]) } | |
this.scale = function(s) { return new vec3(s*this.x, s*this.y,s*this.z) } | |
this.rotz = function(ang) { | |
var c = Math.cos(ang) | |
var s = Math.sin(ang) | |
return new vec3(this.x*c - this.y*s,this.y*c + this.x*s, this.z) | |
} | |
this.rotx = function(ang) { | |
var c = Math.cos(ang) | |
var s = Math.sin(ang) | |
return new vec3(this.x,this.y*c - this.z*s, this.z*c + this.y*s); | |
} | |
this.proj = function (perspective) { | |
return new vec3( | |
this.x * ( perspective/ ( perspective + this.z ) ), | |
this.y * ( perspective/ ( perspective + this.z ) ), | |
1 | |
); | |
} | |
} | |
/* | |
* Transform 2d pixel pos of a css3d transformed div | |
*/ | |
function transform3d(pos, w, h) { | |
var v = new vec3(pos.x, pos.y, 0); | |
v = v | |
.translate([-w/2.0, -h/2.0, -50.0]) | |
.rotx(45*Math.PI/180.0) | |
.proj(1000) | |
.translate([w/2.0, h/2.0, 0.0]) | |
return { | |
x: v.x, | |
y: v.y | |
} | |
} | |
function latlonTo3DPixel(map, latlon) { | |
var pos = map.latLngToContainerPoint(latlon); | |
var s = map.getSize() | |
return transform3d(pos, s.x, s.y); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment