author | francesco-ST <francesco.abbate@st.com> | 2010年07月15日 12:57:00 +0200 |
---|---|---|
committer | francesco-ST <francesco.abbate@st.com> | 2010年07月15日 12:57:00 +0200 |
commit | f93eaab58d78528b56710dbdbcf0b0232d1f46ad (patch) | |
tree | 0f95ddfbd626276432e5951b2403b1f220b9669f | |
parent | daf0b9bafe32ec66a132bf6f6faabb821512c4b1 (diff) | |
download | gsl-shell-f93eaab58d78528b56710dbdbcf0b0232d1f46ad.tar.gz |
-rw-r--r-- | agg-plot/lua-draw.cpp | 62 | ||||
-rw-r--r-- | agg-plot/plot-window.cpp | 2 | ||||
-rw-r--r-- | pre3d/pre3d.lua | 24 | ||||
-rw-r--r-- | pre3d/pre3d_shape_utils.lua | 2 | ||||
-rw-r--r-- | pre3d/test.lua | 15 |
diff --git a/agg-plot/lua-draw.cpp b/agg-plot/lua-draw.cpp index 58f63f6e..a26c49de 100644 --- a/agg-plot/lua-draw.cpp +++ b/agg-plot/lua-draw.cpp @@ -45,9 +45,14 @@ static int agg_text_set_point (lua_State *L); static int agg_text_rotate (lua_State *L); static int agg_rgba_free (lua_State *L); -static int agg_rgba_set (lua_State *L); +static int agg_rgba_add (lua_State *L); +static int agg_rgba_mul (lua_State *L); +static int agg_rgba_set_alpha (lua_State *L); +#if 0 static int agg_rgba_invert (lua_State *L); static int agg_rgba_dup (lua_State *L); +static int agg_rgba_set (lua_State *L); +#endif static void path_cmd (my::path *p, int cmd, struct cmd_call_stack *stack); @@ -77,9 +82,14 @@ static const struct luaL_Reg agg_path_methods[] = { static const struct luaL_Reg rgba_methods[] = { {"__gc", agg_rgba_free}, + {"__add", agg_rgba_add }, + {"__mul", agg_rgba_mul }, + {"alpha", agg_rgba_set_alpha }, +#if 0 {"set", agg_rgba_set }, {"invert", agg_rgba_invert }, {"dup", agg_rgba_dup }, +#endif {NULL, NULL} }; @@ -327,6 +337,16 @@ agg_rgb_new (lua_State *L) } int +agg_rgba_set_alpha (lua_State *L) +{ + agg::rgba8 *c = (agg::rgba8 *) gs_check_userdata (L, 1, GS_RGBA_COLOR); + double a = luaL_checknumber (L, 2); + c->a = agg::rgba8::base_mask * a; + return 0; +} + +#if 0 +int agg_rgba_set (lua_State *L) { agg::rgba8 *c = (agg::rgba8 *) gs_check_userdata (L, 1, GS_RGBA_COLOR); @@ -362,7 +382,43 @@ int agg_rgba_dup (lua_State *L) { agg::rgba8 *src = (agg::rgba8 *) gs_check_userdata (L, 1, GS_RGBA_COLOR); - agg::rgba8 *dst = new(L, GS_RGBA_COLOR) agg::rgba8(*src); + new(L, GS_RGBA_COLOR) agg::rgba8(*src); + return 1; +} +#endif + +int +agg_rgba_add (lua_State *L) +{ + agg::rgba8 *c1 = (agg::rgba8 *) gs_check_userdata (L, 1, GS_RGBA_COLOR); + agg::rgba8 *c2 = (agg::rgba8 *) gs_check_userdata (L, 2, GS_RGBA_COLOR); + + unsigned int r = c1->r + c2->r; + unsigned int g = c1->g + c2->g; + unsigned int b = c1->b + c2->b; + + new(L, GS_RGBA_COLOR) agg::rgba8(r, g, b); + + return 1; +} + +int +agg_rgba_mul (lua_State *L) +{ + int is = 1, ic = 2; + + if (gs_is_userdata (L, 1, GS_RGBA_COLOR)) + { + ic = 1; + is = 2; + } + + double f = luaL_checknumber (L, is); + agg::rgba8 *c = (agg::rgba8 *) gs_check_userdata (L, ic, GS_RGBA_COLOR); + + unsigned int r = f * c->r, g = f * c->g, b = f * c->b; + + new(L, GS_RGBA_COLOR) agg::rgba8(r, g, b); return 1; } @@ -391,6 +447,8 @@ draw_register (lua_State *L) lua_pop (L, 1); luaL_newmetatable (L, GS_METATABLE(GS_RGBA_COLOR)); + lua_pushvalue (L, -1); + lua_setfield (L, -2, "__index"); luaL_register (L, NULL, rgba_methods); lua_pop (L, 1); } diff --git a/agg-plot/plot-window.cpp b/agg-plot/plot-window.cpp index 8d747046..70fec188 100644 --- a/agg-plot/plot-window.cpp +++ b/agg-plot/plot-window.cpp @@ -195,7 +195,7 @@ plot_window_new (lua_State *L) plot_window *win = new(L, GS_AGG_WINDOW) plot_window(color); - win->id = mlua_window_ref(L, 1); + win->id = mlua_window_ref(L, lua_gettop (L)); pthread_attr_t attr[1]; pthread_t win_thread[1]; diff --git a/pre3d/pre3d.lua b/pre3d/pre3d.lua index 39549c8e..c2592ebe 100644 --- a/pre3d/pre3d.lua +++ b/pre3d/pre3d.lua @@ -732,8 +732,15 @@ function RendererMT.bufferShape(this, shape) -- Lighting intensity is just based on just one of the normals pointing -- towards the camera. Should do something better here someday... + local fill_rgba = this.fill_rgba + local intensity = dotProduct3d(g_z_axis_vector, n1) - if intensity < 0 then intensity = 0 end + if intensity < 0 then + intensity = -intensity + if this.fill_rgba_backside then + fill_rgba = this.fill_rgba_backside + end + end -- We map the quad into world coordinates, and also replace the indices -- with the actual points. @@ -758,12 +765,25 @@ function RendererMT.bufferShape(this, shape) world_qf.normal1 = n1 world_qf.normal2 = n2 +-- local cr, cg, cb = 0x42/255, 0x82/255, 0xAA/255 +-- local cr, cg, cb = 0x4A/255, 0x92/255, 0xBF/255 + + if this.set_light_intensity then + local r1 = 0.2 + local ci = intensity * (1-r1) + fill_rgba = r1 * fill_rgba + ci * fill_rgba + end + + if this.fill_rgba_alpha then + fill_rgba:alpha(this.fill_rgba_alpha) + end + local obj = { qf= world_qf, intensity= intensity, draw_overdraw= this.draw_overdraw, texture= this.texture, - fill_rgba= this.fill_rgba, + fill_rgba= fill_rgba, stroke_rgba= this.stroke_rgba, normal1_rgba= this.normal1_rgba, normal2_rgba= this.normal2_rgba diff --git a/pre3d/pre3d_shape_utils.lua b/pre3d/pre3d_shape_utils.lua index 21da0c42..05776bd8 100644 --- a/pre3d/pre3d_shape_utils.lua +++ b/pre3d/pre3d_shape_utils.lua @@ -802,7 +802,7 @@ local function makeXYFunction(f, xmin, ymin, xmax, ymax) local i0 = 1 for i=1, nx do for j=1, ny do - local i1, i2, i3 = i0+1, i0+(ny+1)+1, i0+(ny+1) + local i1, i2, i3 = i0+(ny+1), i0+(ny+1)+1, i0+1 push(quads, Pre3d.QuadFace(i0, i1, i2, i3)) i0 = i0+1 end diff --git a/pre3d/test.lua b/pre3d/test.lua index f3149512..5f13e796 100644 --- a/pre3d/test.lua +++ b/pre3d/test.lua @@ -18,7 +18,7 @@ end function demo1() local win = window('black') - win:transform(300, 300, 240, 240) + win:transform(400, 400, 240, 240) local renderer = Pre3d.Renderer(win) -- shape = ShapeUtils.makeSphere(1, 12, 12) @@ -39,7 +39,10 @@ function demo1() renderer.draw_overdraw = false renderer.draw_backfaces = true - renderer.fill_rgba = rgba(0x42/255, 0x82/255, 0xAA/255, 0.8) + renderer.fill_rgba = rgb(0x4A/255, 0x92/255, 0xBF/255) + renderer.fill_rgba_backside = rgb(0xBF/255, 0x92/255, 0x4A/255) + renderer.set_light_intensity = true + renderer.fill_rgba_alpha = 0.95 renderer.stroke_rgba = rgb(0x66/255, 0x66/255, 0x66/255) renderer.camera.focal_length = 30; @@ -63,7 +66,9 @@ function demo2() renderer.draw_overdraw = false renderer.draw_backfaces = true - renderer.fill_rgba = rgba(0x42/255, 0x82/255, 0xAA/255, 1) + renderer.fill_rgba = rgb(0x4A/255, 0x92/255, 0xBF/255) + renderer.fill_rgba_backside = rgb(0xBF/255, 0x92/255, 0x4A/255) + renderer.set_light_intensity = true renderer.stroke_rgba = rgb(0x66/255, 0x66/255, 0x66/255) renderer.camera.focal_length = 30; @@ -71,9 +76,7 @@ function demo2() local N, tour = 256, 2*pi for j=0, N do local a = tour*j/N - setTransform(renderer.camera.transform, a, 0.15 * a) + setTransform(renderer.camera.transform, -a, -0.15*a) draw(renderer, shape) end end - -demo1() |