flat assembler
Message board for the users of flat assembler.

Index > Windows > bitmap rotation alghorithm

Author
Thread Post new topic Reply to topic
dave_30



Joined: 15 Dec 2012
Posts: 14
dave_30
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.
Post 19 Jan 2013, 20:35
View user's profile Send private message Reply with quote
typedef



Joined: 25 Jul 2010
Posts: 2913
Location: 0x77760000
typedef
Post 19 Jan 2013, 20:39
View user's profile Send private message Reply with quote
dave_30



Joined: 15 Dec 2012
Posts: 14
dave_30
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.
Post 19 Jan 2013, 21:09
View user's profile Send private message Reply with quote
Siekmanski



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


Description:
Download
Filename: rotatepic_old.zip
Filesize: 86.71 KB
Downloaded: 56 Time(s)

Post 20 Jan 2013, 10:23
View user's profile Send private message Reply with quote
dave_30



Joined: 15 Dec 2012
Posts: 14
dave_30
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
fadd st0,st0
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]
addss xmm0,xmm2
mulss xmm0,[cosa]
subss xmm0,xmm3
mulss xmm0,[sina]
addss xmm0,xmm2
cvtss2si eax,xmm0
mov [nx],eax

addss xmm1,xmm3
mulss xmm1,[cosa]
addss xmm1,xmm2
mulss xmm1,[sina]
addss xmm1,xmm3
cvtss2si eax,xmm1
mov [ny],eax  
    

i don't know why the fuck it doesn't works?!
Post 21 Jan 2013, 16:29
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.