Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

For OrthographicCamera Raycaster.SetFromCamera() sets ray.origin in the near plane #9009

Closed
wojdyr opened this issue May 26, 2016 · 4 comments

Comments

@wojdyr
Copy link

wojdyr commented May 26, 2016

For orthographic camera Raycaster.SetFromCamera() does:

      } else if ( camera instanceof THREE.OrthographicCamera ) {

        this.ray.origin.set( coords.x, coords.y, - 1 ).unproject( camera );

which sets ray.origin in the camera.near clipping plane, not in the plane of camera.position.
So if I want to set, say, raycaster.far consistently with camera.far I do:

  raycaster.setFromCamera(coords, camera);
  raycaster.far = camera.far - camera.near;

(if this was intended just close this issue.)

Three.js version: r77

@SuberFu
Copy link

SuberFu commented May 26, 2016

Setting it from the "near" clipping plane do make more sense. As any objects closer than the near clipping plane is not visible. Otherwise, you get some weird issue that the ray caster is hitting an object that's not visible due to it being "removed" by the near clipping plane.

The raycaster.far not being the same distance as camera's far clipping plane may be something that's not intuitive.

@WestLangley
Copy link
Collaborator

@wojdyr Yes, this has come up before.

As you point out, the distance returned when raycasting using an orthographic camera is the distance from the near plane -- not the plane of the camera. The distance is still useful for sorting, however.

Since we reject hits that fall outside the raycaster near and far planes, and since the distance calculation is not correct unless near is zero, I expect there is a bug that needs to be fixed.

Who would like to propose a solution that works uniformly throughout the library?

@wojdyr
Copy link
Author

wojdyr commented May 26, 2016

I have no idea what else would need to be changed in the library, but in this particular function ray.origin could be set in the camera plane by replacing - 1 in:

this.ray.origin.set( coords.x, coords.y, - 1 ).unproject( camera );

with (camera.near + camera.far) / (camera.near - camera.far)

@WestLangley
Copy link
Collaborator

@wojdyr That does appear to be correct, and the returned distance from raycasting matches the negative of the z-coordinate of the intersected point in camera space.

@mrdoob mrdoob closed this as completed Jun 8, 2016
wojdyr added a commit to uglymol/uglymol that referenced this issue Jun 22, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants