Class: AnimationOperator
- Inherits:
-
Object
- Object
- AnimationOperator
- Defined in:
- lib/teien/animation/animation_operator.rb
Constant Summary collapse
- BL_MODE_SWITCH =
stop current animation and start next animation.
0
- BL_MODE_CONCURRENT =
cross fade, blend current animation out while blending next animation in.
1
- BL_MODE_FIRSTFRAME =
blend current animation to first frame of next animation, when done, start next animation.
2
Instance Attribute Summary collapse
-
#loop ⇒ Object
Returns the value of attribute loop.
-
#name ⇒ Object
Returns the value of attribute name.
Instance Method Summary collapse
- #add_time(delta) ⇒ Object
- #init(name, loop) ⇒ Object
-
#initialize(entity) ⇒ AnimationOperator
constructor
A new instance of AnimationOperator.
- #initialize_all_animations ⇒ Object
- #play(name, loop) ⇒ Object
- #set_blending_mode(mode) ⇒ Object
- #set_blenging_duration(duration) ⇒ Object
- #set_enabled(bl) ⇒ Object
Constructor Details
#initialize(entity) ⇒ AnimationOperator
Returns a new instance of AnimationOperator.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/teien/animation/animation_operator.rb', line 9 def initialize(entity) @entity = entity @state = nil @nextState = nil @mode = BL_MODE_CONCURRENT @duration = 0.2 @timeLeft = 0 @complete = false @name = nil @loop = false # @blender = Ogrelet::AnimationBlender.new(entity) end |
Instance Attribute Details
#loop ⇒ Object
Returns the value of attribute loop.
7 8 9 |
# File 'lib/teien/animation/animation_operator.rb', line 7 def loop @loop end |
#name ⇒ Object
Returns the value of attribute name.
6 7 8 |
# File 'lib/teien/animation/animation_operator.rb', line 6 def name @name end |
Instance Method Details
#add_time(delta) ⇒ Object
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 |
# File 'lib/teien/animation/animation_operator.rb', line 115 def add_time(delta) if @state if @timeLeft > 0 @timeLeft -= delta if @timeLeft < 0 @state.set_enabled(false) @state.set_weight(0) @state = @nextState @state.set_enabled(true) @state.set_weight(1) @nextState = nil else # still blending, advance weights @state.set_weight(@timeLeft / @duration) @nextState.set_weight(1.0 - @timeLeft / @duration) if(@mode == BL_MODE_CONCURRENT) @nextState.add_time(delta) end end end if @state.get_time_position() >= @state.get_length() @complete = true else @complete = false end @state.add_time(delta) @state.set_loop(@loop) end # @blender.addTime(delta) end |
#init(name, loop) ⇒ Object
24 25 26 27 |
# File 'lib/teien/animation/animation_operator.rb', line 24 def init(name, loop) initialize_all_animations() play(name, loop) end |
#initialize_all_animations ⇒ Object
29 30 31 32 33 34 35 36 |
# File 'lib/teien/animation/animation_operator.rb', line 29 def initialize_all_animations() set = @entity.get_all_animation_states() set.each_animation_state {|state| state.set_enabled(false) state.set_weight(0) state.set_time_position(0) } end |
#play(name, loop) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 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/teien/animation/animation_operator.rb', line 50 def play(name, loop) @name = name @loop = loop unless @state @state = @entity.get_animation_state(name) @state.set_enabled(true) @state.set_weight(1) @state.set_time_position(0) @state.set_loop(loop) return end case @mode when BL_MODE_SWITCH @state.set_enabled(false) @state = @entity.get_animation_state(name) @state.set_enabled(true) @state.set_weight(1) @state.set_time_position(0) @timeLeft = 0 else newState = @entity.get_animation_state(name) if @timeLeft > 0 if newState.get_animation_name == @nextState.get_animation_name return elsif newState.get_animation_name == @state.get_animation_name # going back to the source state @state = @nextState @nextState = newState @timeLeft = @duration - @timeLeft else if @timeLeft < @duration * 0.5 # simply replace the target with this one @nextState.set_enabled(false) @nextState.set_weight(0) else # old target becomes new source @state.set_enabled(false) @state.set_weight(0) @state = @nextState end @nextState = newState @nextState.set_enabled(true) @nextState.set_weight( 1.0 - @timeLeft / @duration ) @nextState.set_time_position(0) end else return if newState.get_animation_name == @state.get_animation_name # assert( target == 0, "target should be 0 when not blending" ) # @state.setEnabled(true) # @state.setWeight(1) # mTransition = transition; @timeLeft = @duration @nextState = newState @nextState.set_enabled(true) @nextState.set_weight(0) @nextState.set_time_position(0) end end # @blender.blend(name, Ogrelet::AnimationBlender::BlendWhileAnimating, 0.2, loop) end |
#set_blending_mode(mode) ⇒ Object
42 43 44 |
# File 'lib/teien/animation/animation_operator.rb', line 42 def set_blending_mode(mode) @mode = mode end |
#set_blenging_duration(duration) ⇒ Object
46 47 48 |
# File 'lib/teien/animation/animation_operator.rb', line 46 def set_blenging_duration(duration) @duration = duration end |
#set_enabled(bl) ⇒ Object
38 39 40 |
# File 'lib/teien/animation/animation_operator.rb', line 38 def set_enabled(bl) # @blender.getSource().setEnabled(bl) end |