bar_3d.lua


NAME
    bar_3d

FUNCTION
    bar_3d(r, h, n)

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

INPUTS
    r    - radius in pixels
    h    - height in pixels along z-axis
    n    - number of slices that comprise the shape

OUTPUTS
    node - a zeNode object

SOURCE

require("register")

function bar_3d(r, h, n)
    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 node = zeGrf.new("node")
    node:add(shape1, shape2)
    
    local arr, vec = zeUtl.new("double", "double")
    
    zeMake.cylinder(arr, h, r, r, n, 0, 360)
    xyz1:add(arr)
    arr:shift(3)
    nor1:add(arr)

    zeMake.fan(arr, r, n, 0, 360)
    local m = arr:size()
    vec:resize(m, 1)
    vec:fill(h)
    arr:setarr(2, vec)
    xyz2:add(arr)
    nor2:add(0, 0, 1)
    
    return node
end