Advertisement
Guest User

MAIN

a guest
May 16th, 2012
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 10.79 KB | None | 0 0
  1. -- Use this function to perform your initial setup
  2. function setup()
  3.     displayMode(STANDARD)
  4.     oldangx=0 
  5.     oldangy=0
  6.  
  7.      watch ("angx")
  8.     watch ("angy")
  9.     availableTests = { Test2()}
  10.     currentTest = availableTests[1]
  11.  
  12.     iparameter("SceneSelect",1,#availableTests,1)
  13.     r=0
  14.     parameter("Size",50,500,150)
  15.     parameter("CamHeight", 0, 1000, 300)
  16.     parameter("Angle",-360, 360, 0)
  17.     parameter("FieldOfView", 10, 140, 45)
  18.     
  19.     camera(0,0,0)
  20.     the3DViewMatrix = viewMatrix()
  21.     watch("the3DViewMatrix")
  22.     --displayMode(FULLSCREEN_NO_BUTTONS)
  23.     print("This example tracks multiple touches and colors them based on their ID")
  24.     -- keep track of our touches in this table
  25.     touches = {}
  26.     dx= 0
  27.     dy=0
  28.     lx=-1
  29.     ly=-1
  30.     rx=-1
  31.     ry=-1
  32.     olx=-1
  33.     oly=-1
  34.     orx=-1
  35.     ory=-1
  36.     ran =0
  37.     ranl=0
  38.     ranr=0
  39.     ld =0
  40.     rd =0
  41.     angx =0
  42.     tlx=0
  43.     tlz=0
  44.     angy =0
  45.     le=0
  46.     re=0
  47.     rr=0
  48.     watch("WIDTH/10")
  49.     watch("oldangx")
  50.     watch("oldangy")
  51.     watch("angx")
  52.     watch("angy")
  53.     watch ("dx")
  54.     watch ("dy")
  55.     watch ("lx")
  56.     watch ("ly")
  57.     watch ("rx")
  58.     watch ("ry")
  59.     watch ("olx")
  60.     watch ("oly")
  61.     watch("rdx")
  62.     watch ("orx")
  63.     ry=0
  64.     watch ("ory")
  65.     watch("ran")
  66.     lo=0
  67.     watch ("tlx")
  68.     watch("tlz")
  69.     watch("oldrx")
  70.     watch("oldry")
  71.     oldrx=0
  72.     oldry=0
  73.     ro=0
  74.     dx=0
  75.     -- These watches are evaluated after draw() is finished
  76.     -- Thus the contents are not as interesting
  77.     watch("viewMatrix()")
  78.     watch("modelMatrix()")
  79.     watch("projectionMatrix()")
  80. end
  81. function touched(touch)
  82.     if touch.state == ENDED then
  83.         touches[touch.id] = nil
  84.     else
  85.         touches[touch.id] = touch
  86.     end
  87. end
  88.  
  89. -- This function gets called once every frame
  90. function draw()
  91.     -- Set the currentTest to the selected scene
  92.   --  boarder=nil
  93.     currentTest = availableTests[SceneSelect]
  94.     
  95.     -- First arg is FOV, second is aspect
  96.     perspective(FieldOfView, WIDTH/HEIGHT)
  97.  
  98.     -- Position the camera up and back, look at origin
  99.     camera(0,CamHeight,-300, 0,0,0, 0,1,0)
  100.     
  101.     -- Write this into a variable so we can watch() it
  102.     -- at this point in time
  103.     the3DViewMatrix = viewMatrix()
  104.     
  105.     -- This sets a dark background color 
  106.     background(40, 40, 50)
  107.  
  108.     -- Do your drawing here
  109.     currentTest:draw()    
  110.     
  111.     -- Restore orthographic projection
  112.     ortho()
  113.     
  114.     -- Restore the view matrix to the identity
  115.     viewMatrix(matrix())
  116.     
  117.     -- Draw a label at the top of the screen
  118.     fill(255)
  119.     font("MyriadPro-Bold")
  120.     fontSize(30)
  121.     
  122.     text(currentTest:name(), WIDTH/2, HEIGHT - 30)
  123.     --background(0, 0, 0, 255)
  124.  
  125.  
  126.     lx=-1
  127.     ly=-1
  128.     rx=-1
  129.     ry=-1
  130.     ran=0
  131.         ranl=0
  132.         ranr=0
  133.        rdx=0
  134.         
  135.             for k,touch in pairs(touches) do
  136.                 
  137.         ran =1
  138.         ldx =0 
  139.         ldy=0
  140.         rdx=0
  141.        -- print(rr)
  142.         rdy=0
  143.         -- Use the touch id as the random seed
  144.         math.randomseed(touch.id)
  145.         -- This ensures the same fill color is used for the same id
  146.         fill(255, 255, 255, 255)
  147.         if touch.state== ENDED then
  148.             oldangx=angx
  149.             oldangy=angy
  150.             if touch.prevx <0 then
  151.                 lx=-1
  152.                 ly=-1
  153.                 olx=-1
  154.                 oly=-1
  155.             else
  156.                 rx=-1
  157.                 ry=-1
  158.                 orx=-1
  159.                 ory=-1
  160.                 end
  161.         else
  162.             if touch.x < WIDTH/2 then
  163.  
  164.             ranl =1
  165.          
  166.             lx = touch.x
  167.             ly = touch.y
  168.             
  169.             if olx ==-1 then
  170.                 olx = lx
  171.                 oly = ly
  172.             end
  173.             if olx == lx or oly ==ly then
  174.                 ldx=0
  175.                 ldy=0
  176.                 else
  177.             ldx = touch.deltax
  178.             ldy = touch.deltay
  179.             end
  180.             else
  181.                 ranr=1
  182.             
  183.             rx = touch.x
  184.             ry = touch.y
  185.  
  186.             if orx ==-1 then
  187.                 print("down")
  188.                 rr=0
  189.                 orx = rx
  190.                 ory = ry
  191.                 else 
  192.                     rr=1
  193.             end
  194.             --print(touch.x-touch.prevX)
  195.            -- print(touch.deltaX)
  196.            -- print(touch.prevX)
  197.             if rr==1 then
  198.             if touch.prevX-touch.x==0 then
  199.                 print(rdx)
  200.                 rdx=0
  201.                 print(rdx)
  202.                 else
  203.                     print(touch.deltaX)
  204.                      rdx = touch.deltaX
  205.                     print(rdx)
  206.                     end
  207.             
  208.             
  209.                 print (touch.prevY)
  210.                         if touch.prevY-touch.y==0 then
  211.                 print(rdy)
  212.                 rdy=0
  213.                 print(rdy)
  214.                 else
  215.                     print(touch.deltaY)
  216.                      rdy = touch.deltaY
  217.                     print(rdy)
  218.                     end
  219.             else 
  220. r=1
  221.             end
  222.             if oldrx==rx then
  223.                 rdx=0
  224.             end
  225.             if oldry==ry then
  226.                 rdy=0
  227.             end
  228.  
  229.             if orx == rx  or ory == ry then
  230.                 rdx=0
  231.                 rdy=0
  232.                 else
  233.  
  234.             end
  235.                         oldrx=rx
  236.             oldry=ry
  237.             end
  238.         
  239.         -- Draw ellipse at touch position
  240.         end
  241.  
  242.        -- ellipse(touch.x, touch.y, 100, 100)
  243.         
  244.     end
  245.     if r==1 then
  246.         if rdx==0 and rdy==0 then
  247.             r=0
  248.         elseif rdx > 0 then
  249.         rdx = rdx - .5
  250.         elseif rdy>0 then
  251.         rdy=rdy-.5
  252.     end
  253.     
  254.     end
  255.     if ran==0 then
  256.         ldx=0
  257.         ldy=0
  258.         rdx=0
  259.         rdy=0
  260.         if ranl==0 then
  261.             olx=-1
  262.             oly=-1
  263.         end
  264.         if ranr==0 then
  265.             orx=-1
  266.             ory=-1
  267.         end
  268.     end
  269.         
  270.         if ranr==0 then 
  271.         --rr=0
  272.         else
  273.             --rr=1
  274.             end
  275.     le=1
  276.     re=1
  277.     if ran==0 then
  278.         ldx=0
  279.         ldy=0
  280.  
  281.         rdx=0
  282.         rdy=0
  283.         if ranl==0 then
  284.             
  285.             olx=-1
  286.             oly=-1
  287.         end
  288.         if ranr==0 then
  289.       --              oldangx =angx
  290.       --  oldangy =angy
  291.            orx=-1
  292.             ory=-1
  293.         end
  294.     
  295.     if ranl ==1 or ranr == 1 then
  296.         print("s")
  297.     end
  298.     
  299.  
  300.         if ranl==0 then
  301.             olx=-1
  302.             oly=-1
  303.         end
  304.         if ranr==0 then
  305.             orx=-1
  306.             ory=-1
  307.         end
  308.     
  309.     if ranr==0 then
  310.         ro=0
  311.     end
  312.         end
  313.     popStyle()
  314.         fill(255,255,255,255)
  315.     strokeWidth(15)
  316.     if le ==1 then
  317.     if olx==-1 then
  318.         else
  319.             if lx==-1 then
  320.                 olx=-1
  321.             else
  322.         line(olx,oly,lx,ly)
  323.         end
  324.         end
  325.     end
  326.     if re==1 then
  327.     if orx==-1 then
  328.         
  329.         else
  330.         if rx==-1 then
  331.             orx=-1
  332.         else
  333.             line(orx,ory,rx,ry)
  334.         end
  335.     end
  336.     
  337.       --  boarder = nil
  338.  
  339.     strokeWidth(0)
  340.     
  341.     if orx ==-1 then
  342.         rx=-1
  343.     else
  344.         ellipse(orx,ory,100,100)
  345.     end
  346.     end
  347.     if le==1 then
  348.     if olx ==-1 then
  349.         lx=-1
  350.         
  351.     else
  352.         ellipse(olx,oly,100,100)
  353.     end
  354.     end
  355.     if re==1 then
  356.         if orx ==-1 then
  357.             rx=-1
  358.             
  359.             
  360.     else
  361.         ellipse(rx,ry,50,50)
  362.     end
  363.     end
  364.     if le==1 then
  365.     if olx ==-1 then
  366.         lx=-1
  367.     else
  368.         ellipse(lx,ly,50,50)
  369.     end
  370.     end
  371.     pushStyle()
  372.  
  373.     if ranr == 1 then
  374.         if angx ==0 and angy ==0 then
  375.             if oldangx <= 0 then
  376.                 else
  377.                 angx = oldangx
  378.                 angy=oldangy
  379.                 end
  380.                    
  381.                          if oldangy <= 0 then
  382.                 else
  383.                 angx = oldangx
  384.                 angy=oldangy
  385.             end
  386.             
  387.         end
  388. --  if rr==1 then
  389.         angx =(angx+rdx/10)--(rx-orx)/10)
  390.         
  391.    
  392.         angy =(angy+rdy/10)--(ry-ory)/10)
  393.         oldangx=rdx
  394.       oldangx =  angx
  395.       oldangy = oldangy
  396.     else
  397.         --oldangx=angx
  398.        -- oldangy=angy
  399.     --end
  400.     end
  401.     
  402.     if ranl ==1 then 
  403.         dx = dx + lx-olx
  404.         dy = dy + ly-oly
  405.     end
  406.     translate(dy,dx,0)
  407.     print("aa")
  408. print(boarder)
  409.     if boarder == 1 then
  410.         
  411.         displayMode(FULLSCREEN_NO_BUTTONS)
  412.         end
  413.     if boarder ==2 then
  414.         displayMode(STANDARD)
  415.     end
  416.            if rx>WIDTH -WIDTH/15 then
  417.            boarder = 1
  418.         print("b")
  419.        end
  420.         print("a")
  421.         print(rx)
  422.       
  423.             if lx<WIDTH/15 then 
  424.                 if lx==-1 then
  425.                     else
  426.             boarder=2
  427.           end
  428.         end
  429.         if rr==1  then
  430.             rdx=rdx
  431.     print(rdx)
  432.     end
  433.     tlz = .2*(ly-oly) +tlz
  434.     tlx=tlx + .2*(lx-olx)
  435.     strokeWidth(5)
  436.     --line(WIDTH-WIDTH/10,0,WIDTH-WIDTH/10,HEIGHT)
  437. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement