pie_3d.lua


NAME
    pie_3d

FUNCTION
    pie_3d(r, h, n, a, b)

NOTES
    Creates a pie shape at (0, 0, 0).

INPUTS
    r    - radius in pixel
    h    - height in pixel along z-axis
    n    - number of slices that comprise the shape
    a    - start angle in degree
    b    - end angle in degree

OUTPUTS
    a zeNode object

SOURCE

require("register")

function pie_3d(r, h, n, a, b)
    local shape1, xyz1, nor1 = zeGrf.new("polygon", "vertex", "vertex")
    shape1:set{vertex = xyz1, vertex_normal = nor1, type = "quadstrip"}

    local shape2, xyz2, nor2 = zeGrf.new("polygon", "vertex", "vertex")
    shape2:set{vertex = xyz2, vertex_normal = nor2, type = "trianglefan"}

    local shape3, xyz3, nor3 = zeGrf.new("polygon", "vertex", "vertex")
    shape3:set{vertex = xyz3, vertex_normal = nor3, type = "quads"}
    
    local node = zeGrf.new("node")
    node:add(shape1, shape2, shape3)
    
    local arr = zeUtl.new("double")
    
    zeMake.cylinder(arr, h, r, r, n, a, b-a)
    xyz1:add(arr)
    arr:shift(3)
    nor1:add(arr)

    zeMake.fan(arr, r, n, a, b-a)
    arr:setarr(2, h)
    xyz2:add(arr)
    nor2:add(0, 0, 1)
    
    local x = math.cos(0.017453293 * a)
    local y = math.sin(0.017453293 * a)
    xyz3:add(0, 0, 0)
    xyz3:add(r * x, r * y, 0)
    xyz3:add(r * x, r * y, h)
    xyz3:add(0, 0, h)
    nor3:add(y, -x, 0)
    nor3:add(y, -x, 0)
    nor3:add(y, -x, 0)
    nor3:add(y, -x, 0)

    x = math.cos(0.017453293 * b)
    y = math.sin(0.017453293 * b)
    xyz3:add(0, 0, 0)
    xyz3:add(0, 0, h)
    xyz3:add(r * x, r * y, h)
    xyz3:add(r * x, r * y, 0)
    nor3:add(-y, x, 0)
    nor3:add(-y, x, 0)
    nor3:add(-y, x, 0)
    nor3:add(-y, x, 0)

    return node
end