Skip to content

Commit

Permalink
Add projection utils
Browse files Browse the repository at this point in the history
  • Loading branch information
jzy3d committed Jun 23, 2022
1 parent 85b0acb commit 632af16
Showing 1 changed file with 7 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -311,12 +311,14 @@ public void project() {

/** Perform the 3d projection of a 2d coordinate. */
public Coord3d projectMouse(int x, int y) {
Coord3d screen = new Coord3d(x, y, 0.5f);
return projectMouse(screen);
}

/** Perform the 3d projection of a 2d coordinate. The z component of the screen coordinate should be between 0 and 1, representing the position in the depth range*/
public Coord3d projectMouse(Coord3d screen) {
painter.acquireGL();

float averageDistance = cam.getNear() + (cam.getFar() - cam.getNear())/2;

//System.out.println("Near : " + cam.getNear() + " Far : " + cam.getFar() + " D : " + averageDistance);
Coord3d p = cam.screenToModel(painter, new Coord3d(x, y, averageDistance));
Coord3d p = cam.screenToModel(painter, screen);
painter.releaseGL();
return p;
}
Expand Down

0 comments on commit 632af16

Please sign in to comment.