<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[How to get the coordinate value through the mouse？]]></title><description><![CDATA[<p dir="auto">Hi, all! How to get the coordinates in the coordinate system through the mouse?<br />
<img src="/assets/uploads/files/1632825039560-cb6629d6-fb99-428a-8883-239763e85860-image.png" alt="cb6629d6-fb99-428a-8883-239763e85860-image.png" class=" img-fluid img-markdown" /><br />
When the mouse clicks here, get the clicked coordinates (1, 0).</p>
<p dir="auto">Maybe a method similar to <code>Vector3</code> requires <code>unproject()</code> to complete?</p>
<p dir="auto">In Threejs：</p>
<pre><code class="language-js">unproject( camera ) {

		return this.applyMatrix4( camera.projectionMatrixInverse ).applyMatrix4( camera.matrixWorld );

	}

</code></pre>
]]></description><link>https://openjscad.nodebb.com/topic/305/how-to-get-the-coordinate-value-through-the-mouse</link><generator>RSS for Node</generator><lastBuildDate>Sun, 14 Jun 2026 07:26:13 GMT</lastBuildDate><atom:link href="https://openjscad.nodebb.com/topic/305.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 28 Sep 2021 10:33:38 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to How to get the coordinate value through the mouse？ on Wed, 29 Sep 2021 08:32:43 GMT]]></title><description><![CDATA[<hr />
<p dir="auto">I use camera-unproject to do coordinate mapping, but the obtained coordinates are obviously wrong.</p>
<p dir="auto">code:</p>
<pre><code class="language-js">    const regl = this.$el
    const handleMouseDown = (e) =&gt; {
      const x = 1 - (e.offsetX / regl.clientWidth) * 2
      const y = (e.offsetY / regl.clientHeight) * 2 - 1

      const point = vec3.fromValues(x, y, 0.5)

      const { projection, view, viewport } = this.camera

      const combinedProjView = mat4.multiply([], projection, view)

      const invProjView = mat4.invert([], combinedProjView)

      const result = unproject([], point, viewport, invProjView)

      console.log('convasSize: ', [regl.clientWidth, regl.clientHeight])
      console.log('viewport: ', viewport)
      console.log('clickPoint: ', [x, y])
      console.log('unproject result:', result)
    }
    this.$el.addEventListener('mousedown', handleMouseDown.bind(this))
</code></pre>
<p dir="auto"><img src="/assets/uploads/files/1632904246061-4a0979ad-ef8d-4af6-80d6-b7a52f92e8f9-image.png" alt="4a0979ad-ef8d-4af6-80d6-b7a52f92e8f9-image.png" class=" img-fluid img-markdown" /><br />
Could it be that I did something wrong?</p>
]]></description><link>https://openjscad.nodebb.com/post/925</link><guid isPermaLink="true">https://openjscad.nodebb.com/post/925</guid><dc:creator><![CDATA[jess yan]]></dc:creator><pubDate>Wed, 29 Sep 2021 08:32:43 GMT</pubDate></item></channel></rss>