LUA: Turning the wheels of a windmill

  • #1, by marvelSunday, 07. July 2013, 13:58 7 years ago
    How would it be possible with LUA to "turn" something... lets say the wheel of a windmill. smile

    Key Killer

    598 Posts


  • #2, by afrlmeSunday, 07. July 2013, 14:07 7 years ago
    currently we have no support for rotation as far as I know...
    if we could add some of the Löve 2D framework libraries/functions then would be possible I suppose as they have a couple functions for rotation & all their code/lib files are open source.

    I have no idea how to include & use them though.

    but anyway you can usually animate something turning in a few frames.
    you really only have to animate the first spoke of things like windmills - the point between one blade until it's just before position of the last & then loop. usually only need maybe 3-5 frames. Well providing the thing rotating isn't covered in debris, graffiti or vegetation etc. You could also get away with creating the animation in layers too so that the images for the animation aren't as big.

    Imperator

    6815 Posts

  • #3, by marvelSunday, 07. July 2013, 14:25 7 years ago
    There was a compass script "einzelkaempfer" did a while ago. There is a turning, rotating compass needle. How could he arrange that?

    Key Killer

    598 Posts

  • #4, by afrlmeSunday, 07. July 2013, 15:37 7 years ago
    hmm...

    it doesn't rotate, it uses a lot of frames of which (I haven't gone over the script, but I'm assuming) it selects the frame to display based on a calculation of where the mouse cursor is on the screen.

    -- Interface
    comp_interface = getObject("Interfaces[Kompass]")

    -- Lokale Interface-Koordinaten des Kompassnadel-Drehpunktes
    rot_point = {55;85}

    -- Anzahl Sprites
    num_sprites = 64

    -- Geschwindigkeit (1=sofort; je größer, je langsamer)
    rot_speed = 5




    ---------------------------------------

    -- Aktuelle Position des Kompasses
    pos_compass = {0;0}

    -- Aktueller Winkel
    curr_angle = 0
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23

    --Dreht die Kompassnadel in Richtung des Mauszeigers
    function spinNeedle()
    local pos_cursor = getCursorPos()

    local target_angle = math.atan2(pos_compass[2] - pos_cursor.y, pos_compass[1] - pos_cursor.x) / math.pi * 180
    local rot_angle = target_angle - curr_angle
    if rot_angle <= -180 then
    rot_angle = 360 + rot_angle
    elseif rot_angle > 180 then
    rot_angle = 360 - rot_angle
    end
    curr_angle = curr_angle + rot_angle / rot_speed

    if curr_angle < 0 then
    curr_angle = 360 + curr_angle
    elseif curr_angle >= 360 then
    curr_angle = curr_angle - 360
    end
    local call_frame = math.floor(curr_angle / 360 * num_sprites + 0.5) + 1
    if call_frame == 65 then call_frame = 1 end

    comp_anim:setValue(VAnimationFirstFrame, call_frame)
    comp_anim:setValue(VAnimationLastFrame, call_frame)
    end


    -- Speichert die Position des Kompass-Drehpunktes in einer globalen Variable
    function setRotationPoint()
    local int_pos = comp_interface:getPoint(VInterfacePosition)
    pos_compass = {int_pos.x + rot_point[1];int_pos.y + rot_point[2]}
    end
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32


    P.S: we need something like this: http://love2d.org/wiki/love.graphics.rotate
    mind you there's loads of useful sounding stuff listed for the framework! check out all the stuff just for graphics: http://love2d.org/wiki/love.graphics

    Imperator

    6815 Posts

  • #5, by marvelSunday, 07. July 2013, 17:02 7 years ago
    Isnt it possible to implement an external library via lua?

    Key Killer

    598 Posts

  • #6, by afrlmeSunday, 07. July 2013, 17:23 7 years ago
    better off asking Alex about that wink

    Imperator

    6815 Posts

Write post