Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8276745
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T08:27:56+00:00 2026-06-08T08:27:56+00:00

There’s many answers to this problem, but I’m not sure that they all work

  • 0

There’s many answers to this problem, but I’m not sure that they all work with XTK, such as seeing multiple answers for this in Three.JS, but of course XTK and Three.JS don’t have the same API obviously. Using a ray and Matrix seemed very similar to many other solutions for other frameworks, but I’m still not grasping a possible solution here. For now just finding the coordinates X, Y, and Z and recording them into Console.Log is fine, later I was hoping to create a caption/tooltip to display the information, but there is other ways to display it also. But can someone at least tell me if this is possible to use a ray to collide with the objects? I’m not sure how collision works in XTK with meshes or any other files. Any hints right now would be great!!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T08:27:59+00:00Added an answer on June 8, 2026 at 8:27 am

    Here is my function to unproject in xtk. Please tell me if you see mistakes. Now with the resulting point and the camera position I should be able to find my intersections. To make the computation faster for the following step, I’ll call it in a pick event and so I’ll only have to try the intersections with a given object. If I’ve time i’ll also try with testing the bounding boxes.

    Nota bene : the last lines are not required, I could work on the ray instead of the point.

    X.camera3D.prototype.unproject = function (x,y) {
    
      // get the 4x4 model-view matrix
      var mvMatrix = this._view;
    
      // create the 4x4 projection matrix from the flatten gl version
      var pMatrix = new X.matrix(4,4);
      for (var i=0 ; i<16 ; i++) {
        pMatrix.setValueAt(i - 4*Math.floor(i/4), Math.floor(i/4), this._perspective[i]);
      }
      // compute the product and inverse it
      var mvpMatrxix = pMatrix.multiply(mwMatrix); /** Edit : wrong product corrected **/
      var inverse_mvpMatrix = mvpMatrxix.getInverse();
      if (!goog.isDefAndNotNull(inverse_mvpMatrix)) throw new Error("Could not inverse the transformation matrix.");
    
      // check if x & y are map in [-1,1] interval (required for the computations)
      if (x<-1 || x>1 || y<-1 || y>1) throw new Error("Invalid x or y coordinate, it must be between -1 and 1");
    
      // fill the 4x1 normalized (in [-1,1]⁴) vector of the point of the screen in word camera world's basis
      var point4f = new X.matrix(4,1);
      point4f.setValueAt(0, 0, x);
      point4f.setValueAt(1, 0, y);
      point4f.setValueAt(2, 0, -1.0); // 2*?-1, with ?=0 for near plan and ?=1 for far plan
      point4f.setValueAt(3, 0, 1.0); // homogeneous coordinate arbitrary set at 1
    
      // compute the picked ray in the world's basis in homogeneous coordinates
      var ray4f = inverse_mvpMatrix.multiply(point4f);
      if (ray4f.getValueAt(3,0)==0) throw new Error("Ray is not valid.");
      // return in not-homogeneous coordinates to compute the 3D direction vector
      var point3f = new X.matrix(3,1);
      point3f.setValueAt(0, 0, ray4f.getValueAt(0, 0) / ray4f.getValueAt(3, 0) );
      point3f.setValueAt(1, 0, ray4f.getValueAt(1, 0) / ray4f.getValueAt(3, 0) );
      point3f.setValueAt(2, 0, ray4f.getValueAt(2, 0) / ray4f.getValueAt(3, 0) );
      return point3f;
    };
    

    Edit

    Here, in my repo, you can find functions in camera3D.js and renderer3D.js for efficient 3D picking in xtk.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

There are nice SO question and answers about this issue, but these options didn't
There are plenty of questions and answers to this like this question but I
There is a number of topics on this problem around the web, but I
There are currently two AppExchange apps that do this, but I was wondering if
There is a column that exists in 2 tables. In table 1, this column
There are tons of codes that sort an array of strings lexicographically but I
There are some related questions that I've come across (like this , this ,
There was a thread on this in comp.lang.javascript recently where victory was announced but
I know there's a lot of other questions out there that deal with this
There is a reason why this method doesn't work? -(void)textViewDidBeginEditing:(UITextView *)textView { textView.text =

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.