RotoSprite um einen Pin-Punkt auf dem Sprite

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

Schranz0r

coole sache das!

Hast du noch zufällig das "Rotation Polyvector"-Teil da, das du mir mal geschickt hast ?(Die Funktion)
I <3 DGArray's :D

PC:
AMD Ryzen 7 3800X 16@4.5GHz, 16GB Corsair Vengeance LPX DDR4-3200 RAM, ASUS Dual GeForce RTX™ 3060 OC Edition 12GB GDDR6, Windows 11 Pro 64Bit, MSi Tomahawk B350 Mainboard

Kitty Hello

Auszug aus einer Funktion in meinem "KidsFlash" Editor...
Code (glbasic) Select
GETSPRITESIZE sprid, spx, spy
scale = rpix / (SQR(spx*spx+spy*spy)/2) * .5
dx=spx*scale
dy=spy*scale

IF obj.hide
sprid = 1102 // ghost
GETSPRITESIZE sprid, spx, spy
ENDIF

IF obj.flip=0
spx0 = spx
spx=0
ELSE
spx0=0
ENDIF

STARTPOLY sprid
POLYVECTOR x+ cphi*dx-sphi*dy, y+cphi*dy+sphi*dx, spx,0,c
POLYVECTOR x+ cphi*dx+sphi*dy, y-cphi*dy+sphi*dx, spx,spy,c
POLYVECTOR x- cphi*dx+sphi*dy, y-cphi*dy-sphi*dx, spx0,spy,c
POLYVECTOR x- cphi*dx-sphi*dy, y+cphi*dy-sphi*dx, spx0,0,c
ENDPOLY

Schranz0r

I <3 DGArray's :D

PC:
AMD Ryzen 7 3800X 16@4.5GHz, 16GB Corsair Vengeance LPX DDR4-3200 RAM, ASUS Dual GeForce RTX™ 3060 OC Edition 12GB GDDR6, Windows 11 Pro 64Bit, MSi Tomahawk B350 Mainboard

Schranz0r

I <3 DGArray's :D

PC:
AMD Ryzen 7 3800X 16@4.5GHz, 16GB Corsair Vengeance LPX DDR4-3200 RAM, ASUS Dual GeForce RTX™ 3060 OC Edition 12GB GDDR6, Windows 11 Pro 64Bit, MSi Tomahawk B350 Mainboard

Schranz0r

I <3 DGArray's :D

PC:
AMD Ryzen 7 3800X 16@4.5GHz, 16GB Corsair Vengeance LPX DDR4-3200 RAM, ASUS Dual GeForce RTX™ 3060 OC Edition 12GB GDDR6, Windows 11 Pro 64Bit, MSi Tomahawk B350 Mainboard

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
    RotoZoomPivot(0, mx, 200, 9,25, phi, my/100)
    DRAWRECT mx-1,200-1, 2,2, RGB(0,255,0)
    SHOWSCREEN
WEND


//! RotoZoomPivot
// \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
// \param scale- scale factor for rotated sprite
FUNCTION RotoZoomPivot: id, x,y, px, py, phi, scale
LOCAL sx, sy, rx,ry
LOCAL cosp, sinp
    cosp=COS(phi)*scale
    sinp=SIN(phi)*scale
   
   
    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
    ROTOZOOMSPRITE id, x-rx, y-ry, phi, scale
ENDFUNCTION

Kitty Hello


Schranz0r

Einen RotoZoom auf den Mittelpunkt bezogen...

Müsste aber doch jetzt mit deiner Funktion auch gehn ^^

Muss ja nurnoch GETSPRITESIZE und damit dann die px und py füttern


EDIT: Ne ist ja kein Polyvector dabei -.-

Wollte es ja per Poly haben ...

Wollte nochmal ne bessere ParticleEngine machen in nächster Zeit
I <3 DGArray's :D

PC:
AMD Ryzen 7 3800X 16@4.5GHz, 16GB Corsair Vengeance LPX DDR4-3200 RAM, ASUS Dual GeForce RTX™ 3060 OC Edition 12GB GDDR6, Windows 11 Pro 64Bit, MSi Tomahawk B350 Mainboard

Kitty Hello

aso. Rotozoom ist aber schneller als polyvector.
auf die Mitte:

getspritesize id, sx, sy
rotozoomsprite id, x-sx/2, y-sy/2, phi, scale

Schranz0r

Na brauch das doch für Particle um sie Farbig zu machen :/
I <3 DGArray's :D

PC:
AMD Ryzen 7 3800X 16@4.5GHz, 16GB Corsair Vengeance LPX DDR4-3200 RAM, ASUS Dual GeForce RTX™ 3060 OC Edition 12GB GDDR6, Windows 11 Pro 64Bit, MSi Tomahawk B350 Mainboard

Kitty Hello

Code (glbasic) Select
FUNCTION RotoZoom: sprid, x,y, phi, scale
LOCAL sphi, cphi, sp, spy, dx, dy
LOCAL c=RGB(255,255,255)
sphi=SIN(phi)
cphi=COS(phi)
GETSPRITESIZE sprid, spx, spy
dx=spx*scale
dy=spy*scale


// make it act like ROTOZOOMSPRITE
// if you remove this line, x+y are
// the center of the rotation
INC x, spx/2; INC y, spy/2

STARTPOLY sprid
POLYVECTOR x- cphi*dx-sphi*dy, y-cphi*dy+sphi*dx, 0,0,c
POLYVECTOR x- cphi*dx+sphi*dy, y+cphi*dy+sphi*dx, 0,spy,c
POLYVECTOR x+ cphi*dx+sphi*dy, y+cphi*dy-sphi*dx, spx,spy,c
POLYVECTOR x+ cphi*dx-sphi*dy, y-cphi*dy-sphi*dx, spx,0,c
ENDPOLY
ENDFUNCTION
Biddaschööön :D

Schranz0r

I <3 DGArray's :D

PC:
AMD Ryzen 7 3800X 16@4.5GHz, 16GB Corsair Vengeance LPX DDR4-3200 RAM, ASUS Dual GeForce RTX™ 3060 OC Edition 12GB GDDR6, Windows 11 Pro 64Bit, MSi Tomahawk B350 Mainboard

AndyH

Oooo....thanks Gernot.

That was the last function I had to write for my BMax wrapper (ie: the colour part for the POLYVECTOR) so you've saved me a headache - and it works a treat. :)

I now can do:


spr3 = oLoadAnim("ovine.png", 32,32, 10, FALSE)
oSetHandle (spr3, 16,28 )
oSetColor ( RGB(255,0,255) )
oSetScale (1.5)
oSetRotation (45)
oDrawSprite ( spr3, 17, 120, 0 )
oSetRotation (90)
oDrawSprite ( spr3, 40, 120, 0 )
oSetColor ( RGB(255,255,255))

My draw sprite routine will pick the quickest method for drawing the sprite based upon the current scale, rotation and color values.  More important for the PPC and GP2X.

Schranz0r

A BMax Wrapper?
Some examples ?
I <3 DGArray's :D

PC:
AMD Ryzen 7 3800X 16@4.5GHz, 16GB Corsair Vengeance LPX DDR4-3200 RAM, ASUS Dual GeForce RTX™ 3060 OC Edition 12GB GDDR6, Windows 11 Pro 64Bit, MSi Tomahawk B350 Mainboard