Module: Bayonetta::ExpKeyInterpolate

Instance Method Summary collapse

Instance Method Details

#interpol(position, start, stop, key_index) ⇒ Object

[View source]

47
48
49
50
51
52
53
54
55
56
# File 'lib/bayonetta/exp.rb', line 47

def interpol(position, start, stop, key_index)
  p_0 = get_p(key_index)
  p_1 = get_p(key_index + 1)
  m_0 = get_m1(key_index)
  m_1 = get_m0(key_index + 1)
  t = (value - start).to_f / (stop - start)
  t3 = t*t*t
  t2 = t*t
  (2 * t3 - 3 * t2 + 1)*p_0 + (t3 - 2 * t2 + t)*m_0 + (-2 * t3 + 3 * t2)*p_1 + (t3 - t2)*m_1
end

#interpolate(position) ⇒ Object

[View source]

58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/bayonetta/exp.rb', line 58

def interpolate(position)
  if positions <= key_positions.first
    get_p(0)
  elsif positions >= key_positions.last
    get_p(key_positions.length -1)
  else
    key_positions.each_cons(2).each_with_index { |(start, stop), i|
      if position <= stop && position >= start
        return interpol(position, start, stop)
      end
    }
  end
end