From 81283b584a7f7c38b697c438858a8b70294dd276 Mon Sep 17 00:00:00 2001 From: David Walter Seikel Date: Sat, 10 May 2014 14:14:08 +1000 Subject: Add physics to the windows. Sure, it's just an annoying gimmick right now, but there's plans for this to be actually useful. --- src/GuiLua/GuiLua.c | 16 +++++++++++----- src/GuiLua/GuiLua.h | 5 +++-- src/GuiLua/skang.c | 2 +- src/extantz/ephysics_demo.c | 33 ++++++++++++++++++--------------- src/extantz/extantz.c | 23 +++++++++-------------- src/extantz/extantz.h | 3 ++- src/extantz/files.c | 2 +- src/extantz/woMan.c | 2 +- src/libraries/winFang.c | 12 +++++++++++- src/libraries/winFang.h | 4 +++- src/purkle/purkle.c | 14 +++++++++----- 11 files changed, 69 insertions(+), 47 deletions(-) (limited to 'src') diff --git a/src/GuiLua/GuiLua.c b/src/GuiLua/GuiLua.c index 55037e0..494be84 100644 --- a/src/GuiLua/GuiLua.c +++ b/src/GuiLua/GuiLua.c @@ -242,6 +242,7 @@ static int window(lua_State *L) { winFang *win = NULL; winFang *parent = NULL; + EPhysics_World *world = NULL; char *name = "GuiLua"; char *title = "GuiLua test harness"; int w = WIDTH, h = HEIGHT; @@ -252,9 +253,13 @@ static int window(lua_State *L) lua_getfield(L, LUA_REGISTRYINDEX, glName); gl = lua_touserdata(L, -1); lua_pop(L, 1); - if (gl && gl->parent) parent = gl->parent; + if (gl) + { + parent = gl->parent; + world = gl->world; + } - win = winFangAdd(parent, 25, 25, w, h, title, name); + win = winFangAdd(parent, 25, 25, w, h, title, name, world); if (gl) { // If there's no parent, we become the parent. @@ -372,7 +377,7 @@ PD("GuiLua 3"); return 1; } -GuiLua *GuiLuaDo(int argc, char **argv, winFang *parent) +GuiLua *GuiLuaDo(int argc, char **argv, winFang *parent, EPhysics_World *world) { GuiLua *result; lua_State *L; @@ -380,6 +385,7 @@ GuiLua *GuiLuaDo(int argc, char **argv, winFang *parent) result = calloc(1, sizeof(GuiLua)); result->parent = parent; + result->world = world; L = luaL_newstate(); if (L) @@ -433,12 +439,12 @@ GuiLua *GuiLuaDo(int argc, char **argv, winFang *parent) return result; } -void GuiLuaLoad(char *module, winFang *parent) +void GuiLuaLoad(char *module, winFang *parent, EPhysics_World *world) { char *args[] = {"GuiLUa", "-l", ""}; args[2] = module; - GuiLuaDo(3, args, parent); + GuiLuaDo(3, args, parent, world); } void GuiLuaDel(GuiLua *gl) diff --git a/src/GuiLua/GuiLua.h b/src/GuiLua/GuiLua.h index b123fe7..3bd2baf 100644 --- a/src/GuiLua/GuiLua.h +++ b/src/GuiLua/GuiLua.h @@ -20,6 +20,7 @@ typedef struct _GuiLua lua_State *L; winFang *us; // Our window, if it exists. winFang *parent; // Our parent window, if it exists. + EPhysics_World *world; // Our world, if it exists. int inDel; Eina_Clist node; @@ -29,8 +30,8 @@ typedef struct _GuiLua extern const char *glName; -GuiLua *GuiLuaDo(int argc, char **argv, winFang *parent); -void GuiLuaLoad(char *module, winFang *parent); +GuiLua *GuiLuaDo(int argc, char **argv, winFang *parent, EPhysics_World *world); +void GuiLuaLoad(char *module, winFang *parent, EPhysics_World *world); void GuiLuaDel(GuiLua *gl); #endif diff --git a/src/GuiLua/skang.c b/src/GuiLua/skang.c index ed6d31f..c116f30 100644 --- a/src/GuiLua/skang.c +++ b/src/GuiLua/skang.c @@ -5,7 +5,7 @@ EAPI_MAIN int elm_main(int argc, char **argv) { HamrTime(elm_main, "GuiLua"); - GuiLuaDo(argc, argv, NULL); + GuiLuaDo(argc, argv, NULL, NULL); return 0; } diff --git a/src/extantz/ephysics_demo.c b/src/extantz/ephysics_demo.c index 6697cc9..4655dbb 100644 --- a/src/extantz/ephysics_demo.c +++ b/src/extantz/ephysics_demo.c @@ -2,8 +2,6 @@ #include -#if USE_PHYSICS - #define EPHYSICS_TEST_THEME "extantz" EPhysics_World *ephysicsAdd(globals *ourGlobals) @@ -34,37 +32,42 @@ EPhysics_World *ephysicsAdd(globals *ourGlobals) ephysics_body_restitution_set(boundary, 1); ephysics_body_friction_set(boundary, 0); - box1 = elm_image_add(ourGlobals->win); sprintf(buf, "%s/%s.edj", elm_app_data_dir_get(), EPHYSICS_TEST_THEME); - elm_image_file_set(box1, strdup(buf), "blue-cube"); - evas_object_move(box1, ourGlobals->win_w / 2 - 80, ourGlobals->win_h - 200); - evas_object_resize(box1, 70, 70); - evas_object_show(box1); + box1 = eo_add(ELM_OBJ_IMAGE_CLASS, ourGlobals->win, + elm_obj_image_file_set(strdup(buf), "blue-cube"), + evas_obj_size_set(70, 70), + evas_obj_position_set(ourGlobals->win_w / 2 - 80, ourGlobals->win_h - 200), + evas_obj_visibility_set(EINA_TRUE) + ); box_body1 = ephysics_body_box_add(world); ephysics_body_evas_object_set(box_body1, box1, EINA_TRUE); ephysics_body_restitution_set(box_body1, 0.7); ephysics_body_friction_set(box_body1, 0); - ephysics_body_linear_velocity_set(box_body1, -150, 200, 0); + ephysics_body_linear_velocity_set(box_body1, -1500, 2000, 0); ephysics_body_angular_velocity_set(box_body1, 0, 0, 36); ephysics_body_sleeping_threshold_set(box_body1, 0.1, 0.1); + eo_unref(box1); + - box2 = elm_image_add(ourGlobals->win); - elm_image_file_set(box2, strdup(buf), "purple-cube"); - evas_object_move(box2, ourGlobals->win_w / 2 + 10, ourGlobals->win_h - 200); - evas_object_resize(box2, 70, 70); - evas_object_show(box2); + sprintf(buf, "%s/%s.edj", elm_app_data_dir_get(), EPHYSICS_TEST_THEME); + box2 = eo_add(ELM_OBJ_IMAGE_CLASS, ourGlobals->win, + elm_obj_image_file_set(strdup(buf), "purple-cube"), + evas_obj_size_set(70, 70), + evas_obj_position_set(ourGlobals->win_w / 2 + 10, ourGlobals->win_h - 200), + evas_obj_visibility_set(EINA_TRUE) + ); box_body2 = ephysics_body_box_add(world); ephysics_body_evas_object_set(box_body2, box2, EINA_TRUE); ephysics_body_restitution_set(box_body2, 0.7); ephysics_body_friction_set(box_body2, 0); - ephysics_body_linear_velocity_set(box_body2, 80, -60, 0); + ephysics_body_linear_velocity_set(box_body2, 800, -600, 0); ephysics_body_angular_velocity_set(box_body2, 0, 0, 360); ephysics_body_sleeping_threshold_set(box_body2, 0.1, 0.1); + eo_unref(box2); ephysics_world_gravity_set(world, 0, 0, 0); return world; } -#endif diff --git a/src/extantz/extantz.c b/src/extantz/extantz.c index 5fb88f4..03979ab 100644 --- a/src/extantz/extantz.c +++ b/src/extantz/extantz.c @@ -89,6 +89,8 @@ static void _on_resize(void *data, Evas *evas EINA_UNUSED, Evas_Object *obj EINA evas_obj_size_hint_min_get(NULL, &h), evas_obj_size_set(ourGlobals->win_w, h) ); + if (ourGlobals->world) + ephysics_world_render_geometry_set(ourGlobals->world, 0, 0, -50, ourGlobals->win_w, ourGlobals->win_h, 100); _resize(gld); } @@ -403,7 +405,6 @@ void overlay_add(globals *ourGlobals) EAPI_MAIN int elm_main(int argc, char **argv) { - EPhysics_World *world; GLData *gld = NULL; char buf[PATH_MAX]; // Eina_Bool gotWebKit = elm_need_web(); // Initialise ewebkit if it exists, or return EINA_FALSE if it don't. @@ -435,17 +436,15 @@ EAPI_MAIN int elm_main(int argc, char **argv) elm_config_finger_size_set(0); elm_config_scale_set(1.0); -#if USE_PHYSICS if (!ephysics_init()) return 1; -#endif gld = &ourGlobals.gld; gldata_init(gld); // Set the engine to opengl_x11, then open our window. elm_config_preferred_engine_set("opengl_x11"); - ourGlobals.mainWindow = winFangAdd(NULL, 0, 0, 50, 20, "extantz virtual world viewer", "extantz"); + ourGlobals.mainWindow = winFangAdd(NULL, 0, 0, 50, 20, "extantz virtual world viewer", "extantz", NULL); // Set preferred engine back to default from config elm_config_preferred_engine_set(NULL); @@ -514,17 +513,15 @@ EAPI_MAIN int elm_main(int argc, char **argv) // Also, GL focus gets lost when any menu is used. sigh makeMainMenu(&ourGlobals); + ourGlobals.world = ephysicsAdd(&ourGlobals); + // overlay_add(&ourGlobals); - GuiLuaLoad("test", ourGlobals.mainWindow); + GuiLuaLoad("test", ourGlobals.mainWindow, ourGlobals.world); woMan_add(&ourGlobals); - GuiLuaLoad("purkle", ourGlobals.mainWindow); + GuiLuaLoad("purkle", ourGlobals.mainWindow, ourGlobals.world); ourGlobals.files = filesAdd(&ourGlobals, (char *) elm_app_data_dir_get(), EINA_TRUE, EINA_FALSE); -#if USE_PHYSICS - world = ephysicsAdd(&ourGlobals); -#endif - - // Bump the top toolbar above the windows. + // Bump the top toolbar above the windows. evas_object_raise(ourGlobals.tb); evas_object_show(ourGlobals.mainWindow->box); @@ -532,10 +529,8 @@ EAPI_MAIN int elm_main(int argc, char **argv) elm_run(); -#if USE_PHYSICS - ephysics_world_del(world); + ephysics_world_del(ourGlobals.world); ephysics_shutdown(); -#endif if (ourGlobals.win) { diff --git a/src/extantz/extantz.h b/src/extantz/extantz.h index 684b53d..5b172c2 100644 --- a/src/extantz/extantz.h +++ b/src/extantz/extantz.h @@ -1,7 +1,6 @@ #ifndef _EXTANTZ_H_ #define _EXTANTZ_H_ -#define USE_PHYSICS 1 #define USE_IRR 0 #define USE_DEMO 1 #define DO_GEARS 0 @@ -225,6 +224,8 @@ typedef struct _globals GLData gld; Scene_Data *scene; + EPhysics_World *world; + winFang *files; } globals; diff --git a/src/extantz/files.c b/src/extantz/files.c index 7dd08fa..3aeb7f9 100644 --- a/src/extantz/files.c +++ b/src/extantz/files.c @@ -146,7 +146,7 @@ winFang *filesAdd(globals *ourGlobals, char *path, Eina_Bool multi, Eina_Bool sa Widget *wid; Evas_Object *vbox, *fs, *bt, *rd = NULL, *rdg = NULL, *hoversel; - me = winFangAdd(ourGlobals->mainWindow, ourGlobals->win_w - 380, ourGlobals->win_w - 530, 350, 500, "file selector", "files"); + me = winFangAdd(ourGlobals->mainWindow, ourGlobals->win_w - 380, ourGlobals->win_w - 530, 350, 500, "file selector", "files", ourGlobals->world); wid = widgetAdd(me, ELM_OBJ_FILESELECTOR_CLASS, me->box, NULL); fs = wid->obj; diff --git a/src/extantz/woMan.c b/src/extantz/woMan.c index cd1d5c8..2911686 100644 --- a/src/extantz/woMan.c +++ b/src/extantz/woMan.c @@ -159,7 +159,7 @@ winFang *woMan_add(globals *ourGlobals) char buf[PATH_MAX]; int i; - me = winFangAdd(ourGlobals->mainWindow, 30, 150, ourGlobals->win_w / 3, ourGlobals->win_h / 3, "virtual world manager", "woMan"); + me = winFangAdd(ourGlobals->mainWindow, 30, 150, ourGlobals->win_w / 3, ourGlobals->win_h / 3, "virtual world manager", "woMan", ourGlobals->world); // A tab thingy. tb = elm_toolbar_add(me->win); diff --git a/src/libraries/winFang.c b/src/libraries/winFang.c index a52d01c..205cedb 100644 --- a/src/libraries/winFang.c +++ b/src/libraries/winFang.c @@ -72,7 +72,7 @@ void winFangShow(winFang *win) evas_object_show(win->hand[i]); } -winFang *winFangAdd(winFang *parent, int x, int y, int w, int h, char *title, char *name) +winFang *winFangAdd(winFang *parent, int x, int y, int w, int h, char *title, char *name, EPhysics_World *world) { winFang *result; Evas_Object *obj, *obj2; @@ -143,6 +143,16 @@ winFang *winFangAdd(winFang *parent, int x, int y, int w, int h, char *title, ch eo_unref(result->hand[i]); #endif } + if (world) + { + result->body = ephysics_body_box_add(world); + ephysics_body_evas_object_set(result->body, obj, EINA_TRUE); + ephysics_body_restitution_set(result->body, 0.7); + ephysics_body_friction_set(result->body, 0); + ephysics_body_linear_velocity_set(result->body, 80, -60, 0); + ephysics_body_angular_velocity_set(result->body, 0, 0, 360); + ephysics_body_sleeping_threshold_set(result->body, 0.1, 0.1); + } } else { diff --git a/src/libraries/winFang.h b/src/libraries/winFang.h index 05c3036..a84c8de 100644 --- a/src/libraries/winFang.h +++ b/src/libraries/winFang.h @@ -13,6 +13,7 @@ #include #include #include +#include typedef struct _winFang @@ -20,6 +21,7 @@ typedef struct _winFang Evas_Object *win; Evas_Object *bg; Evas_Object *box; + EPhysics_Body *body; Eina_Clist widgets; Eina_Clist winFangs; int x, y, w, h; @@ -48,7 +50,7 @@ typedef struct _Widget Evas_Smart_Cb on_del; } Widget; -winFang *winFangAdd(winFang *parent, int x, int y, int w, int h, char *title, char *name); +winFang *winFangAdd(winFang *parent, int x, int y, int w, int h, char *title, char *name, EPhysics_World *world); void winFangHide(winFang *win); void winFangShow(winFang *win); void winFangDel(winFang *win); diff --git a/src/purkle/purkle.c b/src/purkle/purkle.c index 971ad37..8ea012c 100644 --- a/src/purkle/purkle.c +++ b/src/purkle/purkle.c @@ -13,13 +13,13 @@ static void _on_entry_del(void *data, Evas_Object *obj, void *event_info) elm_entry_editable_set(obj, EINA_FALSE); } -static winFang *purkleAdd(winFang *parent, int w, int h) +static winFang *purkleAdd(winFang *parent, int w, int h, EPhysics_World *world) { winFang *me; Widget *wid; Evas_Object *en; - me = winFangAdd(parent, 30, 520, w, h, "chatter box", "purkle"); + me = winFangAdd(parent, 30, 520, w, h, "chatter box", "purkle", world); en = eo_add(ELM_OBJ_ENTRY_CLASS, me->win, elm_obj_entry_scrollable_set(EINA_TRUE), @@ -52,7 +52,7 @@ int luaopen_purkle(lua_State *L) { GuiLua *gl; winFang *parent = NULL; - + EPhysics_World *world = NULL; // local skang = require 'skang' lua_getglobal(L, "require"); @@ -71,9 +71,13 @@ int luaopen_purkle(lua_State *L) lua_getfield(L, LUA_REGISTRYINDEX, glName); gl = lua_touserdata(L, -1); lua_pop(L, 1); - if (gl && gl->parent) parent = gl->parent; + if (gl) + { + parent = gl->parent; + world = gl->world; + } - purkleAdd(parent, 300, 400); + purkleAdd(parent, 300, 400, world); push_lua(L, "@ ( = )", skang, MODULEEND, _M, 0); -- cgit v1.1