Rotate Objetects With Finger

Hi
I have found it in share codes:
http://developer.anscamobile.com/code/rotate-object-finger
and it works fine, but how do I add a function to this clockwise or counter-clockwise

I want to up or down an object using this code in another circular object

someone knows how to do that?

thanks [import]uid: 23063 topic_id: 16223 reply_id: 316223[/import]

anyone? [import]uid: 23063 topic_id: 16223 reply_id: 60752[/import]

Using one finger or two?

Personally, if I were to write this code (something I don’t have time to do right now) I would:

Record the location of the initial touch
Track the position of the moving touch
When the moving touch goes beyond a threshold distance from the original touch…
Calculate the angle between the two and set the .rotation value of the object you want to rotate.

It should then rotate in line with your finger, regardless of how far from the original touch it is.

The maths are around this site, often in sample code or code exchange, so I’ll leave that investigation for you…

Matt [import]uid: 8271 topic_id: 16223 reply_id: 60857[/import]

you don’t understand, the code to rotate objects with finger is done. What I need is to apply this rotate to do another function

when I rotate objectA ( with the code that already done ), it will move up or down objectB

move up if I’m doing counterclockwise and down if i’m doing clockwise

get it? :S
thanks [import]uid: 23063 topic_id: 16223 reply_id: 60864[/import]

So, you have a function which fires when the touch moves and you’re wondering where to put the code to move the second object? In that function? No? If you’re wondering how to move the second object relative to the amount of rotation, just take the rotation value and change the .y property of the second object to the amount being added or subtracted to/from the first object’s .rotation value.

If I’m still incorrect, please post some code to explain your situation. Perhaps, if it’s not too long, someone can fix it for you… [import]uid: 8271 topic_id: 16223 reply_id: 60875[/import]

yea, it that but I don’t know what I need to put in code to do this

there’s the code:

[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

– HERE SHOULD GO THE CODE TO MOVE THE OBJECTB BUT I DON’T KNOW WHAT TO PUT HERE

elseif (phase == “ended”) then

display.getCurrentStage():setFocus( nil )
t.isFocus = false
end
end

– Stop further propagation of touch event
return true
end
yourObject:addEventListener(“touch”, rotateObj)
[/code] [import]uid: 23063 topic_id: 16223 reply_id: 60898[/import]

In the ‘began’ phase store the rotation of the t object.

In the ‘moved’ phase subtract the stored rotation from the new rotation of t. Call this value r.

Next, also in the ‘moved’ phase, add the value r to the .y property of the object to moved moved. [import]uid: 8271 topic_id: 16223 reply_id: 60904[/import]

I’m realy confused
can you show me how to do that in code? [import]uid: 23063 topic_id: 16223 reply_id: 60917[/import]

You’re almost doing it already.

I don’t know what the other object is called, so I refer to it as ‘secondObject’. Put your variable name in. The changes I’ve made are (not counting comments) only 3 lines…

[lua]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

– store initial rotation of t
t.startRotation = t.rotation

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

– HERE SHOULD GO THE CODE TO MOVE THE OBJECTB BUT I DON’T KNOW WHAT TO PUT HERE

– get difference between initial rotation and current rotation
local diffRot = t.rotation - t.startRotation

– set second object’s vertical position
secondObject.y = secondObject.y + diffRot

elseif (phase == “ended”) then

display.getCurrentStage():setFocus( nil )
t.isFocus = false
end
end

– Stop further propagation of touch event
return true
end
yourObject:addEventListener(“touch”, rotateObj)[/lua]
[import]uid: 8271 topic_id: 16223 reply_id: 60925[/import]

it moves the secoundObject but… did’nt work because the motion is clockwise and counter-clockwise, so checking if rotation is + or - don’t will work =T [import]uid: 23063 topic_id: 16223 reply_id: 60928[/import]