Sha256: e67722e88ff9d68e8a09dc54063ca5cf2c895bc82b7816d69029075c8bf6d7d1

Contents?: true

Size: 1021 Bytes

Versions: 10

Compression:

Stored size: 1021 Bytes

Contents

#
#  Raycast
#
#  by Ricard Marxer
#
#  This example shows how to use the raycasts.
#
load_library :fisica

module Fisica
  include_package 'fisica'
end


attr_reader :world, :obstacle

def setup
  size(400, 400)
  smooth
  
  Fisica::Fisica.init(self)
  
  @world = Fisica::FWorld.new
  
  @obstacle = Fisica::FBox.new(150, 150)
  obstacle.set_rotation(QUARTER_PI)
  obstacle.set_position(width/2, height/2)
  obstacle.set_static(true)
  obstacle.set_fill(0)
  obstacle.set_restitution(0)
  world.add(obstacle)
end

def draw
  background(255)  
  world.draw
  world.step  
  cast_ray
end

def cast_ray
  result = Fisica::FRaycastResult.new
  b = world.raycast_one(width/2, height, mouse_x, mouse_y, result, true)  
  stroke(0)
  line(width/2, height, mouse_x, mouse_y)  
  if (b)
    b.set_fill(120, 90, 120)
    fill(180, 20, 60)
    no_stroke    
    x = result.get_x
    y = result.get_y
    ellipse(x, y, 10, 10)    
  else
    obstacle.set_fill(0)
  end
end

def key_pressed  
  save_frame("screenshot.png")  
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
ruby-processing-2.6.3 samples/external_library/java_processing/fisica/raycast.rb
ruby-processing-2.6.2 samples/external_library/java_processing/fisica/raycast.rb
ruby-processing-2.6.1 samples/external_library/java_processing/fisica/raycast.rb
ruby-processing-2.6.0 samples/external_library/java_processing/fisica/raycast.rb
ruby-processing-2.5.1 samples/external_library/java_processing/fisica/raycast.rb
ruby-processing-2.5.0 samples/external_library/java_processing/fisica/raycast.rb
ruby-processing-2.4.4 samples/external_library/java_processing/fisica/raycast.rb
ruby-processing-2.4.3 samples/external_library/java_processing/fisica/raycast.rb
ruby-processing-2.4.2 samples/external_library/java_processing/fisica/raycast.rb
ruby-processing-2.4.1 samples/external_library/java_processing/fisica/raycast.rb