Skip to content

Instantly share code, notes, and snippets.

local abs,cos,sin,tan,acos,asin,atan,deg,rad,floor,fmod,modf,max,min,pow,sqrt=math.abs,math.cos,
math.sin,math.tan,math.acos,math.asin,math.atan,math.deg,math.rad,math.floor,math.fmod,
math.modf,math.max,math.min,math.pow,math.sqrt
local fmod,modf,pack=math.fmod,math.modf,table.pack
n=5000000
local a,b,c,d=math.random()*100,math.random()*100,math.random()*100,math.random()*100
local v1=vec3(math.random()*100,math.random()*100,-math.random()*100)
local v2=vec3(math.random()*100,math.random()*100,math.random()*100)
local tbl={1,2,3,4}
--# Main
-- Speed
local abs,cos,sin,tan,acos,asin,atan,deg,rad,floor,fmod,modf,max,min,pow,sqrt=math.abs,math.cos,
math.sin,math.tan,math.acos,math.asin,math.atan,math.deg,math.rad,math.floor,math.fmod,
math.modf,math.max,math.min,math.pow,math.sqrt
local fmod,modf,pack=math.fmod,math.modf,table.pack
function setup()
@dermotbalson
dermotbalson / gist:adc5004948da9caaa392
Created November 23, 2015 06:14
Tank with target width
--# Main
-- Tiger4
displayMode(FULLSCREEN)
function setup()
backup("WoT","ver 106","culling 2")
Settings()
end
local V=Vec2
function setup()
txt=""
n=50000000 --iterations
--test data
local a,b,c,d=23,-45.54,86,4
local v1,v2=vec3(120,3,-34),vec3(412,4,23)
v3,v4=vec2(5,-2),vec2(3.623,789.43)
vx3,vy3,vx4,vy4=v3.x,v3.y,v4.x,v4.y
--given a 2D table "tiles" with a cell for each tile on the ground, and each cell containing a list of objects
--in that cell,find all cells which are in line of sight between points A and T
--s is cellsize (square)
--tiles is a 2D table
--results will be passed back in a table
--so if tile[3][4] is in line of sight, then (whatever is in) tiles[3][4] will be added to the results
function GetTiles(T,A,s,tiles)
local x0,y0,x1,y1=T.x/s,T.z/s,A.x/s,A.z/s --tile positions of the two points
local dx = abs(x1-x0)
local dy = abs(y1-y0)
--Circles2
local dx,dy,f1x,f1y,f2x,f2y,invPM1,cosFOV,cosFOV2
local sqrt=math.sqrt
function setup()
pos=vec2(100,100) --circle position
camPos=vec2(WIDTH/2,HEIGHT/2) --fixed camera
far=700
print("Fructum is in blue, pointing up")
print("True tangent is in pink")
function setup()
FOV=45
perspective(FOV)
PM1=1/projectionMatrix()[1]
ortho()
pos=vec2(100,100) --circle position
camPos=vec2(WIDTH/2,HEIGHT/2) --fixed camera
--camDir=vec2(0.25,1):normalize() --camera direction
far=700
--fructum=mesh()
@dermotbalson
dermotbalson / gist:69b25e4e00a105ca46f9
Last active November 16, 2015 08:15
Frustum test
function setup()
FOV=45
perspective(FOV)
PM1=1/projectionMatrix()[1]
ortho()
pos=vec2(100,100) --circle position
camPos=vec2(WIDTH/2,0) --fixed camera
camDir=vec2(0.25,1):normalize() --camera direction
far=700
fructum=mesh()
function setup()
FOV=45
perspective(FOV)
PM1=1/projectionMatrix()[1]
ortho()
pos=vec2(100,100) --circle position
camPos=vec2(WIDTH/2,0) --fixed camera
camDir=vec2(-0.5,1):normalize() --camera direction
far=700
fructum=mesh()
@dermotbalson
dermotbalson / gist:7a5988ff80924d3a7c23
Created November 14, 2015 00:22
Is point in triangle
function setup()
A={}
n=10000
for i=1,n do
A[i]=vec2(math.random(0,WIDTH),math.random(0,HEIGHT))
end
v1,v2,v3=vec2(445,30),vec2(150,500),vec2(600,600)
parameter.integer("Method",1,4,1)
methods={IsPointInTriangleBary,IsPointInTrianglePara,IsPointInTriangleDot,IsPointInTriangleDot2}
local n1=vec2(v2.y-v1.y,v1.x-v2.x)