title: Rotate object related to center
body: <p>Here's the thing, I have a cannon in my game that I want to be able to turn using my finger. I want the tip to always point in the opposite direction of where the finger is dragging off to, i.e. the tip should be pointing to the upper right if the finger is dragged to the lower left.</p>
  
  <p>I just cant figure out how to get this to work. I've managed to get it to rotate using the following code:</p>
  
  <pre><code>local function rotateObj(event)
      local t = event.target
      local phase = event.phase
  
      if (phase == "began") then
          display.getCurrentStage():setFocus( t )
          t.isFocus = true
  
          -- Store initial position of finger
          t.x1 = event.x
          t.y1 = event.y
  
      elseif t.isFocus then
          if (phase == "moved") then
              t.x2 = event.x
              t.y2 = event.y
  
              angle1 = 180/math.pi * math.atan2(t.y1 - t.y , t.x1 - t.x)
              angle2 = 180/math.pi * math.atan2(t.y2 - t.y , t.x2 - t.x)
              print("angle1 = "..angle1)
              rotationAmt = angle1 - angle2
  
              --rotate it
              t.rotation = t.rotation - rotationAmt
              print ("t.rotation = "..t.rotation)
  
              t.x1 = t.x2
              t.y1 = t.y2
  
          elseif (phase == "ended") then
  
              display.getCurrentStage():setFocus( nil )
              t.isFocus = false
          end
      end
  
      -- Stop further propagation of touch event
      return true
  end
  cannon:addEventListener("touch", rotateObj)
  </code></pre>
  
  <p>While this does allow me to rotate my cannon, it doesnt keep the tip relational to where I'm dragging. I have no idea where to even go from here.</p>