We use cookies to ensure that we give you the best experience on our website. If you continue to use this site we will assume that you are happy with it.

Verge3D: get screen coordinate from 3D coordinates?

Home Forums Programming Verge3D: get screen coordinate from 3D coordinates?

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #40100
    elie520
    Participant

    Hi everyone. I’m trying to retrieve the screen coordinates of a Vector3. I’ve been playing with the vector.project method but I can’t get it to work as I’d like. Here’s the best shot I had so far:
    myVec3.project(new v3d.PerspectiveCamera("__DEFAULT_CAMERA__"))
    but it doesn’t work at all.

    If you have any idea, that’d be great!

    Many thanks.

    #40114

    Hi,

    You should use the application’s main camera for that, it’s available from the application instance as app.camera. Also, the project method returns coordinates in range of [-1, 1]. You can convert them to screen pixels like this:

    
    myVec3.project(app.camera);
    
    var width = app.getWidth();
    var height = app.getHeight();
    
    var x = (0.5 + myVec3.x / 2) * width;
    var y = (0.5 - myVec3.y / 2) * height;
    

    Co-founder and lead developer at Soft8Soft.

    #40138
    elie520
    Participant

    Thanks for your answer!

    I ended up solving my problem with v3Copy.project(getObjectByName("__DEFAULT_CAMERA__")) which is essentially the same I guess, except for performance issues. So I’ll use directly the app.camera

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.