rotating by multitouch

HunnenkoenigHunnenkoenig Member Posts: 1,173
edited November -1 in Working with GS (Mac)
I believe, Tshirt or Firemapple linked somewhere a demo with something like that, but I can't find it.

I want to rotate an image by multitouch, but I can't figure out, how to do it the best way.

If I use angletovector and change the rotate attribute by this number, it works somehow, but it is not good.

Any advice?

Comments

  • JackBQuickJackBQuick Member Posts: 524
    Was this what you were thinking of:

    http://gamesalad.com/forums/topic.php?id=502

    CodeMonkey has a demo here:

    http://gamesalad.com/game/play/22929
  • JackBQuickJackBQuick Member Posts: 524
    Was this what you were thinking of:

    http://gamesalad.com/forums/topic.php?id=502
  • netdzynrnetdzynr Member Posts: 296
    HK, I'm trying to do this as well. Did you ever figure it out or find a demo? I have some code from another development environment that relies on atan2, so it won't work in GS. It does seem like vectorToAngle is the right direction.

    And while we're at it, where is the origin in GS? The center of the display, or one of the corners? The Expression Editor Reference says vectorToAngle uses the "origin" but doesn't clarify where exactly the origin is.
  • firemaplegamesfiremaplegames Member Posts: 3,211
    @netdzynr: VectorToAngle is the same as atan2, it actually goes one step further and gives you the angle in degrees, since GS doesn't use radians. I converted a bunch of my Flash stuff over to GS by replacing the Flash atan2 functions with VectorToAngle.

    The origin is in the lower left corner of the screen, or "camera". If the camera moves, an Actor instance, (like the Scene controller you just made) has access to Camera.Origin.X and Camera.Origin.Y

    @Hunn: yes, you will need VectorToAngle to give you the angle between the two touches. When you first touch the actor, capture those touches' angle by using VectorToAngle. That will be the starting point, or zero point. Then, constrain the rotation of the actor based on the difference between the current vectorToAngle minus the Original VectorToAngle.

    So:

    Change Attribute: originalTouchAngle To: vectorToAngle(touch1.X-touch2.X,touch1.Y-touch2.Y)
    Constrain Attribute. self.rotation to vectorToAngle(touch1.X-touch2.X,touch1.Y-touch2.Y)-originalTouchAngle

    That's just off the top of my head, so it probably won't work!
    But I think that's sort of the basic idea...
  • HunnenkoenigHunnenkoenig Member Posts: 1,173
    Thank you guys.

    I gave up on it and I made just a switcher, where if it is on, a touch will just rotate the actor counter clockwise.

    Maybe later I will mess around with this again.
  • design219design219 Member Posts: 2,273
    "
    make 2 attributes
    game.touchy
    game.releasey
    "

    You enjoy naming attributes, don't you!
  • aalzankiaalzanki Member Posts: 283
    Create two integer game attributes spinX and spinY

    Create an invisible actor with rule:

    when touch is pressed
    constrain self.positionY to touchY
    constrain self.positionX to touchX

    constrain game.spinY to self.positionY
    constrain game.spinX to self.positionX

    In the spinning objecting:

    When touch is pressed and inside
    constrain self.rotation to VectorToAngle(self.positionX-game.spinX, self.position.Y-game.spinY)

    Use this example.
  • netdzynrnetdzynr Member Posts: 296
    Thanks bojamal -- I've got a variation of what you posted working. Now I'm wondering, is there a way to calculate what I'm guessing is an offset between the current rotation of the actor and the touch/mouse position so that actor doesn't rotate until the touch/mouse position is changed?

    To explain another way: using the above, the actor when clicked "jumps" (rotates) to the current touch position. I'm trying to find a way to take into account the actors current rotation so it doesn't jump to a new rotation upon the initial touch/click.

    I tried storing the current rotation in an attribute and using abs(current angle - new angle) and abs(new angle - current angle) but failed miserably -- I'm doing something wrong and am not sure how to account for the 359.99 limit on rotation.

    Thanks for any suggestions you can offer.
  • HunnenkoenigHunnenkoenig Member Posts: 1,173
    I gave up exactly on this.

    When I tried to store the angle, so it doesn't jumb back to your touch.

    If you get it work, please post a demo :-)
  • netdzynrnetdzynr Member Posts: 296
    OK, this seems to work:

    On the initial click/touch, don't rotate the actor, store the offset of the vectorToAngle() of the click minus the current Rotation of the actor in an attribute (I used rotationOffset).

    Pseudo-code:

    RULE
    if allowRotation = true

    CHANGE ATTRIBUTE
    (self.rotationOffset = vectorToAngle(actor.position.X-game.Mouse.Position.x,actor.Position.Y-game.Position.Y))-actor.Rotation

    [ Then in the same rule, constrain the rotation of the actor to the current vectorToAngle() minus the rotationOffset ]

    CONSTRAIN ATTRIBUTE
    actor.Rotation to vectorToAngle(actor.position.X-game.Mouse.Position.x,actor.Position.Y-game.Position.Y))-self.rotationOffset

    Over here, this allows rotation of an actor using its current rotation, so there's no initial "jump" when clicking. Need to try this on an actual device, but it works fine in Creator.
Sign In or Register to comment.