Throttle animation in VC

misha.physics

Well-known member
Joined
Dec 22, 2021
Messages
1,480
Reaction score
2,210
Points
128
Location
Lviv
Preferred Pronouns
he/him
I thought the animation of throttle in VC on Lua will be as simple as animations of control surfaces and yokes, but looking at DG Lua scripts I see many unfamiliar things. I suppose the following parts of DG may be related with my goal:
Code:
function MainRetroThrottleLevers:RedrawVC (hMesh, hSurf)
    local dg = self.component:DG()
    for i=1, 2 do
        local level = dg:GetMainThrusterLevel(i)
        local pos
        if level > 0 then
            pos = 150 + level*300.0
        else
            level = dg:GetRetroThrusterLevel(i)
            pos = 150 - level*150.0
        end
        if pos ~= self.sliderpos[i] then
            self.sliderpos[i] = pos
            dg:set_animation (self.component.anim_lever[i], pos/450.0)
        end
    end
    return true
end
Code:
function MainRetroThrottle:new(_subsys)
    DGSubsystem.new(self, _subsys)

    self.ELID_LEVERS, self.levers = self:AddElement (MainRetroThrottleLevers (self))

    -- VC animation: Left main engine throttle
    local MainThrottleLGrp = {GRP_VC.THROTTLE_MAIN_L1,GRP_VC.THROTTLE_MAIN_L2}
    local MainThrottleL = MGROUP_ROTATE (1, MainThrottleLGrp, _V(0,0.72,6.9856), _V(1,0,0), 50*RAD)
    self.anim_lever = {}
    self.anim_lever[1] = self:DG():create_animation (0.4)
    self:DG():add_animationcomponent (self.anim_lever[1], 0, 1, MainThrottleL)

    -- VC animation: Right main engine throttle
    local MainThrottleRGrp = {GRP_VC.THROTTLE_MAIN_R1,GRP_VC.THROTTLE_MAIN_R2}
    local MainThrottleR = MGROUP_ROTATE (1, MainThrottleRGrp, _V(0,0.72,6.9856), _V(1,0,0), 50*RAD)
    self.anim_lever[2] = self:DG():create_animation (0.4)
    self:DG():add_animationcomponent (self.anim_lever[2], 0, 1, MainThrottleR)
end

function MainRetroThrottle:clbkLoadVC (vcid)
    if vcid ~= 0 then return false end

    -- Throttle lever animations
    oapi.VC_register_area (self.ELID_LEVERS, PANEL_REDRAW.ALWAYS, PANEL_MOUSE.LBDOWN + PANEL_MOUSE.LBPRESSED)
    oapi.VC_set_areaclickmode_quadrilateral (self.ELID_LEVERS, _V(-0.372,0.918,6.905), _V(-0.279,0.918,6.905), _V(-0.372,0.885,7.11), _V(-0.279,0.885,7.11))

    return true
end
I just would like to animate these two separated meshroups to make them rotate in accordance with the throttle level of main engines (THGROUP.MAIN) without controling them by mouse and so on:

Без імені.png

Maybe anyone familiar with this could help me with a simple template without anything extra.
 
Thanks, I really should explain this, since it will be useful for other members. This is the all that relates to the throttle animation:
C++:
Throttle =
{
    type = 'rotation',
    mesh = 0,
    grp = 33,
    ref = {x=-0.40975, y=0.063366, z=1.7301},
    axis = {x=1, y=0, z=0},
    angle = PI/4+PI/16
}

function clbk_setclasscaps(cfg)
    
  ThrottleAnimationComponent = oapi.create_animationcomponent(Throttle)
  ThrottleAnimation = vi:create_animation(0)
  vi:add_animationcomponent(ThrottleAnimation, 0, 1, ThrottleAnimationComponent)

end

function clbk_poststep(simt,simdt)
 
  ThrottleLevel = vi:get_thrustergrouplevel(THGROUP.MAIN)
  vi:set_animation(ThrottleAnimation, ThrottleLevel)

end
 
Back
Top