Hi
Thank you for your answer
Quote: "Can you explain or show how it is not working?"
in the first code, we can zoom in or out but not as we want. The zoom don't stop even if we don't move our fingers, and it's impossible to zoom like we want (zoom in or out, it's a kind of random ^^)..
Another test, which seems to work better : (I have found this code on the agk example commands, and change it to work with 3D),
- we can zoom in/out and only with two fingers
- if we zoom in, the camera zoom in
- if we zoom out, the camera zoom out
But I have two bugs to fixes (I don't know how for the moment) :
- sometimes, the view is "duplicated" (a little "shaked" )
- I would like to knwo how to not change the position of the box "N1" (the camera has the same position) when I begin to do a multitouch, because each time we start to change the zoom (with the distance of two finders different), the camera keep not its precedent place but is placed immediatly at the place of the zoom factor.
// Project: zoom3d
// Created: 2023-04-10
CreateObjectBox(1,5,5,5)
SetObjectColor(1,250,100,100,255)
SetObjectcastShadow(1,1)
setobjectposition(1,0,5,0)
Global n1, cameraz
global z as float
N1=3
CreateObjectBox(3,5,5,5)
SetObjectColor(3,250,250,100,255)
setobjectposition(3,0,20,-20)
SetObjectVisible(3,0)
FixObjectToObject(3,1)
CreateObjectPlane(2,100,100)
SetObjectRotation(2,90,0,0)
SetObjectColor(2, 10, 150,100, 255)
SetObjectReceiveShadow(2,1)
SetCameraPosition(1,0,20,-20)
SetCameraLookAt(1,0,0,0,0)
SetSunActive(1)
setsundirection(-0.3,-0.7,0.5)
SetShadowBias(0.005)
SetShadowMapSize(1024,1024)
SetShadowSmoothing(2)
SetShadowMappingMode(3)
SetShadowRange(-1)
start =0
// our main loop
do
print(ScreenFPS())
// update the loaded scene
if GetRawKeyReleased(27)
end
endif
/*
//multitouch
i = getRawFirstTouchEvent(1)
while i>0
ID = i
sx = getRawTouchStartX(i)
sy = getRawTouchStartY(i)
cx = getRawTouchCurrentX(i)
cy = getRawTouchCurrentY(i)
released = getRawTouchReleased(i)
i = getRawNextTouchEvent()
if start<1
inc start
if start =1
olddistance = (sx-cx)*(sx-cx)+(sy-cy)*(sy-cy)
endif
endif
distance = (sx-cx)*(sx-cx)+(sy-cy)*(sy-cy) -olddistance
distance2 =sqrt( (sx-cx)*(sx-cx)+(sy-cy)*(sy-cy)) // + cameraz+olddistance
if (distance2*0.2 >cameraz and cameraz<60) or (cameraz=60 and distance2*0.2<cameraz)
cameraz =distance2*0.2
endif
if cameraz < 20
cameraz = 20
elseif cameraz >60
cameraz = 60
else
SetObjectPosition(n1, 0,20,-20)
SetObjectLookAt(n1, 0,0,0,0)
MoveObjectLocalZ(n1, -cameraz)
setcameraposition(1, GetCameraX(1),getobjecty(n1),GetObjectZ(n1))
//setcameraposition(1, GetCameraX(1),getobjecty(n1)+cameraz*0.5,GetObjectZ(n1)-cameraz)
SetCameraLookAt(1,0,0,0,0)
endif
// olddistance =sqrt( (sx-cx)*(sx-cx)+(sy-cy)*(sy-cy) )
endwhile
olddistance =sqrt( (sx-cx)*(sx-cx)+(sy-cy)*(sy-cy) )
print(str(sx)+"/"+str(cx)+"/"+str(sy)+"/"+str(cy))
print(str(distance2)+"/"+str(cameraz))
//print(str(distance1)+"/"+str(distance3))
*/
Zoomtouch()
// update the screen
sync()
loop
function ZoomTouch()
if GetMultiTouchExists() =1
if GetRawTouchCount(1)=1
elseif GetRawTouchCount(1)=2 //two Fingers
t=GetRawFirstTouchEvent(1)
k=t
sx1#=GetRawTouchStartX(t)
sy1#=GetRawTouchStarty(t)
x1#=GetRawTouchCurrentX(t)
y1#=GetRawTouchCurrenty(t)
t=GetRawNextTouchEvent()
sx2#=GetRawTouchStartX(t)
sy2#=GetRawTouchStarty(t)
x2#=GetRawTouchCurrentX(t)
y2#=GetRawTouchCurrenty(t)
//drawline(sx1#,sy1#,sx2#,sy2#,255,255,255)
drawline(x1#,y1#,x2#,y2#,0,255,0)
dx#=sx2#-sx1#
dy#=sy2#-sy1#
l1#=sqrt(dx#*dx# + dy#*dy#) //distance start 1 - start 2
dx#=x2#-x1#
dy#=y2#-y1#
l2#=sqrt(dx#*dx# + dy#*dy#) //distance current 1 - current 2
if k
cameraz =GetObjectZ(n1)
SetObjectPosition(n1, 0,20,-20)
SetObjectLookAt(n1, 0,0,0,0)
MoveObjectLocalZ(n1, -cameraz)
//~ dec l1#, z
//~ dec l2#, z
endif
if l1# <> l2#
if l1#>0
l#=(1.0 / l1#) * l2#
l#=l#-1.0
// l#=l#/3.0 //slower
// z#=getviewzoom()+l#
Z =getobjectz(N1)+l2#*0.2
z=l2#
if z<10.0 then z=10.0 //Limit
if z>95 then z=95 //Limit
//setviewzoom(z#)
Moveobjectlocalz(N1, -z)
setcameraposition(1, GetCameraX(1),getobjecty(n1),GetObjectZ(n1))
print(str(l1#)+"/"+str(l#)+"/"+str(l2#))
print("cameraZ : "+str(z))
endif
endif
endif
endif
endfunction
AGK2 tier1 - http://www.dracaena-studio.com