Author Topic: Pinch, multi-pointers, for android. 2D + 3D.  (Read 1150 times)

Offline sf-in-sf

  • Mr. Drawsprite
  • **
  • Posts: 92
  • Artist F.P. Brixey
    • View Profile
    • My computed art project
This example shows zooming in 2D with 2 fingers on android. Gernot's example must be changed for android: I get 16 detected mice permanently, but never more than 4 pointers. "Pinch" is about looking at fingers behaviour, and can control the 3D camera as well. Pointers location and number are shown on screen. Works on Archos tablet 10.1 G9. Have fun and tell us your story.
Code: GLBasic [Select]
// --------------------------------- //
// Project: pinch00
// Start: Tuesday, April 15, 2014
// IDE Version: 10.283
// SETCURRENTDIR("Media") // go to media files

SYSTEMPOINTER TRUE
CONSTANT rectNb%=33 // up to you
GLOBAL scrx%,scry%, zoom=1.0, cx,cy
GLOBAL sqx[],sqy[],sqw[],sqh[],sqcol%[]
GLOBAL mx%, my%,b1%,b2%
DIM sqx[rectNb+1] ; DIM sqy[rectNb+1] ; DIM sqw[rectNb+1] ; DIM sqh[rectNb+1] ; DIM sqcol[rectNb+1]
        FOR i% =0 TO rectNb
                sqx[i]=RND(900)*0.001 ; sqy[i]=RND(900)*0.001
                sqw[i]=0.05 +0.001*RND(155) ; sqh[i]=0.05 +0.001*RND(155)
                sqcol[i]=RGB(255/(1+RND(4)),255/(1+RND(4)),255/(1+RND(4)))
        NEXT

GETSCREENSIZE scrx,scry ; cx=scrx*0.5 ; cy=scry*0.5

//********************
WHILE TRUE
        GOSUB redraw
        ?IFDEF WIN32
                GOSUB kees //windows only. No double glazing.
        ?ENDIF
        GOSUB mousedetect
        SHOWSCREEN
WEND
//********************

END

SUB redraw:
FOR i%=0 TO rectNb
        DRAWRECT scrx*(0.5+(sqx[i]-0.5)*zoom),scry*(0.5+(sqy[i]-0.5)*zoom), _
        scrx*zoom*sqw[i], scry*zoom*sqh[i],sqcol[i]
NEXT
ENDSUB

?IFDEF WIN32
SUB kees:
STATIC k$
        k$=INKEY$()
        SELECT k$
                CASE "," // <<
                        zoom=zoom*0.99
                CASE "." // >>
                        zoom=zoom*1.01
        ENDSELECT
ENDSUB
?ENDIF

SUB mousedetect:
STATIC newmousecount%, zoomMem, mem //mouse distance
STATIC mouseAmount%
        newmousecount=GETMOUSECOUNT() ; mouseAmount=0
//draw pointers
        FOR i%=0 TO newmousecount-1
                //0->15 on android, all the time.
      SETACTIVEMOUSE i
      MOUSESTATE mx, my, b1, b2
      IF (b1+b2)
        drawmouse(i) ; INC mouseAmount
      ENDIF
      PRINT newmousecount, 10,200
      // always =16 on android, Archos tablet G9 10.1
        NEXT
//fingers' gym (best with 2 fingers...)
        SELECT mouseAmount //how many fingers on screen?
                //CASE 1 // glide
                //     
                CASE 2 //zoom. Implement rotation here.
                // could change camera position and FOV in 3D.
       
                        IF mem=0.0 //fresh fingers
                                mem=getdistance()
                                zoomMem=zoom //store the start values.
                        ELSE // pinch that spot, enjoy the magic
                                zoom=zoomMem*getdistance()/mem
                        ENDIF
                //CASE 3 //special config. Usable.
                //CASE 4 //Usable too. Wave a white flag.
                DEFAULT
                        mem=0.0 // fingers off
        ENDSELECT
ENDSUB

FUNCTION drawmouse: n%
STATIC p%
        FOR i%=0 TO n
                p=55+i+i+i
                DRAWLINE mx-p,my-p,mx+p, my-p, 0xffff00
                DRAWLINE mx-p,my+p,mx+p, my+p, 0xff99ff
                DRAWLINE mx-p,my-p,mx-p, my+p, 0xff99ff
                DRAWLINE mx+p,my-p,mx+p, my+p, 0xffff00
        NEXT
ENDFUNCTION

FUNCTION getdistance:
STATIC mx1%,mx2%,my1%,my2%,bb%,bbb%,d
        SETACTIVEMOUSE 0
        MOUSESTATE mx1,my1,bb,bbb
        SETACTIVEMOUSE 1
        MOUSESTATE mx2,my2,bb,bbb
        d=SQR((mx1-mx2)*(mx1-mx2) +(my1-my2)*(my1-my2))
PRINT "                       ", 30,30
PRINT d,30,30
RETURN d
ENDFUNCTION
On the day the atom is a cube I will start believing in the square pixel.