Note that there are some explanatory texts on larger screens.

plurals
  1. POvec3.unproject() mouse collision problems
    primarykey
    data
    text
    <pre><code>var fNearZ = -100.0; var farZ = 100.0; var fZoom = 10.0; var iR = this.iWidth/fZoom; var iL = (this.iWidth/fZoom)*(-1); var iT = this.iHeight/fZoom; var iB = (this.iHeight/fZoom)*(-1); var pMatrix = new mat4.ortho(iL, iR, iB, iT, fNearZ, farZ); var mvMatrix = new mat4.create(); mat4.identity(mvMatrix); zI.debug(mat4.str(mvMatrix),{'grp':'mv_before','style':'color:#060;'}); mat4.translate(mvMatrix, [0.0, 0.0, -50.0]); mat4.scale(mvMatrix, [3, 3, 3]); zI.debug(vec3.unproject([ parseFloat(this.pLastMouse.x-this.iLeft), parseFloat(this.pLastMouse.y-this.iTop), 0 ], mvMatrix, pMatrix, [ 0, 0, this.iWidth, this.iHeight ]),{'grp':'dest____','style':'color:#00F;'}); this.setMatrices(pMatrix, mvMatrix); //After this line, buffers will be set </code></pre> <p><img src="https://i.stack.imgur.com/au2ac.png" alt="Screen of 16x16 Planes with 0.1 offset between"> SCREEN URL: <a href="https://i.stack.imgur.com/au2ac.png" rel="nofollow noreferrer">http://i.stack.imgur.com/au2ac.png</a></p> <p>Today I've tried to realize my mouse-collision with the new version of gl-matrix, providing vec3.unproject. What I want is to get the z-world-coordinate of the mouse-position. As you can see on the Screenshot, the x and y coordinates are ok, but the z-coordinate is always 50, no matter where the cursor befinds.</p> <p>Each of the planes is 1.0x1.0 with 0.1 space between.</p> <p>When I add rotation or translation on the Y-Axis, I'm receiving wrong(?) x- and y- coordinates from unproject. I think the way I handle mvMatrix and pMatrix is wrong. Can anyone please help me?</p> <p><strong>EDIT</strong> Without using .translate() and .scale() functions I'm getting the correct values of zNear and zFar right now, still don't know if the coordinates are correct, when I apply these functions to the modelview-matrix. What's still missing is the intersection-calculation.</p> <p><strong>Link to my source:</strong> <a href="http://jsfiddle.net/matthoz/vucAq/" rel="nofollow noreferrer">http://jsfiddle.net/matthoz/vucAq/</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload