problem with 3d rastarizer in lua z dimension is not working - lua
so basicaly i try to translate olc3d engine from cpp to lua in computercraft in minecraft
i can translate the cube in x and y but z does not work
this is the original olc3d engine that i try to copy
https://github.com/OneLoneCoder/videos/blob/master/OneLoneCoder_olcEngine3D_Part1.cpp
function newLine()
xPos, yPos = term.getCursorPos()
term.setCursorPos(1,(yPos + 1))
end
paitutils2.newMonitor("left")
mesh = {
{vector.new(0.0,0.0,0.0),vector.new(0.0,1.0,0.0),vector.new(1.0,1.0,0.0)},
{vector.new(0.0,0.0,0.0),vector.new(1.0,1.0,0.0),vector.new(1.0,0.0,0.0)},
{vector.new(1.0,0.0,0.0),vector.new(1.0,1.0,0.0),vector.new(1.0,1.0,1.0)},
{vector.new(1.0,0.0,0.0),vector.new(1.0,1.0,1.0),vector.new(1.0,0.0,1.0)},
{vector.new(1.0,0.0,1.0),vector.new(1.0,1.0,1.0),vector.new(0.0,1.0,1.0)},
{vector.new(1.0,0.0,1.0),vector.new(0.0,1.0,1.0),vector.new(0.0,0.0,1.0)},
{vector.new(0.0,0.0,1.0),vector.new(0.0,1.0,1.0),vector.new(0.0,1.0,0.0)},
{vector.new(0.0,0.0,1.0),vector.new(0.0,1.0,0.0),vector.new(0.0,0.0,0.0)},
{vector.new(0.0,1.0,0.0),vector.new(0.0,1.0,1.0),vector.new(1.0,1.0,1.0)},
{vector.new(0.0,1.0,0.0),vector.new(1.0,1.0,1.0),vector.new(1.0,1.0,0.0)},
{vector.new(1.0,0.0,1.0),vector.new(0.0,0.0,1.0),vector.new(0.0,0.0,0.0)},
{vector.new(1.0,0.0,1.0),vector.new(0.0,0.0,0.0),vector.new(1.0,0.0,0.0)}
}
matrix = {{0,0,0,0},
{0,0,0,0},
{0,0,0,0},
{0,0,0,0}}
matproj = matrix
wysokosc = 80.0
szerokosc = 164.0
fnear = 0.1
ffar = 1000.0
ffov = 90.0
fasr = (wysokosc/szerokosc)* (7/5) --because 'pixel' is 7x5 pixels
ffovr = 1.0 / math.tan(ffov * 0.5 / 180.0 * math.pi)
w=1
--3dpespective matrix
matproj[1][1] = fasr * ffovr
matproj[2][2] = ffovr
matproj[3][3] = -ffar / (ffar - fnear)
matproj[4][3] = (-ffar * fnear)/(ffar - fnear)
matproj[3][4] = -1.0
matproj[4][4] = 0.0
function proj_mat(matrix ,trj)
proj_tri = vector.new()
--print(trj.x .." ".. trj.y .." " .. trj.z )
proj_tri.x = (trj.x * matrix[1][1]) + (trj.y * matrix[2][1]) + (trj.z * matrix[3][1] )+ w * matrix[4][1]
proj_tri.y = (trj.x * matrix[1][2]) + (trj.y * matrix[2][2]) + (trj.z * matrix[3][2] )+ w * matrix[4][2]
proj_tri.z = (trj.x * matrix[1][3]) + (trj.y * matrix[2][3]) + (trj.z * matrix[3][3] )+ w * matrix[4][3]
w = (trj.x * matrix[1][4]) + (trj.y * matrix[2][4]) + (trj.z * matrix[3][4] )+ w * matrix[4][4]
if not w == 0.0 then
proj_tri.x = proj_tri.x / w
proj_tri.y = proj_tri.y / w
proj_tri.z = proj_tri.z / w
end
print(proj_tri.x .." ".. proj_tri.y .." " .. proj_tri.z .." ".. trj.x .." ".. trj.y .. " " .. trj.z)
return(proj_tri)
end
peripheral.call("left","setBackgroundColor",colors.black)
peripheral.call("left","setCursorBlink",false)
peripheral.call("left","setTextScale",0.5)
peripheral.call("left","clear")
peripheral.call("left","setBackgroundColor",colors.red)
for i = 1 , 12 ,1 do
vert = {}
vert[1] = mesh[i][1]
vert[2] = mesh[i][2]
vert[3] = mesh[i][3]
--print(vert[1].x .." ".. vert[1].y.." " .. vert[1].z .. " "..vert[2].x .." ".. vert[2].y.." " .. vert[2].z .." ".. vert[3].x .." ".. vert[3].y.." " .. vert[3].z)
vert[1].z = vert[1].z + 3.0
vert[2].z = vert[2].z + 3.0 --translacja
vert[3].z = vert[3].z + 3.0
vert[1].x = vert[1].x + 0.25
vert[2].x = vert[2].x + 0.25 --translacja
vert[3].x = vert[3].x + 0.25
--vert[1].y = vert[1].y + 0.5
--vert[2].y = vert[2].y + 0.5 --translacja
--vert[3].y = vert[3].y + 0.5
--print(vert[1].x .." ".. vert[1].y.." " .. vert[1].z .. " | "..vert[2].x .." ".. vert[2].y.." " .. vert[2].z .." | ".. vert[3].x .." ".. vert[3].y.." " .. vert[3].z)
proj_vert = vector.new()
-- proj_vert[1] = proj_mat(rotx,vert[1])
-- proj_vert[2] = proj_mat(rotx,vert[2]) --rotate x
-- proj_vert[3] = proj_mat(rotx,vert[3])
proj_vert[1] = proj_mat(matproj,vert[1])
proj_vert[2] = proj_mat(matproj,vert[2]) --projekcja 3d na 2d
proj_vert[3] = proj_mat(matproj,vert[3])
--skalowanie
proj_vert[1].x = proj_vert[1].x * szerokosc
proj_vert[1].y = proj_vert[1].y * wysokosc + 1
proj_vert[2].x = proj_vert[2].x * szerokosc
proj_vert[2].y = proj_vert[2].y * wysokosc + 1
proj_vert[3].x = proj_vert[3].x * szerokosc
proj_vert[3].y = proj_vert[3].y * wysokosc + 1
paitutils2.drawLine(proj_vert[1].x,proj_vert[1].y,proj_vert[2].x,proj_vert[2].y)
paitutils2.drawLine(proj_vert[1].x,proj_vert[1].y,proj_vert[3].x,proj_vert[3].y)
paitutils2.drawLine(proj_vert[3].x,proj_vert[3].y,proj_vert[2].x,proj_vert[2].y)
term.setTextColor(colors.white)
--term.write("w["..w.."] ")
--newLine()
--term.write(" x[" .. proj_vert[1].x .. "] y[" .. proj_vert[1].y .. "] x2[" .. proj_vert[2].x .. "] y2[" .. proj_vert[2].y .."] \n")
--newLine()
--term.write(" x[" .. proj_vert[1].x .. "] y[" .. proj_vert[1].y .. "] x2[" .. proj_vert[3].x .. "] y2[" .. proj_vert[3].y .."] \n")
--newLine()
--term.write(" x[" .. proj_vert[3].x .. "] y[" .. proj_vert[3].y .. "] x2[" .. proj_vert[2].x .. "] y2[" .. proj_vert[2].y .."] \n")
--newLine()
end
if someone wants to try and replicate the setup it is a 6x8 advanced monitor as a display on the left and advanced computer on the right(it is important the monitor is on the left ).modpack is ftb revelation but it should work with just the computercraft mod instaled.
Related
Hi, I am creating a simpleplatformer game with love2d, I got a problem in the collisions
In my player script. I called a function to check is if a tile is collided with the player. The basic tile collisions has been made, but I got some problems. When the player jump while colliding with the wall, the player stop. When the player is falling while colliding with the wall, the player stop. I think the problem is in the Y collision checking part, but I can't figure out how to solve it. --------------------- Collision Check ---------------------- local box = Vt2:new(self.pos.x + self.vel.x * dt * self.dirXTemp, self.pos.y + self.vel.y * dt) for i = 1, #collTile do local tile = collTile[i] local isColl = BdBoxCollision(box, self.size, tile.pos, tile.size) if isColl[1] == true and isColl[2] == true and isColl[3] == true and isColl[4] == true then local isOnWall = false if self.pos.y + self.size.y > tile.pos.y then -- X Collision if box.x + self.size.x / 2 < tile.pos.x + tile.size.x / 2 then if box.x + self.size.x > tile.pos.x then if self.dirX == 1 then self.vel.x = 0 isOnWall = true end end end if box.x + self.size.x / 2 > tile.pos.x + tile.size.x / 2 then if box.x < tile.pos.x + tile.size.x then if self.dirX == -1 then self.vel.x = 0 isOnWall = true end end end end if box.y + self.size.y / 2 < tile.pos.y + tile.size.y / 2 then -- Y Collision if box.y + self.size.y > tile.pos.y and self.pos.y + self.size.y < tile.pos.y + 8 then if isOnWall == false then self.pos.y = tile.pos.y - self.size.y self.vel.y = 0 end end elseif box.y + self.size.y / 2 > tile.pos.y + tile.size.y / 2 then if box.y < tile.pos.y + tile.size.y then self.vel.y = self.gravity end end end end ::skip:: self.pos.x = self.pos.x + self.vel.x * dt self.pos.y = self.pos.y + self.vel.y * dt
print method in lua script/redis is not working
I am trying to execute the following script and getting the below error. Redis is running in docker Exception in thread "main" org.redisson.client.RedisException: ERR user_script:1: Script attempted to access nonexistent global variable 'print' script: 6f736423f082e141036b833d1f86b5a36a494611, on #user_script:1.. I get the same error when I execute using redis CLI 127.0.0.1:6379> eval "print("Comparison is_made b/w minimum_value out of two is: ")" 0 (error) ERR user_script:1: Script attempted to access nonexistent global variable 'print' script: 8598b7f0db450c711d3a9e73a296e331bd1ef945, on #user_script:1. 127.0.0.1:6379> Java code. I am using Redison lib to connect to Redis and execute script. String script = "local rate = redis.call('hget', KEYS[1], 'rate');" + "local interval = redis.call('hget', KEYS[1], 'interval');" + "local type = redis.call('hget', KEYS[1], 'type');" + "assert(rate ~= false and interval ~= false and type ~= false, 'RateLimiter is not initialized')" + "local valueName = KEYS[2];" + "local permitsName = KEYS[4];" + "if type == '1' then " + "valueName = KEYS[3];" + "permitsName = KEYS[5];" + "end;" +"print(\"rate\"..rate) ;" +"print(\"interval\"..interval) ;" +"print(\"type\"..type); " + "assert(tonumber(rate) >= tonumber(ARGV[1]), 'Requested permits amount could not exceed defined rate'); " + "local currentValue = redis.call('get', valueName); " + "local res;" + "if currentValue ~= false then " + "local expiredValues = redis.call('zrangebyscore', permitsName, 0, tonumber(ARGV[2]) - interval); " + "local released = 0; " + "for i, v in ipairs(expiredValues) do " + "local random, permits = struct.unpack('Bc0I', v);" + "released = released + permits;" + "end; " + "if released > 0 then " + "redis.call('zremrangebyscore', permitsName, 0, tonumber(ARGV[2]) - interval); " + "if tonumber(currentValue) + released > tonumber(rate) then " + "currentValue = tonumber(rate) - redis.call('zcard', permitsName); " + "else " + "currentValue = tonumber(currentValue) + released; " + "end; " + "redis.call('set', valueName, currentValue);" + "end;" + "if tonumber(currentValue) < tonumber(ARGV[1]) then " + "local firstValue = redis.call('zrange', permitsName, 0, 0, 'withscores'); " + "res = 3 + interval - (tonumber(ARGV[2]) - tonumber(firstValue[2]));" + "else " + "redis.call('zadd', permitsName, ARGV[2], struct.pack('Bc0I', string.len(ARGV[3]), ARGV[3], ARGV[1])); " + "redis.call('decrby', valueName, ARGV[1]); " + "res = nil; " + "end; " + "else " + "redis.call('set', valueName, rate); " + "redis.call('zadd', permitsName, ARGV[2], struct.pack('Bc0I', string.len(ARGV[3]), ARGV[3], ARGV[1])); " + "redis.call('decrby', valueName, ARGV[1]); " + "res = nil; " + "end;" + "local ttl = redis.call('pttl', KEYS[1]); " + "if ttl > 0 then " + "redis.call('pexpire', valueName, ttl); " + "redis.call('pexpire', permitsName, ttl); " + "end; " + "return res;"; RedissonClient client = null; try { client = Redisson.create(); client.getRateLimiter("user1:endpoint1").setRate( RateType.PER_CLIENT, 5, 1, RateIntervalUnit.SECONDS); String sha1 = client.getScript().scriptLoad(script); List<Object> keys = Arrays.asList("user1:endpoint1", "{user1:endpoint1}:value", "{user1:endpoint1}:value:febbb04d-6365-4cb8-b32b-8d90800cd4e6", "{user1:endpoint1}:permits", "{user1:endpoint1}:permits:febbb04d-6365-4cb8-b32b-8d90800cd4e6"); byte[] random = new byte[8]; ThreadLocalRandom.current().nextBytes(random); Object args[] = {1, System.currentTimeMillis(), random}; boolean res = client.getScript().evalSha(READ_WRITE, sha1, RScript.ReturnType.BOOLEAN, keys, 1, System.currentTimeMillis(), random); System.out.println(res); }finally { if(client != null && !client.isShutdown()){ client.shutdown(); } } checked the Lua print on the same line thread but io.write also is giving same error.
As in the comments wrote return() seems* the only way. Example for redis-cli (set redis DB and use it in Lua) (Collect Data and return as one string) set LuaV 'local txt = "" for k, v in pairs(redis) do txt = txt .. tostring(k) .. " => " .. tostring(v) .. " | " end return(txt)' Now the eval eval "local f = redis.call('GET', KEYS[1]) return(loadstring(f))()" 1 LuaV ...shows whats in table: redis (One long String no \n possible) Exception: eval 'redis.log(2, _VERSION)' 0 gives out without ending the script but only on the server. Than \n will work when you do... set LuaV 'local txt = "" for k, v in pairs(redis) do txt = txt .. tostring(k) .. " => " .. tostring(v) .. "\n" end return(txt)' ...and the eval eval 'local f = redis.call("GET", KEYS[1]) f = loadstring(f)() redis.log(2, f)' 1 LuaV
Unit root test on lagged variables
guys! I'm using this sintaxe but when I use the last part ("modelo = ...") it shows the following: "Error in merge.zoo(difetanol, detanol, mes2, mes3, mes4, mes5, mes6, mes7, : all(sapply(args, function(x) is.zoo(x) || !is.plain(x) || (is.plain(x) && .... is not TRUE" ethidra = (tsrelatorio[,"etanol"]) ethidra length(ethidra) acuavhp = (tsrelatorio[,"avhp"]) acuavhp length(acuavhp)``` matr <- matrix(0, nr = 12, nc = 12) matr[row(matr) == col(matr)] <- 1 matr Djt <- rbind(matr,matr,matr,matr); Djt dim(Djt) names(Djt) dimnames(Djt) = list(c(),c("M1", "M2", "M3", "M4","M5","M6","M7","M8","M9","M10","M11","M12")) Djt dim(Djt)``` teste=data.frame(Djt) attach(teste) mes2= teste[1:47,2] mes2 length(mes2) mes3= teste[1:47,3] mes3 length(mes3) mes4= teste[1:47,4] mes4 length(mes4) mes5= teste[1:47,5] mes5 length(mes5) mes6= teste[1:47,6] mes6 length(mes6) mes7= teste[1:47,7] mes7 length(mes7) mes8= teste[1:47,8] mes8 length(mes8) mes9= teste[1:47,9] mes9 length(mes9) mes10= teste[1:47,10] mes10 length(mes10) mes11= teste[1:47,11] mes11 length(mes11) mes12= teste[1:47,12] mes12 length(mes12) detanol = (ethidra[1:47]) detanol length(detanol) difetanol=diff(detanol) difetanol length(difetanol) tempo = tempo <- seq(1:47) modelo = dynlm(difetanol ~ detanol + mes2 +mes3 +mes4 + mes5 + mes6 + mes7 + mes8 + mes9 + mes10 + mes11 + mes12 + tempo + L(difetanol,1) + L(difetanol,2)) summary(modelo)
My 'elseif' Statement Has a Bug
if message:sub(6, message:len()) == "%d+" then local a = message:find(" ") local hatId = message:sub(a + 1, message:len()) local hat = game:GetService("InsertService"):LoadAsset(tonumber(hatId)):GetChildren()[1] hat.Parent = character print("Adding hat " .. hatId .. " to " .. player.Name) elseif message:sub(6, message:len()) ~= "%d+" then local a, b = message:find(" ") local c, d = message:find(" ", b + 1) local meshId = message:sub(b + 1, d) local textureId = message:sub(d + 1, message:len()) local hat = game:GetService("InsertService"):LoadAsset(tonumber(meshId)):GetChildren()[1] hat.Parent = character hat.Handle.Mesh.TextureId = "http://www.roblox.com/asset/?id=" .. textureId print("Adding hat " .. meshId .. " with texture " .. textureId .. " to " .. player.Name) end For some reason, after I type in /hat hatIdHere, it goes on to the elseif statement and says that there's an error at the local hat = game:GetService(--[===[etc]===] line. There should not be an error because the code there shouldn't be running. However, if I type in /hat meshId textureId, then it works. Please help, I have no clue why this isn't working. My message is a defined string.
How to monitor progress from ffmpeg?
I have this ffmpeg video encoder using Rails and I needed to report ffmpeg progress to the user. How can that be done provided that I am using Linux?
This is the solution I reached: def execute_ffmpeg(cmd, progress) logger.debug "Running command #{cmd}" command = "#{cmd} 2>&1" progress = nil frames = nil fps = 25 ffmpeg = IO.popen(command) ffmpeg.each("\r") do |line| if frames.nil? && line =~ /Duration:(\s.?(\d*):(\d*):(\d*\.\d*))/ duration = $2.to_s + ":" + $3.to_s + ":" + $4.to_s frames = ($4.to_i + ($3.to_i * 60) + ($2.to_i * 60 * 60)) * fps end if line =~ /frame=(\s.?(\d*))/ progress = $1.to_i / frames.to_i print "Progress: #{progress}" end end end
Thanks for the post, I modified it a little. I am using ffmpeg version 0.10.2. Here's my version: def exec_ffmpeg src_path, dst_path cmd = "ffmpeg -i \"%s\" -acodec libfaac -ac 2 -ab 128k -vcodec libx264 -threads 0 \"%s\" 2>&1" % [src_path, dst_path] puts "%s" % cmd.gsub(/2\>\&1$/,'') puts "press 'q' to quit" progress = nil dur_secs = nil frame_rate = nil frames = 0 dur_str = '00:00:00.000' ostr = '' ffmpeg = IO.popen(cmd) ffmpeg.each("\r") do |line| if dur_secs == nil && line =~ /Duration:\s*(\d*):(\d*):(\d*\.\d*)/ dur_str = $1.to_s + ":" + $2.to_s + ":" + $3.to_s dur_secs = ($3.to_f + ($2.to_i * 60).to_f + ($1.to_i * 360).to_f) puts "Video Duration:" + dur_str end if frame_rate == nil && line =~ /Stream.+\, (\d+\.{0,1}\d{0,3}) fps\,/ frame_rate = $1.to_f frames = dur_secs * frame_rate puts "Total Frames: %i" % frames.to_i puts "Frame Rate: %.3f fps" % frame_rate end if line =~ /frame=(\s.?(\d*))/ cframe = $1.to_i csecs = 0 if line =~ /time=\s*(\d*):(\d*):(\d*\.\d*)/ csecs = ($3.to_f + ($2.to_i * 60).to_f + ($1.to_i * 360).to_f) csecs_str = $1.to_s + ":" + $2.to_s + ":" + $3.to_s elsif line =~ /time=\s*(\d*\.\d*)/ csecs $1.to_f t = Time.at(csecs).gmtime csecs_str = "%0.2i:%0.2i:%0.2i.%3i" % [t.hour, t.min, t.sec, t.nsec] end if line =~ /fps=\s*(\d*)/ cfps = $1.to_i else cfps = 0 end if line =~ /bitrate=\s*(\d*\.\d*kbits)/ br = $1 else br = "???" end ostr = " %3.2f%% ( %s ) #frame:%i fps:%i bitrate:%s" % [((csecs/dur_secs)*100), csecs_str, cframe, cfps, br] print ostr + ("\b" * (ostr.length + 4)) end end print "\n" end