I'm trying to find a point (screen to world coordinates) in my data by using the following code (based on Click to zoom in WebGL):
var world1 = [0,0,0,0] ;
var world2 = [0,0,0,0] ;
var dir = [0,0,0] ;
var w = event.srcElement.clientWidth ;
var h = event.srcElement.clientHeight ;
// calculate x,y clip space coordinates
var x = (event.offsetX-w/2)/(w/2) ;
var y = -(event.offsetY-h/2)/(h/2) ;
mat4.inverse(pvMatrix, pvMatrixInverse) ;
// convert clip space coordinates into world space
mat4.multiplyVec4(pvMatrixInverse, [x,y,0,1], world1) ;
for simplicity's sake I have set up a series of vertices where the z coordinate is always 0: coordinates I'm graphing:
0.0 0.0 0.0 1.0 1.0 0.0 1.0 0.0 0.0 0.0 1.0 0.0 0.5 0.5 0.0
Then I compare the values in world1 to my vertices. The values in world1 do not match to where I know I've clicked. Can anyone help with this?