Sha256: 5fb6ed09d7995904361fbbcabdfa22d2feccc8ca28bf206d8e2bbf1cac2a26ad

Contents?: true

Size: 1.28 KB

Versions: 2

Compression:

Stored size: 1.28 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-0.5.0+ gem
#
# (c) 2012 Karsten Schmidt / LGPL2 licensed
#
require 'toxiclibs' # gem

# container for mesh positions
attr_reader :gfx, :positions

def settings
  size(640, 480, P3D)
end

def setup
  sketch_title 'Model Align'
  ArcBall.init(self)
  @gfx = Gfx::ToxiclibsSupport.new(self)
  # compute mesh positions on circle in XZ plane
  @positions = (Toxi::Circle.new(200).toPolygon2D(8)).map(&:to3DXZ)
end

def draw
  background(51)
  lights
  no_stroke
  # create manual focal point in XY plane
  focus = TVec3D.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 = AABB.new(25).to_mesh
  # draw focus
  gfx.box(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), TVec3D::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

2 entries across 2 versions & 1 rubygems

Version Path
toxiclibs-2.1.0 examples/model_align.rb
toxiclibs-2.0.0 examples/model_align.rb