Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

rotating sprites

Status
Not open for further replies.

shanley06

Programmer
Nov 26, 2002
101
0
0
US
i have a 32x32 sprite stored i stored in an array using GET and i was wondering how i could rotate the sprite around the center of itself and the PUT it on the screen
 
defint a-z 'must use this for this algorithm
'rot 90 degrees
'iref is the 1st index of the sprite
'sprData is your array the image is in

'this is info inside each sprite that tells
'qb the dimensions of the sprite
xi = sprData(iref) / 8
yi = sprData(iref + 1)

'this is the integers(or elements) per image
intperimg = (x1 * yi \ 2) + 2

'sets the default segment to that of the
'data array
DEF SEG = VARSEG(sprData(0))

'sets the byte counter up at the first pixel
i = iref * 2 + 4

'converts dimenstions to width and height
wid = xi - 1
hei = yi - 1

'sets rotation point
x0! = wid / 2
y0! = hei / 2

'create temp array
REDIM rotmap(hei, wid)

'do 90 degree rotation inside temp array
FOR y = 0 TO hei
FOR x = 0 TO wid
x2 = hei - y 'formula for 90 degree rotation
y2 = x 'formula for 90 degree rotation
rotmap(x2, y2) = PEEK(i + x + y * xi)
NEXT
NEXT

'swap dimension definition values
x = sprData(iref) / 8
y = sprData(iref + 1)
sprData(iref) = y * 8
sprData(iref+1) = x

'swap this subs version of the same values above
SWAP xi, yi

'export results to sprite array
FOR y = 0 TO wid
FOR x = 0 TO hei
POKE i + x + y * xi, rotmap(x, y)
NEXT
NEXT

for 180 rotation use
x2=wid-x
y2=hei-y

for 270 rotation of 180 use
x2=wid-y
y2=x

for other rotations, its a bit more complicated and a pain
here is the formula:

x = x * cos(angle!) - y * sin (angle!)
y = x * sin(angle!) + y * cos (angle!)

angle! must be in radians
 
thanks alot...i think i understand everything except for what the first index is...sorry but this is the first time ive wanted to do this so i have no clue what it is
 
no problem

remember, you can put more than one sprite in the same one-dimensional array, using a different iref value
iref stands for integer reference
 
one more thing, this only works with 8-bit sprites

such as in screen 13
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Sponsor

Back
Top