Class: Kamelopard::Functions::ViewSplineFunction

Inherits:
SplineFunction show all
Defined in:
lib/kamelopard/spline.rb

Overview

Spline that takes LookAts or Cameras as control points

Instance Attribute Summary collapse

Attributes inherited from SplineFunction

#control_points, #tension, #total_dur

Attributes inherited from FunctionMultiDim

#ndims

Attributes inherited from Function

#append, #compose, #end, #max, #min, #start, #verbose

Instance Method Summary collapse

Methods inherited from FunctionMultiDim

#compose=

Methods inherited from Function

#get_value, interpolate

Constructor Details

#initialize(tension = 0.5) ⇒ ViewSplineFunction

Returns a new instance of ViewSplineFunction.


144
145
146
147
148
# File 'lib/kamelopard/spline.rb', line 144

def initialize(tension = 0.5)
    @first_control_point = nil
    @fields = [:latitude, :longitude, :altitude, :heading, :tilt, :roll, :range]
    super(@fields.length, tension)
end

Instance Attribute Details

#first_control_pointObject (readonly)

Returns the value of attribute first_control_point


142
143
144
# File 'lib/kamelopard/spline.rb', line 142

def first_control_point
  @first_control_point
end

#viewtypeObject (readonly)

Returns the value of attribute viewtype


142
143
144
# File 'lib/kamelopard/spline.rb', line 142

def viewtype
  @viewtype
end

Instance Method Details

#add_control_point(point, dur) ⇒ Object


150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
# File 'lib/kamelopard/spline.rb', line 150

def add_control_point(point, dur)
    raise "Control points for ViewSplines must be AbstractViews" unless point.kind_of? AbstractView
    if @first_control_point.nil?
        @first_control_point = point
    elsif point.kind_of? @first_control_point.class
    else
        raise "Control points for ViewSplines must be the same class type (#{@first_control_point.class} vs #{point.class})"
    end

    super((
        @fields.collect { |f|
            begin
                point.method(f).call
            rescue
                0
            end
         }), dur)
end

#run_function(x) ⇒ Object


169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
# File 'lib/kamelopard/spline.rb', line 169

def run_function(x)
    res = super(x)
    h = {}
    @fields.each_index do |i|
        h[@fields[i]] = res[i]
    end

    if @first_control_point.is_a? Kamelopard::LookAt
        h.delete :roll
    elsif @first_control_point.is_a? Kamelopard::Camera
        h.delete :range
    else
        raise "Unknown control point type #{@first_control_point.class.name}. ViewSplines only support LookAts and Cameras"
    end

    return make_view_from h
end