-rw-r--r-- | agg-plot/agg_platform_support_x11.cpp | 9 | ||||
-rw-r--r-- | agg-plot/canvas.h | 2 | ||||
-rw-r--r-- | agg-plot/colors.cpp | 2 | ||||
-rw-r--r-- | examples/anim.lua | 2 | ||||
-rw-r--r-- | examples/nlinfit.lua | 1 | ||||
-rw-r--r-- | pre3d/pre3d_shape_utils.lua | 32 | ||||
-rw-r--r-- | pre3d/test.lua | 30 |
diff --git a/agg-plot/agg_platform_support_x11.cpp b/agg-plot/agg_platform_support_x11.cpp index 8e9152a7..60c83587 100644 --- a/agg-plot/agg_platform_support_x11.cpp +++ b/agg-plot/agg_platform_support_x11.cpp @@ -76,10 +76,9 @@ namespace agg pthread_mutex_t m_mutex[1]; + static bool initialized; }; - - //------------------------------------------------------------------------ platform_specific::platform_specific(pix_format_e format, bool flip_y) : m_format(format), @@ -1238,9 +1237,15 @@ namespace agg } +bool agg::platform_specific::initialized = false; void platform_support_prepare() { + if (! agg::platform_specific::initialized) + { + XInitThreads(); + agg::platform_specific::initialized = true; + } } void platform_support_lock(agg::platform_support *app) diff --git a/agg-plot/canvas.h b/agg-plot/canvas.h index 8ffc3c04..4cffc5d2 100644 --- a/agg-plot/canvas.h +++ b/agg-plot/canvas.h @@ -53,7 +53,7 @@ public: m_width(width), m_height(height) { mtx.scale(width, height); - prof.width(1.0); + prof.width(1.5); }; double width() const { return m_width; }; diff --git a/agg-plot/colors.cpp b/agg-plot/colors.cpp index a9b31413..a972a809 100644 --- a/agg-plot/colors.cpp +++ b/agg-plot/colors.cpp @@ -7,7 +7,7 @@ agg::rgba8 * rgba8_push_default (lua_State *L) { - return new(L, GS_RGBA_COLOR) agg::rgba8(180, 0, 0, 255); + return new(L, GS_RGBA_COLOR) agg::rgba8(80, 0, 0, 255); } agg::rgba8 * diff --git a/examples/anim.lua b/examples/anim.lua index 0d1b1828..8047e00e 100644 --- a/examples/anim.lua +++ b/examples/anim.lua @@ -29,7 +29,7 @@ function demo2() local w = 4*exp((j-256)/256) p:clear() local ln = fxline(|x| exp(-0.1*x)*cos(w*x), 0, x1) - p:draw(ln, 'red', {{'stroke'}}) + p:draw(ln, 'red', {{'stroke', width=1.5}}) p:refresh() end end diff --git a/examples/nlinfit.lua b/examples/nlinfit.lua index 3828097f..5a6e20b2 100644 --- a/examples/nlinfit.lua +++ b/examples/nlinfit.lua @@ -133,6 +133,7 @@ function demo2bis() pl = plot('Non-linear fit / A * exp(a t) sin(w t)') pl:addline(xyline(x, y), 'blue', {{'marker', size= 5}}) + pl:show() local function print_state(s) print ("x: ", tr(s.p)) diff --git a/pre3d/pre3d_shape_utils.lua b/pre3d/pre3d_shape_utils.lua index 05776bd8..cc52ad60 100644 --- a/pre3d/pre3d_shape_utils.lua +++ b/pre3d/pre3d_shape_utils.lua @@ -814,6 +814,37 @@ local function makeXYFunction(f, xmin, ymin, xmax, ymax) return s end + +local function makeUVSurface(x, y, z, umin, vmin, umax, vmax, nu, nv) + nu = nu and nu or 20 + nv = nv and nv or 20 + + local s = Pre3d.Shape() + for i=0, nu do + local u = umin + (umax - umin)*i/nu + for j=0, nv do + local v = vmin + (vmax - vmin)*j/nv + local xp, yp, zp = x(u,v), y(u,v), z(u,v) + push(s.vertices, {x= xp, y= yp, z= zp}) + end + end + + local quads = {} + local i0 = 1 + for i=1, nu do + for j=1, nv do + local i1, i2, i3 = i0+(nv+1), i0+(nv+1)+1, i0+1 + push(quads, Pre3d.QuadFace(i0, i1, i2, i3)) + i0 = i0+1 + end + i0 = i0+1 + end + + s.quads = quads + rebuildMeta(s) + return s +end + return { rebuildMeta= rebuildMeta, triangulate= triangulate, @@ -827,6 +858,7 @@ return { makeSphere= makeSphere, makeOctahedron= makeOctahedron, makeXYFunction= makeXYFunction, + makeUVSurface= makeUVSurface, averageSmooth= averageSmooth, linearSubdivide= linearSubdivide, diff --git a/pre3d/test.lua b/pre3d/test.lua index b1855f1e..ff291090 100644 --- a/pre3d/test.lua +++ b/pre3d/test.lua @@ -95,7 +95,7 @@ function demo3() -- renderer.fill_rgba_alpha = 0.95 -- renderer.stroke_rgba = rgb(0x66/255, 0x66/255, 0x66/255) - renderer.camera.focal_length = 30; + renderer.camera.focal_length = 40; local N, tour = 256, 2*pi for j=0, N do @@ -104,3 +104,31 @@ function demo3() draw(renderer, shape) end end + +function demo4() + local win = window('black') + win:setview(-1, -1, 1, 1) + + local renderer = Pre3d.Renderer(win) + local x = |u,v| (1 + 1/2 * v *cos(u/2))*cos(u) + local y = |u,v| (1 + 1/2 * v *cos(u/2))*sin(u) + local z = |u,v| 1/2 * v * sin(u/2) + local shape = ShapeUtils.makeUVSurface(y, z, x, 0, -1, 2*pi, 1, 60, 4) + + renderer.draw_overdraw = false + renderer.draw_backfaces = true + 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.draw_overdraw = true +-- renderer.stroke_rgba = rgb(0x66/255, 0x66/255, 0x66/255) + + renderer.camera.focal_length = 40; + + local N, tour = 256, 2*pi + for j=0, N do + local a = tour*j/N + setTransform(renderer.camera.transform, -a, -0.15*a) + draw(renderer, shape) + end +end |