animate_node.lua
NAME
animate_node
FUNCTION
animate_node(render, width, height, node, roty, rotx)
NOTES
Creates a window and renders the plot to it for animation.
Double click the left mouse button to start/stop the animation.
Click the right mouse button to restore the original state.
Use arrow keys to control rotation directions.
INPUTS
render - zeRender object
width - image width
height - image height
node - zeNode object
roty - initial rotation angle (degree) about the y-axis.
rotx - initial rotation angle (degree) about the x-axis.
OUTPUTS
None
SOURCE
require("register")
function animate_node(render, width, height, node, roty, rotx)
local deg = 2
local interval = 30
local hwnd = 0
local key = 0
local timer = true
local rotx0 = rotx
local roty0 = roty
callback = function(message, hwnd, wparm, lwparm, hwparm, lparm, llparm, hlparm)
if (message == "PAINT") then
if (hwnd > 0) then
render:towindow(hwnd, 1)
end
elseif (message =="KEYUP") then
if (wparm >= 37 and wparm <= 40) then
if (wparm == 37) then
-- left arrow
roty = roty - deg
elseif (wparm == 38) then
-- up arrow
rotx = rotx - deg
elseif (wparm == 39) then
-- right arrow
roty = roty + deg
else
-- down arrow
rotx = rotx + deg
end
key = wparm
node:rotatex(rotx)
node:rotatey(roty)
render:towindow(hwnd, 1)
end
elseif (message =="LBUTTONDBLCLK") then
if (timer) then
zeWindow.timer(interval)
timer = false
else
zeWindow.timer(0)
timer = true
end
elseif (message =="RBUTTONDOWN") then
zeWindow.timer(0)
timer = true
node:rotatex(rotx0)
node:rotatey(roty0)
rotx = rotx0
roty = roty0
render:towindow(hwnd, 1)
elseif (message == "TIMER") then
if (key >= 37 and key <= 40) then
if (key == 37) then
roty = roty - deg
elseif (key == 38) then
rotx = rotx - deg
elseif (key == 39) then
roty = roty + deg
else
rotx = rotx + deg
end
node:rotatex(rotx)
node:rotatey(roty)
render:towindow(hwnd, 1)
end
elseif (message == "CREATE") then
hwnd = wparm
end
end
zeWindow.create("callback", width, height)
end