Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local function makeRot(rot)
- rot = math.rad(rot)
- return { math.cos(rot), -math.sin(rot), 0,
- math.sin(rot), math.cos(rot), 0,
- 0, 0, 1, }
- end
- local function makeIdentity()
- return { 1, 0, 0,
- 0, 1, 0,
- 0, 0, 1, }
- end
- local function makeScale(scale)
- return { scale.x, 0, 0,
- 0, scale.y, 0,
- 0, 0, 1, }
- end
- local function makeLoc(loc)
- return { 1, 0, loc.x,
- 0, 1, loc.y,
- 0, 0, loc.z, }
- end
- local function matMul(m,vL)
- local result = {}
- --print(textutils.serialise(m))
- for i = 1, #vL, 3 do
- local i1,i2 = i+1,i+2
- result[i] = vL[i]*m[1]+vL[i1]*m[4]+vL[i2]*m[7]
- result[i1] = vL[i]*m[2]+vL[i1]*m[5]+vL[i2]*m[8]
- result[i2] = vL[i]*m[3]+vL[i1]*m[6]+vL[i2]*m[9]
- end
- return result
- end
- local function makeTri()
- local data = {
- loc = vector.new( 0, 0, 1),
- rot = 0,
- scale = vector.new( 5, 5 ),
- vL = {
- -1/3, 0, 1,
- 0, 1, 1,
- 1/3, 0, 1,
- },
- iL = {
- 1, 2, 3,
- },
- cL = {
- 0xee6c4d,
- }
- }
- for i,val in ipairs(data.iL) do
- data.iL[i] = val*3-2
- end
- return data
- end
- --center to screen, grab vertices from index list and load them into final vertice list
- local function postProcess(vL,iL,display)
- local hw = display.x * 0.5
- local hh = display.y * 0.5
- local result = {}
- for i = 1, #iL, 9 do
- i1,i2 = i+1,i+2
- result[i] = vL[ iL[i] ] + hw
- result[i+1] = vL[ iL[i]+1 ] + hh
- result[i+2] = vL[ iL[i]+2 ]
- result[i+3] = vL[ iL[i1] ] + hw
- result[i+4] = vL[ iL[i1]+1 ] + hh
- result[i+5] = vL[ iL[i1]+2 ]
- result[i+6] = vL[ iL[i2] ] + hw
- result[i+7] = vL[ iL[i2]+1 ] + hh
- result[i+8] = vL[ iL[i2]+2 ]
- end
- return result
- end
- local function processVertices(oL,display)
- local result = {}
- for name,obj in pairs(oL) do
- result[name] = {}
- result[name] = matMul(makeLoc(obj.loc), matMul(makeRot(obj.rot), matMul(makeScale(obj.scale), obj.vL)))
- result[name] = postProcess(result[name],obj.iL,display)
- result[name].cL = obj.cL
- end
- return result
- end
- return {
- processVertices = processVertices,
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement