setFromCamera method

void setFromCamera(
  1. Vector2 coords,
  2. Camera camera
)

Implementation

void setFromCamera(Vector2 coords, Camera camera) {
  if (camera is PerspectiveCamera) {
    ray.origin.setFromMatrixPosition(camera.matrixWorld);
    ray.direction.set(coords.x, coords.y, 0.5).unproject(camera).sub(ray.origin).normalize();
    this.camera = camera;
  } else if (camera is OrthographicCamera) {
    ray.origin
        .set(coords.x, coords.y, (camera.near + camera.far) / (camera.near - camera.far))
        .unproject(camera); // set origin in plane of camera
    ray.direction.set(0, 0, -1).transformDirection(camera.matrixWorld);
    this.camera = camera;
  } else {
    print('three.Raycaster: Unsupported camera type: ${camera.type}');
  }
}