Hi,

since there is no gluUnproject in webgl, i tried to make such a function on my own.

The normal order of viewing pipeline is as follows:

(ModelView*Projection*Viewport)*Vertex = Pixelcoordinates
When i want to have object coordinates I have to reverse that order and take the inverse:
Inverse(Viewport*Projection*ModelView)*Pixel

By this far everything is still correct, right?

Now the practice with some code:

```
mvPushMatrix();
mvTranslate([deltaX,deltaY,323);
multMatrix(rotationMatrix);
mvTranslate([-3492595.0,-5341589.0,-907.0]);
var pixel=vec3.create([pixelX,pixelY,0]);
var view=getViewportMatrix(canvas.clientWidth,canvas.clientHeigh);
var pM=pMatrix;
var mvM=mvMatrix;
var vp=mat4.multiply(viewport,pM);
var mvp=mat4.multiply(pM,mvM)
var mvpInv=mat4.inverse(mvp);
var objCoord=mat4.multiplyVec3(mvpInv,pixel)
alert(objCoord[0]/5+objCoord[1]/5+objCoord[2]/5+); //5= w component
mvPopMatrix();
```

and that is the viewport matrix:

```
w/2,0, 0, w/2,
0, h/2,0, h/2,
0, 0, 1, 0,
0, 0, 0, 1
```

The output of alert is: 349251.15 534146.2 122.0

(At this moment i dont know why the output is like that, but that’s not the problem.).

Then the strange thing comes. If i click around in canvas, almost nothing happens to the output of alert. That means the coordinates are almost not changing. The only values that are changed are the one after the point of the transformed object coordinates, e.g. 349251.75, or 349251.05 etc.

It seems to be an viewport-matrix problem. But i don’t know exactly…

Maybe someone of got an idea what is going wrong?

I look forward for your answer

regards