Ooh, nice.
@LoopSpace I wasn’t able to get it working exactly, the scale logic works great but for translation i end up going with deltaXY (when i tried to implement translation earlier i couldnt get it to work)
ill try rotation tomorrow
for now here is the code i have
(note that instead of a# c# i’d put ab or cd
-- zoom pan
-- Use this function to perform your initial setup
function setup()
print("Hello World!")
trans=vec2(0,0)
scalar=vec2(1,1)
end
-- This function gets called once every frame
tick = 0
function draw()
-- This sets a dark background color
background(40, 40, 50)
-- This sets the line thickness
strokeWidth(5)
-- Do your drawing here
pushMatrix()
scale(scalar.x,scalar.y)
translate(trans.x,trans.y)
sprite("Blocks:Brick Grey",0,0)
popMatrix()
textMode(CORNER)
text(trans.x..','..trans.y, 50,700)
text(scalar.x,50,650)
end
abtap = {}
cdtap = {}
-- prevtap = {}
idtap = {}
function began(t)
if t.state == BEGAN then
local a,b = abtap.a,abtap.b
if not a and not b then
-- print"creaate tap a"
abtap.a = vec2(t.x,t.y)
cdtap.c = vec2(t.x,t.y)
-- prevtap.c = vec2(t.x,t.y)
idtap.a = t.id
elseif a and not b then
-- print"create tap b"
abtap.b = vec2(t.x,t.y)
cdtap.d = vec2(t.x,t.y)
-- prevtap.d = vec2(t.x,t.y)
idtap.b = t.id
elseif b and not a then
-- print"created tap à "
abtap.a = vec2(t.x,t.y)
cdtap.c = vec2(t.x,t.y)
-- prevtap.c = vec2(t.x,t.y)
idtap.a = t.id
end
end
end
function pan(t)
if t.state == MOVING then
local a,b = abtap.a,abtap.b
if not (a and b) then return end
local c,d = cdtap.c,cdtap.d
if idtap.a==t.id then
--abtap.a = vec2(t.prevX,t.prevY)
-- prevtap.c = vec2(t.prevX,t.prevY)
cdtap.c = vec2(t.x,t.y)
dotap(t)
elseif idtap.b==t.id then
--abtap.b = vec2(t.prevX,t.prevY)
-- prevtap.d = vec2(t.prevX,t.prevY)
cdtap.d = vec2(t.x,t.y)
dotap(t)
end
end
end
function dotap(t)
local a,b = abtap.a,abtap.b
local c,d = cdtap.c,cdtap.d
-- local pc, pd = prevtap.c, prevtap.d
local ab = (a+b)/2 --original touch center
local cd = (c+d)/2 --current touch center
--local pcd = (pc+pd)/2 --prev touch center
local r = a:dist(ab)
local s = c:dist(cd)
local rs = s/r
--trans = trans - ab
--trans = trans - pcd
scalar = vec2(rs,rs)
--print(rs)
--trans = trans * rs
--trans = trans + vec2(cd.x,cd.y)
--trans = trans + pcd
trans = trans + vec2(t.deltaX,t.deltaY)
end
function touched(t)
began(t)
pan(t)
ended(t)
end
function ended(t)
if t.state == CANCELLED or t.state == ENDED then
if idtap.a==t.id then
-- print"delete tapp a"
idtap.a = nil
abtap.a = nil
cdtap.c = nil
elseif idtap.b==t.id then
-- print"dellete tap b"
idtap.b = nil
abtap.b = nil
cdtap.d = nil
end
end
end