RotoSprite around a pivot point

Previous topic - Next topic

Kitty Hello

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