J'ai commencé a créer une adaptation de raydium pour le language de script lua. Pour le moment, touts les éléments nécessaires pour le premier tutorial (
http://raydium.yoopla.org/wiki/MaPremiereApplicationRaydium ) sont en place.
L'application se lance sans problèmes mais:
- raydium exige le dossier rayphp dans le dossier courant.
- raydium télécharge plein de fichiers sans même les ranger là ou il faut
- c'est un peu rouge
- aucun mouvement - pas de rafraichissement de la fenêtre
Je me demande si c'est normal. Et je soupconne un petit problème au niveau du callback.
Voici le code du tutorial codé en lua:
Code:
log(10, "Give arguments")
rawraydium.init_args("--help")
log(10, "Create window")
rawraydium.window_create(320, 250, "WINDOW", "Window title")
log(10, "Change texture filter to trilinear")
rawraydium.texture_filter_change("trilinear")
log(10, "Change projections and updating view")
rawraydium.projection_near(0.01)
rawraydium.projection_far(1000)
rawraydium.projection_fov(60)
rawraydium.window_view_update()
log(10, "Create sun")
local sun = {1.0, 0.9, 0.5, 1.0}
rawraydium.light_on(0)
rawraydium.light_colorRGBA(0, unpack(sun))
rawraydium.light_intensity(0, 1000000)
rawraydium.light_positionXYZ(0, 50, 150, 200)
rawraydium.light_update_all(0)
log(10, "Set background color")
rawraydium.background_color_changeRGBA(unpack(sun))
log(10, "Disable fog")
rawraydium.fog_disable()
log(10, "Register callback")
local cam = {x=10, y=10, z=20}
rawraydium.callback(function()
print("Callback called.")
print(rawraydium.joy_x())
cam.x = cam.x + rawraydium.joy_x();
cam.y = cam.y + rawraydium.joy_y();
if rawraydium.key("PAGE_DOWN") then cam.z = cam.z - 2 end
if rawraydium.key("PAGE_UP") then cam.z = cam.z + 2 end
if rawraydium.key_last==1027 then os.exit(0) end
rawraydium.clear_frame();
rawraydium.camera_look_atXYZXYZ(cam.x,cam.y,cam.z,0,0,0);
rawraydium.object_draw_name("temp/cocorobix.tri");
rawraydium.rendering_finish();
end)
On voit que cela ne change pas beaucoup de l'API originale. Juste des variables qui ont été transformées en fonctions ... presque aucune modification.
Et les fonctions s'écrivent facilement. Un exemple:
Code:
static int luaRaydium_camera_look_atXYZXYZ (lua_State *L) {
int argc = lua_gettop(L);
if(argc < 6) return 0;
raydium_camera_look_at(
(GLfloat) lua_tonumber(L, 1),
(GLfloat) lua_tonumber(L, 2),
(GLfloat) lua_tonumber(L, 3),
(GLfloat) lua_tonumber(L, 4),
(GLfloat) lua_tonumber(L, 5),
(GLfloat) lua_tonumber(L, 6)
);
return 0;
}
static int luaRaydium_object_draw_name (lua_State *L) {
int argc = lua_gettop(L);
if(argc < 1) return 0;
raydium_object_draw_name(lua_tostring(L, 1));
return 0;
}
static int luaRaydium_rendering_finish (lua_State *L) {
raydium_rendering_finish();
return 0;
}
edit: le code source complet est ici:
http://louve.dyndns.org:8080/projets/raydium/dir/liblua-raydium/
http://mildred.pastebin.com/291609
http://louve.dyndns.org:8080/projets/raydium/dir/wotgame/system/entry.lua
edit: le problème c'est que le callback n'est appelé qu'une seule fois.
Car le ramasse miettes de LUA supprime la pile qui me permet d'appeler la fonction lua qui sert de callback.
edit: problème corrigé. le callback est bien appelé comem il faut.
Le problème de couleurs venait du fait que j'utilisais unpack(sun) pour passer les couleurs en paramètre. Et donc seule la première composante (rouge) était prise en compte.