Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local mon = peripheral.find("monitor")
- local ar = peripheral.find("arController")
- local oldTerm = term.redirect(mon)
- mon.setTextScale(0.5)
- mon.setCursorPos(1,1)
- mon.clear()
- term.setCursorPos(1,1)
- term.clear()
- ar.clear()
- local function drawFlatBottomTriangleTex( arController,vec1,vec2,vec3,tex )
- local m1 = (vec2.x - vec1.x) / (vec2.y - vec1.y)
- local m2 = (vec3.x - vec1.x) / (vec3.y - vec1.y)
- local yStart = math.ceil(vec1.y-0.5)
- local yEnd = math.ceil(vec3.y-0.5)-1
- local C = vec2 --Bottom left
- local B = vec1 --Top
- local A = vec3 --Bottom Right
- arController.drawString(A.u..", "..A.v ,A.x+100, A.y, 0xFF00FF)
- arController.drawString(B.u..", "..B.v ,B.x+100, B.y, 0xFF00FF)
- arController.drawString(C.u..", "..C.v ,C.x+100, C.y, 0xFF00FF)
- local tWidth = tex.size.x
- local tHeight = tex.size.y
- for y = yStart, yEnd do
- local px1 = m1 * (y + 0.5 - vec1.y) + vec1.x
- local px2 = m2 * (y + 0.5 - vec1.y) + vec1.x
- local xStart = math.ceil(px1 - 0.5)
- local xEnd = math.ceil(px2 - 0.5)
- for x = xStart, xEnd do
- if y > 0 and x > 0 then
- local w1 =
- ( (A.x*(C.y - A.y)) + ((y - A.y)*(C.x - A.x)) - (x*(C.y - A.y)) )
- / ( ((B.y - A.y) * (C.x - A.x)) - ((B.x - A.x) * (C.y - A.y)) )
- local w2 = (y - A.y - (w1 * (B.y - A.y))) / (C.y - A.y)
- local w3 = 1-w1-w2
- print(w1,w2,w3)
- local u = (w1*A.u)+(w2*B.u)+(w3*C.u)
- local v = (w1*A.v)+(w2*B.v)+(w3*C.v)
- local tu = math.floor(u * tWidth)
- local tv = math.floor(v * tHeight)
- local color
- local colIndex = (tv*tWidth + tu)
- --local colIndex = ((y-(yStart-1))*tWidth + (x-(xStart-1)))
- if tex[ colIndex ] then
- color = tex[ colIndex ] --Look up the pixel color in the image texture
- else
- color = 0xFF00FF
- end
- arController.horizontalLine(x, x, y, color)
- end
- end
- end
- end
- local function getTex(fileName)
- local f, err = fs.open(fileName, "r")
- assert(f, err)
- local fileData = textutils.unserialize(f.readAll())
- f.close()
- return fileData
- end
- local shronk = getTex("shrekC")
- local v1 = { x = 100, y = 100, z = 4, u = 0, v = 1, }
- local v2 = { x = 100, y = 200, z = 4, u = 0, v = 0, }
- local v3 = { x = 200, y = 200, z = 4, u = 1, v = 0, }
- drawFlatBottomTriangleTex(ar, v1 , v2, v3, shronk)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement