samples/07_advanced_rendering/03_render_target_viewports/app/main.rb
def rect_to_rect_tech_demo
    x = 460

    outputs.labels << small_label(x, 17.5, "Click inside the red box below.") # label with instructions
    red_box = [460, 250, 355, 90, 170, 0, 0] # definition of the red box
    outputs.borders << red_box # output as a border (not filled in)

    # If the mouse is clicked inside the red box, two collision boxes are created.
    if inputs.mouse.click
      if inputs.mouse.click.point.inside_rect? red_box
        if !state.box_collision_one # if the collision_one box does not yet have a definition
          # Subtracts 25 from the x and y positions of the click point in order to make the click point the center of the box.
          # You can try deleting the subtraction to see how it impacts the box placement.
          state.box_collision_one = [inputs.mouse.click.point.x - 25, inputs.mouse.click.point.y - 25, 50, 50, 180, 0,   0, 180]  # sets definition
        elsif !state.box_collision_two # if collision_two does not yet have a definition
          state.box_collision_two = [inputs.mouse.click.point.x - 25, inputs.mouse.click.point.y - 25, 50, 50,   0, 0, 180, 180] # sets definition
        else
          state.box_collision_one = nil # both boxes are empty
          state.box_collision_two = nil
        end
      end
    end

    # If collision boxes exist, they are output onto screen inside the red box as solids
    if state.box_collision_one
      outputs.solids << state.box_collision_one
    end

    if state.box_collision_two
      outputs.solids << state.box_collision_two
    end

    # Outputs whether or not the two collision boxes intersect.
    if state.box_collision_one && state.box_collision_two # if both collision_boxes are defined (and not nil or empty)
      if state.box_collision_one.intersect_rect? state.box_collision_two # if the two boxes intersect
        outputs.labels << small_label(x, 23.5, 'The boxes intersect.')
      else # otherwise, if the two boxes do not intersect
        outputs.labels << small_label(x, 23.5, 'The boxes do not intersect.')
      end
    else
      outputs.labels << small_label(x, 23.5, '--') # if the two boxes are not defined (are nil or empty), this label is output
    end
  end
# Outputs a red box onto the screen. A mouse click from the user inside of the red box will output
# a smaller box. If two small boxes are inside of the red box, it will be determined whether or not
# they intersect.
Outputs a red box onto the screen. A mouse click from the user inside of the red box will output
a smaller box. If two small boxes are inside of the red box, it will be determined whether or not
they intersect.
Outputs a red box onto the screen . A mouse click from the user inside of the red box will output a smaller box . If two small boxes are inside of the red box it will be determined whether or not they intersect .
def rect_to_rect_tech_demo
    x = 460
    outputs.labels << small_label(x, 17.5, "Click inside the red box below.") 
    red_box = [460, 250, 355, 90, 170, 0, 0] 
    outputs.borders << red_box 
    if inputs.mouse.click
      if inputs.mouse.click.point.inside_rect? red_box
        if !state.box_collision_one 
          state.box_collision_one = [inputs.mouse.click.point.x - 25, inputs.mouse.click.point.y - 25, 50, 50, 180, 0,   0, 180]  
        elsif !state.box_collision_two 
          state.box_collision_two = [inputs.mouse.click.point.x - 25, inputs.mouse.click.point.y - 25, 50, 50,   0, 0, 180, 180] 
        else
          state.box_collision_one = nil 
          state.box_collision_two = nil
        end
      end
    end
    if state.box_collision_one
      outputs.solids << state.box_collision_one
    end
    if state.box_collision_two
      outputs.solids << state.box_collision_two
    end
    if state.box_collision_one && state.box_collision_two 
      if state.box_collision_one.intersect_rect? state.box_collision_two 
        outputs.labels << small_label(x, 23.5, 'The boxes intersect.')
      else 
        outputs.labels << small_label(x, 23.5, 'The boxes do not intersect.')
      end
    else
      outputs.labels << small_label(x, 23.5, '--') 
    end
  end
def rect_to_rect_tech_demo x = 460 outputs . labels << small_label ( x , 17.5 , "Click inside the red box below." ) red_box = [ 460 , 250 , 355 , 90 , 170 , 0 , 0 ] outputs . borders << red_box if inputs . mouse . click if inputs . mouse . click . point . inside_rect? red_box if ! state . box_collision_one state . box_collision_one = [ inputs . mouse . click . point . x - 25 , inputs . mouse . click . point . y - 25 , 50 , 50 , 180 , 0 , 0 , 180 ] elsif ! state . box_collision_two state . box_collision_two = [ inputs . mouse . click . point . x - 25 , inputs . mouse . click . point . y - 25 , 50 , 50 , 0 , 0 , 180 , 180 ] else state . box_collision_one = nil state . box_collision_two = nil end end end if state . box_collision_one outputs . solids << state . box_collision_one end if state . box_collision_two outputs . solids << state . box_collision_two end if state . box_collision_one && state . box_collision_two if state . box_collision_one . intersect_rect? state . box_collision_two outputs . labels << small_label ( x , 23.5 , 'The boxes intersect.' ) else outputs . labels << small_label ( x , 23.5 , 'The boxes do not intersect.' ) end else outputs . labels << small_label ( x , 23.5 , '--' ) end end
Outputs a red box onto the screen.
Outputs a red box onto the screen .
# label with instructions # definition of the red box # output as a border (not filled in) # If the mouse is clicked inside the red box, two collision boxes are created. # if the collision_one box does not yet have a definition # Subtracts 25 from the x and y positions of the click point in order to make the click point the center of the box. # You can try deleting the subtraction to see how it impacts the box placement. # sets definition # if collision_two does not yet have a definition # sets definition # both boxes are empty # If collision boxes exist, they are output onto screen inside the red box as solids # Outputs whether or not the two collision boxes intersect. # if both collision_boxes are defined (and not nil or empty) # if the two boxes intersect # otherwise, if the two boxes do not intersect # if the two boxes are not defined (are nil or empty), this label is output