(from this post: http://celestiaproject.net/forum/viewtopic.php ... ght=#76103)
hank wrote:Code: Select all
dolly =
function(dollyFactor)
obs = celestia:getobserver();
obsPos = obs:getposition();
sel = celestia:getselection();
if sel == nil or sel:name() == "?" then return end
selPos = sel:getposition();
relPos = selPos:vectorto(obsPos);
newPos = selPos:addvector( relPos * dollyFactor );
obs:setposition(newPos);
end
dollyFactor = 0.9;
dollyin =
function()
celestia:flash("Dolly In", 0.5);
dolly( dollyFactor );
end
dollyout =
function()
celestia:flash("Dolly Out", 0.5);
dolly( 1/dollyFactor );
end
keymap =
{
i = dollyin;
o = dollyout;
}
celestia_keyboard_callback = function(key)
f = keymap[key]
if f then
f()
return true;
end
return false;
end
celestia:requestkeyboard(true);
celestia:flash("dolly test", 2);
wait(2);
repeat
wait(0);
until false;
- Hank
1. Does anyone know how to map functions to keys which are not alphabetical?
eg. instead of "i" and "o" keys, what if I wanted to map to the numeric keys [1, 2, ..9, 0] at the top of the keypad? .. or perhaps alt-1, alt-2, etc. (or maybe even the function keys F1 - F12 ! )
You cannot just replace:
Code: Select all
keymap =
{
i = dollyin;
o = dollyout;
}
with:
Code: Select all
keymap =
{
1 = dollyin;
2 = dollyout;
}
This doesn't work, So perhaps we need to map to an ascii value for special characters, but what's the syntax?
2. Is it possible to prompt the user to set the value of a variable such as dollyfactor, instead of hardcoding it?
eg.
Code: Select all
dollyFactor = tonumber(getLine("Enter Dollyfactor:"))
This also, does NOT work.