JSCAD User Group
    • Tags
    • Popular
    • Users
    • Groups
    • Register
    • Login

    How to get the coordinate value through the mouse?

    Scheduled Pinned Locked Moved Development Discussions
    2 Posts 1 Posters 893 Views 1 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • jess yanJ Offline
      jess yan
      last edited by jess yan

      Hi, all! How to get the coordinates in the coordinate system through the mouse?
      cb6629d6-fb99-428a-8883-239763e85860-image.png
      When the mouse clicks here, get the clicked coordinates (1, 0).

      Maybe a method similar to Vector3 requires unproject() to complete?

      In Threejs:

      unproject( camera ) {
      
      		return this.applyMatrix4( camera.projectionMatrixInverse ).applyMatrix4( camera.matrixWorld );
      
      	}
      
      
      1 Reply Last reply Reply Quote 0
      • jess yanJ Offline
        jess yan
        last edited by


        I use camera-unproject to do coordinate mapping, but the obtained coordinates are obviously wrong.

        code:

            const regl = this.$el
            const handleMouseDown = (e) => {
              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))
        

        4a0979ad-ef8d-4af6-80d6-b7a52f92e8f9-image.png
        Could it be that I did something wrong?

        1 Reply Last reply Reply Quote 0

        Hello! It looks like you're interested in this conversation, but you don't have an account yet.

        Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

        With your input, this post could be even better 💗

        Register Login
        • First post
          Last post
        Powered by NodeBB | Contributors