General Question Propeller animation [solved]

johnnymanly

Donator
Donator
Joined
Mar 17, 2008
Messages
179
Reaction score
116
Points
43
Location
Southwest Pennsylginia
Website
sites.google.com
I'd like to animate a prop in a Lua vessel.
I can set the animation like this:
Code:
pwr = vi:get_animation(anim_Prop)
  da = simdt * 0.1
  pwr_proc = pwr + da
  gas = vi:get_thrusterlevel(thmain)

   if
    gas > 0
   then
    vi:set_animation(anim_Prop,pwr_proc)
   end
but I don't know how to repeat the animation. (loop?)
Any hint would be appreciated.

Thanks.
 
I'd like to animate a prop in a Lua vessel.
I can set the animation like this:
Code:
pwr = vi:get_animation(anim_Prop)
  da = simdt * 0.1
  pwr_proc = pwr + da
  gas = vi:get_thrusterlevel(thmain)

   if
    gas > 0
   then
    vi:set_animation(anim_Prop,pwr_proc)
   end
but I don't know how to repeat the animation. (loop?)
Any hint would be appreciated.

Thanks.
I'm assuming your animation state defines a full totation. The animation state can't exceed 1. So if it does, you have to subtract 1.
 
Thanks for the answer.
Do you mean I have to set the animation state back to 0 before I can make another revolution?

Not quite. Remember that the animation state variable really describes what angle the propeller should be oriented at a given time on a scale from 0 to 360 degrees (0 to 1 animation state). As an example, let's say that the propeller angle increases by 62 degrees every time step. After six steps, the total angle of rotation would be 6*62 = 372 degrees. This would be equivalent to an animation state of 1.03333. You don't want to reset the state to 0 because that wouldn't give the correct angle. What you need to know is what is the angle on a 0 to 360 scale (0 to 1 animation state). So you subtract off 360 degrees (1 from your animation state) to get the proper angle of 12 degrees, at a corresponding animation state of 0.03333.

Mathematically what you want is the remainder of the sum of your animation state increments divided by 1.
 
This seems to do it and ties rpm to thrust.
Code:
  --configuration part
  anim_Prop = vi:create_animation(0)

  Prop1 = {
    type = 'rotation',
    mesh = 0,
    grp = 13,
    ref = {x=0,y=0.467,z=8.928},
    axis = {x=0,y=0,z=1},
    angle = -360*RAD
    }

  animcomp_Prop = oapi.create_animationcomponent(Prop1)

  vi:add_animationcomponent(anim_Prop,0,1,animcomp_Prop)
 
  --prop spinning part
function clbk_prestep(simt,simdt,mjd)

  pwr = vi:get_thrusterlevel(thmain)
  prp = vi:get_animation(anim_Prop)
  da = simdt * 0.1 + (pwr * 0.1)
  prp_proc = prp + da

  if
    prp < 1
  then
    vi:set_animation(anim_Prop,prp_proc)
  else
    vi:set_animation(anim_Prop, 0)
  end

end
 
Last edited:
This seems to do it and ties rpm to thrust.
Code:
  --configuration part
  anim_Prop = vi:create_animation(0)

  Prop1 = {
    type = 'rotation',
    mesh = 0,
    grp = 13,
    ref = {x=0,y=0.467,z=8.928},
    axis = {x=0,y=0,z=1},
    angle = -360*RAD
    }

  animcomp_Prop = oapi.create_animationcomponent(Prop1)

  vi:add_animationcomponent(anim_Prop,0,1,animcomp_Prop)
 
  --prop spinning part
function clbk_prestep(simt,simdt,mjd)

  pwr = vi:get_thrusterlevel(thmain)
  prp = vi:get_animation(anim_Prop)
  da = simdt * 0.1 + (pwr * 0.1)
  prp_proc = prp + da

  if
    prp < 1
  then
    vi:set_animation(anim_Prop,prp_proc)
  else
    vi:set_animation(anim_Prop)
  end

end
I was racking my brain all afternoon until I found this solution. Can you allow me to use it in my C++ project?
I think I know how to convert it from Lua to C++.
 
I was racking my brain all afternoon until I found this solution. Can you allow me to use it in my C++ project?
I think I know how to convert it from Lua to C++.
Of course. Feel free to use it.
If you get any weird behavior pay attention to the other comments in this thread. I'm not a very good coder.
 
Back
Top