rit-sse / Voxel-Display

Volex Display Research
3 stars 1 forks source link

Design / Build Software Driver #9

Open JRJurman opened 10 years ago

JRJurman commented 10 years ago

Design how we turn voxel positions (x,y,z) into positions (x,y) on front-facing and side-facing sheets.

JRJurman commented 10 years ago

@ethanjurman 's design from a top-down perspective

image

weswigham commented 10 years ago
local function transform(vec)
    return Vector(math.floor((vec.x)/2), math.floor((vec.y)/2), vec.z)
end

local display = {
    voxel_width = 25, --number of voxels
    voxel_depth = 25,
    voxel_height = 25,
    planesx = {},
    planesy = {},
    voxels = {}
}

function display:zero()
    self.voxels = {}
    self.planesx = {}
    self.planesy = {}
end

function display:setVoxel(x, y, z, state)
    if (x<0 or y<0 or z<0
        or x>self.voxel_width-1
        or y>self.voxel_depth-1
        or z>self.voxel_height-1) then
        return 
        --Honestly, this just keeps the voxels within the defined bounds
        --If you wanted to us this in garrysmod, nothing's stopping you from removing it and placing your voxels
        --anywhere in the world space
    end
    if not self.voxel then self.voxel = {} end
    if not self.voxel[x] then self.voxel[x] = {} end
    if not self.voxel[x][y] then self.voxel[x][y] = {} end

    if state then
        if (not self.voxel[x][y][z]) then
            self:toggleVoxel(x, y, z)
        end
    else
        if (self.voxel[x][y][z]) then
            self:toggleVoxel(x, y, z)
        end
    end
end

function display:toggleVoxel(x, y, z)
    if (x<0 or y<0 or z<0
        or x>self.voxel_width-1
        or y>self.voxel_depth-1
        or z>self.voxel_height-1) then
        return 
        --Honestly, this just keeps the voxels within the defined bounds
        --If you wanted to us this in garrysmod, nothing's stopping you from removing it and placing your voxels
        --anywhere in the world space
    end

    if not self.voxel then self.voxel = {} end
    if not self.voxel[x] then self.voxel[x] = {} end
    if not self.voxel[x][y] then self.voxel[x][y] = {} end
    if not self.voxel[x][y][z] then self.voxel[x][y][z] = true else
        self.voxel[x][y][z] = nil
    end

    local planes = {
        Vector(2*x,2*y+1,z),
        Vector(2*x+2,2*y+1,z),
        Vector(2*x+1,2*y,z),
        Vector(2*x+1,2*y+2,z)
    }

    for k,v in ipairs(planes) do
        local c = transform(v)
        local plane;
        if v.x%2==0 then --vertical (x)
            plane = self.planesx
        else --horizontal (y)
            plane = self.planesy
        end
        if not plane[c.x] then plane[c.x] = {} end
        if not plane[c.x][c.y] then plane[c.x][c.y] = {} end

        if plane[c.x][c.y][c.z] then
            plane[c.x][c.y][c.z] = nil
        else
            plane[c.x][c.y][c.z] = true
        end
    end
end

Voxel = {
    display = display
}

Proven by practice. Trivial to rewrite in C, as likely needs be.

JRJurman commented 10 years ago

The JVM's support for serial connection may be a little sketchy, at least, more so than originally expected... As a result, we may be converting what we have to python (unless anybody has a language they would suggest using instead).