Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Rotate point

edited October 2013 in Questions Posts: 577

Hi, whenever I try to do rotate(CurrentTouch.y / 2) it works fine, but when I do rotate(CurrentTouch.y, x, y)
it doesn't work. Any ideas?

function draw()


background(40,40,50)

noSmooth()

sprite("Custom", WIDTH / 2, HEIGHT /2, 44, 128)

pushMatrix()

translate(WIDTH/2, HEIGHT/2)

rotate(CurrentTouch.y / 2, WIDTH/2, HEIGHT/2)

sprite("Custom2", 0,0, 8, 36)

end

Comments

  • Posts: 2,042

    I believe that rotate() rotates around 0,0 and so to get it to rotate around a point you translate, which it appears you've done. I don't understand why you need the x,y in rotate?

  • Posts: 577

    Because rotate() can also have a custom place to rotate around, and Since "Custom2" is an arm, I want the shoulder to be the rotate point.

  • Posts: 2,042

    @Prynok, as far as I can tell if you use a rotate point you must include a z value, look at the documentation.

  • Posts: 577

    Tried, it still doesn't like me

  • edited October 2013 Posts: 355

    @Prynok .It's the same when you're doing an animation.
    Why?: in your example when translate then sprite, you are giving the position where the image will appear, then when u rotate , you are giving only the value of z, when you rotate an image, you cant not pass the values ​​of x, y, these will move when you touch the screen giving the target in the same sprite

    sprite("Custom2", WIDTH/2-300,HEIGHT/2-200, 8, 36)
    
    
    
    function setup()
          mensaje = {x=WIDTH/2,y=HEIGHT/2+700,z =100}
    end
    
    function draw()
          background(0,0,0,0)
          tween(1,mensaje,{x = WIDTH/2,y = HEIGHT/2+150, z = 100},
         {easing = tween.easing.backIn,
         loop = tween.loop.once})
        pushMatrix()
        translate(mensaje.x,mensaje.y)
        rotate(mensaje.z) 
        sprite("Cargo Bot:Codea Logo")
        popMatrix()
    
     end
    
  • Posts: 1,976

    @Prynok There is no easy way to do what you want. rotate() doesn't take three variables, it only takes one or four. If you use one, it's degrees for rotation in 2D. If you use four, the first variable is degrees, and the next three are x, y, and z. The last three are either 0 or 1. Four is used for 3D rotation.

  • edited October 2013 Posts: 2,042

    Couldnt you just translate to the correct point and then rotate around that?

  • Posts: 2,161

    @SkyTheCoder: "The last three are either 0 or 1." If you mean that literally then you're wrong. The last three inputs to the rotate function specify the axis to rotate about so can be anything, although 0,0,0 is a silly choice (not actually sure what it will do with that input).

    rotate(angle,x,y,z) rotates by angle about the axis (x,y,z). There's no function for "rotate about a point". What you have to do is what @JakAttak says: translate so that the point you want to rotate about is at the origin, do the rotation, and then translate back again.

    function draw()
        background(40,40,50)
        translate(WIDTH/2,HEIGHT/2)
        rotate(CurrentTouch.y)
        translate(-WIDTH/2,-HEIGHT/2)
        sprite("Cargo Bot:Codea Logo",WIDTH/2,300)
    end
    
  • Posts: 1,976

    @Andrew_Stacey Odd, whenever I used the x, y, z in rotate other than 0 or 1, I think either nothing happened or Codea crashed, not sure which.

  • Posts: 2,161

    @SkyTheCoder It's a 3D thing so if you don't have the matrices set up correctly then it's easy to rotate your stuff off the screen (remember that things get clipped if they are too close or too far away as well).

Sign In or Register to comment.