Skip to content
Discussion options

You must be logged in to vote

Try the following to see if it will help.

Add this method to your class:

Vec3 EditorScene::unprojectGL(Camera* camera, Point p, float z)
{
    auto pointNear = Vec3(p.x, p.y, 0);
    auto pointFar  = Vec3(p.x, p.y, 1);

    pointNear = camera->unprojectGL(pointNear);
    pointFar  = camera->unprojectGL(pointFar);

    auto x0 = pointNear.x;
    auto y0 = pointNear.y;
    auto z0 = pointNear.z;

    auto x1  = pointFar.x;
    auto y1  = pointFar.y;
    auto z1  = pointFar.z;

    auto x = (((z - z0) / (z1 - z0)) * (x1 - x0)) + x0;
    auto y  = (((z - z0) / (z1 - z0)) * (y1 - y0)) + y0;

    return {x, y, z};
}

Change this line:
Vec3 pos3 = camera->unprojectGL(Vec3(currentTouchPos.x, curr…

Replies: 2 comments 7 replies

Comment options

You must be logged in to vote
6 replies
@rh101
Comment options

rh101 Aug 16, 2025
Collaborator

@aceinetx
Comment options

@rh101
Comment options

rh101 Aug 16, 2025
Collaborator

@aceinetx
Comment options

@rh101
Comment options

rh101 Aug 17, 2025
Collaborator

Comment options

You must be logged in to vote
1 reply
@aceinetx
Comment options

Answer selected by aceinetx
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants