Module: AkatsukiFace

Defined in:
lib/ext/projector/projector.rb

Constant Summary collapse

SCALE =

body size: 1040mm 1450mm 1400mm

Vector[1040.0/1450.0, 1.0, 1400.0/1450.0, 1.0]
FACES =
[
  {
    'label' => 'loof',
    'angle' => -90.0, 'axis' => Vector[1.0, 0.0, 0.0, 1.0],
    'texture' => [0.00, 0.00, 0.25, 0.50], # left, top, width, height
  },
  {
    'label' => 'front',
    'angle' => 0.0, 'axis' => Vector[0.0, 1.0, 0.0, 1.0],
    'texture' => [0.00, 0.50, 0.25, 0.50],
  },
  {
    'label' => 'floor',
    'angle' => +90.0, 'axis' => Vector[1.0, 0.0, 0.0, 1.0],
    'texture' => [0.25, 0.00, 0.25, 0.50],
  },
  {
    'label' => 'right',
    'angle' => +90.0, 'axis' => Vector[0.0, 1.0, 0.0, 1.0],
    'texture' => [0.25, 0.50, 0.25, 0.50],
  },
  {
    'label' => 'back',
    'angle' => +180.0, 'axis' => Vector[0.0, 1.0, 0.0, 1.0],
    'texture' => [0.50, 0.50, 0.25, 0.50],
  },
  {
    'label' => 'left',
    'angle' => +270.0, 'axis' => Vector[0.0, 1.0, 0.0, 1.0],
    'texture' => [0.75, 0.50, 0.25, 0.50],
  },
]
MESH =

divide MESH x MESH rectangles per a FACE

2
VERTEXS =

the modeling unit: right-hand 3d object coordinates

[
  Vector[0.0, 0.0, +1.0, 1.0], # left bottom
  Vector[1.0, 0.0, +1.0, 1.0], # right bottom
  Vector[1.0, 1.0, +1.0, 1.0], # right top
  Vector[0.0, 1.0, +1.0, 1.0], # left top
]
TEXTURES =

the texture unit: left-hand 2d Gtk::DrawingArea coordinates

[
  Vector[0.0, 1.0], # left bottom
  Vector[1.0, 1.0], # right bottom
  Vector[1.0, 0.0], # right top
  Vector[0.0, 0.0], # left top
]

Class Method Summary collapse

Class Method Details

.createObject



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/ext/projector/projector.rb', line 73

def create
  scale = Matrix3d::scale(SCALE)
  divide = MESH.to_f
  FACES.inject([]) do |list, face|
    transform = scale * Matrix3d::rotate(face['angle'], face['axis'])
    (0 ... MESH).to_a.product((0 ... MESH).to_a).each do |part|
      x, y = part.map{|i| i.to_f }
      v = VERTEXS.map {|c|
        transform * Vector[
          (c[0] + x) * 2.0 / divide - 1.0,
          (c[1] + divide - 1.0 - y) * 2.0 / divide - 1.0,
          c[2],
          c[3]
        ]
      }
      t = TEXTURES.map {|c|
        left, top, width, height = face['texture']
        Vector[
          (c[0] + x) * width / divide + left,
          (c[1] + y) * height / divide + top
        ]
      }

      # to keep simple calculations on S^{-1},
      # we assume s1 - s0 = (s00, 0.0), s2 - s0 = (0.0, s11)
      # left-bottom triangle counterclockwise
      #   (left, bottom) -> (right, bottom) -> (left, top)
      list.push({
        'vertex' => [0, 1, 3].map {|i| v[i] },
        'texture' => [0, 1, 3].map {|i| t[i] },
      })
      # right-top triangle counterclockwise
      #   (right, top) -> (left, top) -> (right, bottom)
      list.push({
        'vertex' => [2, 3, 1].map {|i| v[i] },
        'texture' => [2, 3, 1].map {|i| t[i] },
      })
    end
    list
  end
end