Author Topic: RotoSprite around a pivot point  (Read 2380 times)

Offline Kitty Hello

  • code monkey
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 10739
  • here on my island the sea says 'hello'
    • View Profile
    • http://www.glbasic.com
RotoSprite around a pivot point
« on: 2008-Jan-22 »
Code: (glbasic) [Select]
DRAWRECT 0,0,64,32,RGB(255,255,0)
DRAWRECT 7,23,4,4,RGB(255,0,0)

GRABSPRITE 0, 0,0,64,32



WHILE TRUE
MOUSESTATE mx,my,b1,b2
INC phi, 1
RotoPivot(0, mx, my, 9,25, phi)
DRAWRECT mx-1,my-1, 2,2, RGB(0,255,0)
SHOWSCREEN
WEND


//! RotoPivot
// \param id - Sprite ID
// \param x,y  - x,y position of pivor point to draw on screen
// \param px,py- x,y position of pivot point on sprite (0,0=topleft corner)
// \param phi  - rotation angle as in ROTOSPRITE
FUNCTION RotoPivot: id, x,y, px, py, phi
LOCAL sx, sy, rx,ry
LOCAL cosp, sinp
cosp=COS(phi)
sinp=SIN(phi)


GETSPRITESIZE id, sx, sy

sx=sx/2
sy=sy/2

// reverse rotate pivot point arount center
// of sprite
DEC px, sx
DEC py, sy
rx = px*cosp + py*sinp
ry = py*cosp - px*sinp

// adjust center
INC rx,sx
INC ry,sy
// perform drawing
ROTOSPRITE id, x-rx, y-ry, phi
ENDFUNCTION


Keywords: hotspot,rotation,center point
« Last Edit: 2010-May-20 by Kitty Hello »