## 2d rotate

## 2d rotate

(OP)

is there any source to rotate a 32 x 32 sprite clockwise or

any..?

if we basically dim an array ;

dim sprite(31,31)

for y=0 to 31

for x=0 to 31

pset (ox+x,oy+y),sprite(x,y)

next

next

Can we rotate it ?

there is a way i think ;

if every pixeldata stores its' color and radious and angle.. then we can rotate it..

Where ox,oy is the center of object (not the upper left corner) one pixel needs 3 integers to be drawen..

But at 67 degrees with 1.447 radius would not give the original sprite on 320 x 200 x 8 screen....(for example)

Here is an example code ;

-------Example Code For Try Of Rotating 2D Objects----------

nop=120 'number of pixels

ox=159

oy=99

an=(22/7)/180

dim sprite(nop,3)

for t=1 to nop

randomize timer

sprite (t,1)=int(rnd*16)'radius

sprite (t,2)=int(rnd*359)'degrees

sprite (t,3)=int(rnd*100)'color

next

screen 13

gosub drawit

routinne:

a$=inkey$

if a$=chr$(0)+chr$(72) gosub turnleft

if a$=chr$(0)+chr$(77) gosub turnright

'not sure about scancodes

if a$=chr$(27) then end

goto routinne

turnleft:

for t=1 to nop

sprite (t,2)=sprite(t,2)+5

if sprite (t,2)>360 then sprite(t,2)=sprite(t,2)-360

next

gosub drawit

return

turnright:

for t=1 to nop

sprite (t,2)=sprite(t,2)-5

if sprite (t,2)<0 then sprite(t,2)=sprite(t,2)+360

next

gosub drawit

return

drawit:

cls

for t=1 to nop

pset (ox+(sprite(t,1)*cos(sprite(t,2)*an),oy-(sprite(t,1)*sin(sprite(t,2)*an)),sprite(t,3)

next

return

----------------------program ends here------------------

Try it and modify it i do not know how the results seems but i know that ;

Where ox+(sprite(t,1)*cos(sprite(t,2)*an)) = 123.22

it will draw it to 123.. By the way the original sprite wont be there or it will please try and help !!!!!!

Shakespare says "To be or not to be" and we say "I/0"

any..?

if we basically dim an array ;

dim sprite(31,31)

for y=0 to 31

for x=0 to 31

pset (ox+x,oy+y),sprite(x,y)

next

next

Can we rotate it ?

there is a way i think ;

if every pixeldata stores its' color and radious and angle.. then we can rotate it..

Where ox,oy is the center of object (not the upper left corner) one pixel needs 3 integers to be drawen..

But at 67 degrees with 1.447 radius would not give the original sprite on 320 x 200 x 8 screen....(for example)

Here is an example code ;

-------Example Code For Try Of Rotating 2D Objects----------

nop=120 'number of pixels

ox=159

oy=99

an=(22/7)/180

dim sprite(nop,3)

for t=1 to nop

randomize timer

sprite (t,1)=int(rnd*16)'radius

sprite (t,2)=int(rnd*359)'degrees

sprite (t,3)=int(rnd*100)'color

next

screen 13

gosub drawit

routinne:

a$=inkey$

if a$=chr$(0)+chr$(72) gosub turnleft

if a$=chr$(0)+chr$(77) gosub turnright

'not sure about scancodes

if a$=chr$(27) then end

goto routinne

turnleft:

for t=1 to nop

sprite (t,2)=sprite(t,2)+5

if sprite (t,2)>360 then sprite(t,2)=sprite(t,2)-360

next

gosub drawit

return

turnright:

for t=1 to nop

sprite (t,2)=sprite(t,2)-5

if sprite (t,2)<0 then sprite(t,2)=sprite(t,2)+360

next

gosub drawit

return

drawit:

cls

for t=1 to nop

pset (ox+(sprite(t,1)*cos(sprite(t,2)*an),oy-(sprite(t,1)*sin(sprite(t,2)*an)),sprite(t,3)

next

return

----------------------program ends here------------------

Try it and modify it i do not know how the results seems but i know that ;

Where ox+(sprite(t,1)*cos(sprite(t,2)*an)) = 123.22

it will draw it to 123.. By the way the original sprite wont be there or it will please try and help !!!!!!

Shakespare says "To be or not to be" and we say "I/0"

## RE: 2d rotate

DIM sprite(31,31)

centrex = ox + 16

centrey = oy + 16

FOR x = -15 to 16

FOR y = -15 to 16

xx = COS(angl) * x

yy = SIN(angl) * y

PSET (centrex + xx,centrey + yy), sprite(x+15,y+15)

NEXT

NEXT

It should rotate the sprite around its centre.

## RE: 2d rotate

heh... saw your sig. here's a better version of it.

qb or not qb... that is the question.

/offtopic

## RE: 2d rotate

here is the code for qb 2d rotate my own;

SCREEN 12

DIM MATRIX(8,8)

CONTROL=0

LOCATE 12,12

PRINT INPUT "A LETTER TO ROTATE"

WHILE CONTROL=0

A$=INKEY$

Z=ASC(A$)

IF Z>32 AND Z<123 THEN CONTROL=1

WEND

COLOR 255

CONST PI = (22/7)/180

OX=319

OY=239

CLS

PRINT A$

FOR X=0 TO 7

FOR Y=0 TO 7

A=POINT(X,Y)

MATRIX(X+1,Y+1)=A

NEXT

NEXT

ANGLE=0

SPEED=5

GOSUB DRAWER

ROUTINNE:

A$=INKEY$

IF A$=CHR$(0)+CHR$(75) THEN GOSUB LEFT

IF A$=CHR$(0)+CHR$(77) THEN GOSUB RIGHT

IF A$=CHR$(27) THEN END

GOTO ROUTINNE

LEFT:

ANGLE=ANGLE-5

IF ANGLE<0 THEN ANGLE=ANGLE+360

GOSUB DRAWER

RETURN

RIGHT:

ANGLE=ANGLE+5

IF ANGLE>360 THEN ANGLE=ANGLE-360

GOSUB DRAWER

RETURN

DRAWER:

XMOMENT=4

YMOMENT=4 'NEARLY ROTATE BY CENTER

FOR X=0 TO 7

FOR Y=0 TO 7

Q=MATRIX(X+1,Y+1)

IF Q<>0 THEN

DISTANCE=SQR((X-XMOMENT)^2+(Y-YMOMENT)^2)

IF Y-YMOMENT <> 0 THEN

SINE = (Y-YMOMENT)/DISTANCE

ELSE

SINE=0

END IF

IF X-XMOMENT <> 0 THEN

COSINE = (X-XMOMENT)/DISTANCE

ELSE

COSINE=0

END IF

GOSUB ARCSINE

THEANGLE=MYANGLE+ANGLE

IF THEANGLE > 360 THEN THEANGLE=THEANGLE - 360

IF THEANGLE < 0 THEN THEANGLE=THEANGLE + 360

AX=OX+COS(THEANGLE*PI)*DISTANCE

AY=OY-SIN(THEANGLE*PI)*DISTANCE

PSET (AX,AY),Q

END IF

NEXT

NEXT

RETURN

ARCSINE:

G=ABS(SINE)

IF G=0 THEN MYANGLE=0:GOSUB REDUCE:RETURN

IF G=1 THEN MYANGLE=90:GOSUB REDUCE:RETURN

C=0

WHILE SIN(C*PI) < G

C=C+.1

WEND

MYANGLE=C

GOSUB REDUCER

RETURN

REDUCER:

IF COSINE < 0 AND SINE < 0 THEN MYANGLE=MYANGLE + 180

IF COSINE < 0 AND SINE > 0 THEN MYANGLE=MYANGLE + 90

IF COSINE > 0 AND SINE < 0 THEN MYANGLE=MYANGLE + 270

RETURN

## RE: 2d rotate