flat assembler
Message board for the users of flat assembler.

 Index > Windows > bitmap rotation alghorithm
Author
dave_30

Joined: 15 Dec 2012
Posts: 14
dave_30 19 Jan 2013, 20:35
just wondering is there any good algorithm in asm to rotate a bitmap by any angle?
for example let's say i draw a bitmap using dib in x=50 and y=70 and i want to rotate it in the same position by 16 degrees.
i'm using dib btw.
19 Jan 2013, 20:35
typedef

Joined: 25 Jul 2010
Posts: 2909
Location: 0x77760000
typedef 19 Jan 2013, 20:39
19 Jan 2013, 20:39
dave_30

Joined: 15 Dec 2012
Posts: 14
dave_30 19 Jan 2013, 21:09
well,to be honest there's tons of examples in vb and c but didn't been able to make the same in fasm or some didn't had what i'm looking for.
i also have several vb codes which does what i want but they draw it first into another dc then rotates the bitmap then transfers it to main dc which isn't what i want.
what i want is to include the bitmap and at run time read the bitmap data pixel by pixel and calculate the x and y by an angle then draw it.
i can draw the bitmap fine using dib it's the rotation i'm stuck at.
19 Jan 2013, 21:09
Siekmanski

Joined: 18 Jun 2006
Posts: 12
Location: The Netherlands
Siekmanski 20 Jan 2013, 10:23
Here's a very old example I did in the DOS days.
It's in TASM and it uses TRAN's PMODE.

20 Jan 2013, 10:23
dave_30

Joined: 15 Dec 2012
Posts: 14
dave_30 21 Jan 2013, 16:29
i used the code from vb and converted it to asm but i don't know why it doesn't works.
here is the code in vb that calculates the x and y based on the angel.
Code:
```Private Function InvRotateCoord(ByVal X As Long, ByVal Y As Long, _
ByVal Xs As Long, ByVal Ys As Long, _
ByVal Angle As Single) As RotateCoordenats
Dim SinA As Single, CosA As Single

'convert X,Y screen positions to math positions
Xs = Xs / 2
Ys = Ys / 2

X = X - Xs
Y = Y - Ys

'convert the angle to angles values
Angle = Angle * PI / 180

'calculate the SIN and COS of an angle
SinA = Sin(Angle)
CosA = Cos(Angle)

'Calculate the X,Y Rotated coordenats
InvRotateCoord.RotatedX = Xs + X * CosA - Y * SinA
InvRotateCoord.RotatedY = Ys + Y * CosA + X * SinA

End Function
```

and here is my code:
Code:
```cvtsi2ss xmm0,[width]
cvtsi2ss xmm1,[height]
cvtsi2ss xmm2,[x]
cvtsi2ss xmm3,[y]
cvtsi2ss xmm4,[Angel]
fld1
fstp [vd]
divss xmm0,[vd]
divss xmm1,[vd]
subss xmm2,xmm0
subss xmm3,xmm1
mulss xmm4,[PI]
divss xmm4,[_2PI]
movss [Angel],xmm4
fld [Angel]
fsincos
fstp [cosa]
fstp [sina]
mulss xmm0,[cosa]
subss xmm0,xmm3
mulss xmm0,[sina]
cvtss2si eax,xmm0
mov [nx],eax

mulss xmm1,[cosa]
mulss xmm1,[sina]
cvtss2si eax,xmm1
mov [ny],eax
```

i don't know why the fuck it doesn't works?!
21 Jan 2013, 16:29
 Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First

 Jump to: Select a forum Official----------------AssemblyPeripheria General----------------MainTutorials and ExamplesDOSWindowsLinuxUnixMenuetOS Specific----------------MacroinstructionsOS ConstructionIDE DevelopmentProjects and IdeasNon-x86 architecturesHigh Level LanguagesProgramming Language DesignCompiler Internals Other----------------FeedbackHeapTest Area

Forum Rules:
 You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forumYou cannot vote in polls in this forumYou cannot attach files in this forumYou can download files in this forum