check_hit_camera Function

private function check_hit_camera(this, hitpoint)

Check if a hitpoint is in the camera detector ref

Type Bound

camera

Arguments

Type IntentOptional Attributes Name
class(camera), intent(inout) :: this
type(hit_t), intent(in) :: hitpoint

Hitpoint to check

Return Value logical


Source Code

    logical function check_hit_camera(this, hitpoint)
        !! Check if a hitpoint is in the camera detector
        !! [ref](https://www.scratchapixel.com/lessons/3d-basic-rendering/minimal-ray-tracer-rendering-simple-shapes/ray-plane-and-ray-disk-intersection)
        class(camera), intent(inout) :: this
        !> Hitpoint to check
        type(hit_t),   intent(in)    :: hitpoint

        real(kind=wp) :: t, proj1, proj2
        type(vector)  :: v

        check_hit_camera = .false.
        if(this%layer /= hitpoint%layer)return

        t = ((this%pos - hitpoint%pos) .dot. this%n) / (hitpoint%dir .dot. this%n)
        if(t >= 0._wp)then
            v = (hitpoint%pos + t * hitpoint%dir) - this%pos
            proj1 = (v .dot. this%e1) / this%width
            proj2 = (v .dot. this%e2) / this%height
            if((proj1 < this%width .and. proj1 > 0._wp) .and. (proj2 < this%height .and. proj2 > 0._wp))then
                check_hit_camera = .true.
            end if
        end if
    end function check_hit_camera