lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Hello...
I'm working in a Particle System with lunar.h (from the lua-users
wiki) and using Get and Set methods to work with the stuff, but using
these methods slows my application a lot. For now, I'm working with
something like:
function Update(p, t)
	local energy = p:Energy()

	-- update the particle's speed
	local s = p:Speed()
	p:Speed(s:GetX(), s:GetY()-10*t, 0.0)
	
	-- setup the particle's color
	local r = energy/max_energy
	local g = (5*energy - max_energy) / (4*max_energy)
	local b = r/3
	p:Color(r, g, b, 1.0)
	
	-- update the particle's energy
	p:Energy(energy-75*t)
end

Where the function Update receives the particle (p) and the delta T
value (t, variation of time, from physics). But since using methods
like p:Speed(x, y, z) or p:Speed():GetX() is slow, I wanted to "bind
variables" from C++, how can I do that from lunar.h?

I want to make it work something like this:
function Update(p, t)
        local energy = p.energy
 
        -- update the particle's speed
        local s = p.speed
        s.y = s.y - 10*t
        s.z = 0
        p.speed = s
 
        -- setup the particle's color
        local r = energy/max_energy
        local g = (5*energy - max_energy) / (4*max_energy)
        local b = r/3
        p.color = Color(r, g, b, 1.0)
 
        -- update the particle's energy
        p.energy = energy-75*t
end

Something like that, I think it would speed up the runtime significantly...

How can I do this using lunar.h?

Thanks...
Luiz Ribeiro