XML Feeds

.

[jitter] lua questions

Wesley Smith wesley.hoke at gmail.com
Tue Jan 1 20:26:07 MST 2008


Sorry, there was a slight typo in my script in the last post.  Here's
a fixed version:


autowatch = 1
print("compiled")
render_context = this.drawto
angle=0
mouseXY={0,0}
dir=1



function BuildLists()

    box = gl.GenLists(2)
    gl.NewList(box    ,"COMPILE");
        gl.Begin("QUADS")
            gl.Vertex (-0.5 , 0.5 , 0. )                -- Top Left
            gl.Vertex ( 0.5 , 0.5 , 0. )                -- Top Right
            gl.Vertex ( 0.5 ,-0.5 , 0. )            -- Bottom Right
            gl.Vertex (-0.5 ,-0.5 , 0. )
        gl.End();
    gl.EndList()
end
function init()
--initialize the dispaly list
	if(this.context ~= 0) then
	    BuildLists()
	end
end


-- functions as variables!
function setOnReloadOrDestChanged(func)
	script_load = func
	dest_changed = func
end
setOnReloadOrDestChanged(init)

--[[
This section is equivalent to the above

function script_load()
	init()
end

function dest_changed()
	init()
end
--]]

function draw()
    gl.Clear("COLOR_BUFFER_BIT" , "DEPTH_BUFFER_BIT")
    --gl.LoadIdentity()
    --gl.Enable("BLEND")
    --gl.BlendFunc(1,6)
    --gl.ClearColor(1,1,0,1)
    rot()
    for i=0,1000 do
    gl.Translate(mouseXY[1],mouseXY[2],(i/1000)-1);
    gl.Rotate(angle,0,0,1)
    gl.Color(i/1000, math.random(), 1, i/1000)
    gl.CallList(box)
    end

end

function rot()
    angle = angle+dir
    if angle==15 then dir= -0.5
    elseif angle==0 then dir= 0.5
    end
end

--create the listener callback function
function callback(event)
    if(event.eventname == "mouseidle") then
        local _glXmouse = event.args[1]
        local _glYmouse = event.args[2]
        --need to transform mouse ccordinates to world domain
        --dono why, but 0.95 needed
        mouseXY=jit.gl.screentoworld({_glXmouse,_glYmouse, 0.95})
    end
end

--create a listener object
listener = jit.listener(render_context, "callback")


More information about the jitter mailing list