Sha256: e2b0438631240f2047aaed4d7b3ae903ff211cb7ca625c87a952ee69cd651e99

Contents?: true

Size: 1.41 KB

Versions: 6

Compression:

Stored size: 1.41 KB

Contents

# This example demonstrates how to rotate a number of meshes
# so that each points towards a common & user controlled focal point.
#
# Requires toxiclibs-0020 or newer
#
# (c) 2012 Karsten Schmidt / LGPL2 licensed
#
load_libraries :toxiclibscore, :toxiclibs_p5, :colorutils, :vecmath

module Toxi
  include_package 'toxi.geom'
  include_package 'toxi.geom.mesh'
  include_package 'toxi.processing'
end

# container for mesh positions

attr_reader :gfx, :positions

def setup
  size(640,480,P3D)
  ArcBall.init(self)
  @gfx = Toxi::ToxiclibsSupport.new(self)
  # compute mesh positions on circle in XZ plane
  @positions = (Toxi::Circle.new(200).toPolygon2D(8)).map{ |p| p.to3DXZ}
end

def draw
  background(51)
  lights
  no_stroke
  # create manual focal point in XY plane
  focus = Toxi::Vec3D.new((mouse_x - width/2), (mouse_y - height/2), 0)
  # create mesh prototype to draw at all generated positions
  # the mesh is a simple box placed at the world origin
  m = Toxi::AABB.new(25).to_mesh
  # draw focus
  gfx.box(Toxi::AABB.new(focus, 5))
  # align the positive z-axis of mesh to point at focus
  # mesh needs to be located at world origin for it to work correctly
  # only once rotated, move it to actual position
  positions.map {|p| gfx.mesh(m.copy.pointTowards(focus.sub(p), Toxi::Vec3D::Z_AXIS).translate(p))}
  
  # draw connections from mesh centers to focal point
  stroke(0,255,255)
  positions.map {|p| gfx.line(p, focus)}
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
ruby-processing-2.6.3 samples/external_library/java_processing/toxiclibs/model_align.rb
ruby-processing-2.6.2 samples/external_library/java_processing/toxiclibs/model_align.rb
ruby-processing-2.6.1 samples/external_library/java_processing/toxiclibs/model_align.rb
ruby-processing-2.6.0 samples/external_library/java_processing/toxiclibs/model_align.rb
ruby-processing-2.5.1 samples/external_library/java_processing/toxiclibs/model_align.rb
ruby-processing-2.5.0 samples/external_library/java_processing/toxiclibs/model_align.rb