MCPcopy Create free account
hub / github.com/arrayfire/arrayfire / generate_viewport_4rays

Method generate_viewport_4rays

examples/pde/bhrt.cpp:667–752  ·  view source on GitHub ↗

* @brief Generates the initial rays 4-vector position and velocities * (direction) for the simulation * * @return std::pair (pos4, vel4) */

Source from the content-addressed store, hash-verified

665 * @return std::pair<af::array, af::array> (pos4, vel4)
666 */
667 std::pair<af::array, af::array> generate_viewport_4rays() {
668 auto& camera_direction = direction;
669 auto& camera_horizontal = horizontal;
670 auto& camera_vertical = vertical;
671 auto& camera_position = position;
672 auto vfov = fov;
673
674 double viewport_height = 2.0 * focal_length * std::tan(vfov / 2.0);
675 double viewport_width = aspect_ratio * viewport_height;
676
677 // Create rays in equally spaced directions of the viewport
678 af::array viewport_rays = af::constant(0, 3, width, height, f64);
679 viewport_rays +=
680 (af::iota(af::dim4(1, width, 1), af::dim4(1, 1, height), f64) /
681 (width - 1) -
682 0.5) *
683 viewport_width * camera_horizontal;
684 viewport_rays +=
685 (af::iota(af::dim4(1, 1, height), af::dim4(1, width, 1), f64) /
686 (height - 1) -
687 0.5) *
688 viewport_height * camera_vertical;
689 viewport_rays += focal_length * camera_direction;
690 viewport_rays = af::moddims(af::reorder(viewport_rays, 1, 2, 0),
691 af::dim4(width * height, 3))
692 .T();
693
694 // Compute the initial position from which the rays are launched
695 af::array viewport_position = viewport_rays + camera_position;
696 af::array viewport_sph_pos;
697 if (scene != Scene::ROTATE_BH)
698 viewport_sph_pos = cart_to_sph_position(viewport_position);
699 else
700 viewport_sph_pos = cart_to_oblate_position(viewport_position);
701
702 // Normalize the ray directions
703 viewport_rays = normalize3(viewport_rays);
704
705 // Generate the position 4-vector
706 af::array camera_sph_pos;
707 if (scene != Scene::ROTATE_BH)
708 camera_sph_pos = cart_to_sph_position(camera_position);
709 else
710 camera_sph_pos = cart_to_oblate_position(camera_position);
711
712 af::array camera_pos4 =
713 af::join(0, af::constant(0.0, 1, f64), camera_sph_pos);
714 double camera_velocity =
715 1.0 /
716 af::sqrt(norm4(camera_pos4, af::array(4, {1.0, 0.0, 0.0, 0.0})))
717 .scalar<double>();
718 af::array camera_vel4 = af::array(4, {camera_velocity, 0.0, 0.0, 0.0});
719
720 af::array viewport_rays_pos4 = af::join(
721 0, af::constant(0.0, 1, width * height, f64), viewport_sph_pos);
722
723 // Generate the velocity 4-vector by setting the camera to be stationary
724 // with respect to an observer at infinity

Callers 1

raytracingFunction · 0.80

Calls 15

tanFunction · 0.85
constantFunction · 0.85
moddimsFunction · 0.85
cart_to_sph_positionFunction · 0.85
cart_to_oblate_positionFunction · 0.85
normalize3Function · 0.85
sqrtFunction · 0.85
norm4Function · 0.85
cart_to_sph_velocityFunction · 0.85
cart_to_oblate_velocityFunction · 0.85
metric4Function · 0.85
TMethod · 0.80

Tested by

no test coverage detected