Sha256: 80772c9f4973bd9e9ef563d83f49aa7410fd0a5f1815a9ea35d4206dd1246f1e

Contents?: true

Size: 1.49 KB

Versions: 4

Compression:

Stored size: 1.49 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'

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)
  @gfx = Toxi::ToxiclibsSupport.new(self)
  @positions = []
  # compute mesh positions on circle in XZ plane
  (Toxi::Circle.new(200).toPolygon2D(8)).each do |p|
    positions << p.to3DXZ
  end
end

def draw
  background(51)
  lights
  no_stroke
  translate(width/2,height/2,0)
  rotate_x(-PI/6)
  # 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))
  positions.each do |p|
    # 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
    gfx.mesh(m.copy.pointTowards(focus.sub(p), Toxi::Vec3D::Z_AXIS).translate(p))
  end
  # draw connections from mesh centers to focal point
  stroke(0,255,255)
  positions.each do |p|
    gfx.line(p, focus)
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
ruby-processing-2.4.4 samples/external_library/java_processing/toxiclibs/model_align.rb
ruby-processing-2.4.3 samples/external_library/java_processing/toxiclibs/model_align.rb
ruby-processing-2.4.2 samples/external_library/java_processing/toxiclibs/model_align.rb
ruby-processing-2.4.1 samples/external_library/java_processing/toxiclibs/model_align.rb