atari gesperrt
Anmeldungsdatum: 26.08.2007 Beiträge: 144
|
Verfasst am: 03.11.2007, 16:47 Titel: sprite ausserhalb der mitte drehen.... |
|
|
hallo, habe dieses programm aus dem engl forum. sprite wird gedreht.
der drehpunkt ist in der mitte.
meine augen finden keinen anschluss daran, wie man ein bestimmtes codeteil ändern kann, damit man den drehpunkt verlagern kann.
wer weiss hier rat?
oder hat eienr noch ein anderes programm auf der pfanne und weiss wo ein programm liegt von freebasic um ein bild ausserhalb der mitte zu drehen?
mfg
Code: |
Dim As String Img_Name = "foobar.bmp"
Dim Shared As Integer X_Mid, Y_Mid, scrn_wid, scrn_hgt, P1, P2, P3, P4, _
Y1, Y2, Y3, Y4, Y_Sin, Y_Cos
Dim Shared As Short Img_Hgt, Img_Wid, Img_Lft, Img_Rgt, Img_Top, Img_Btm, X, Y
Dim Shared As Single Cos_Ang, Sin_Ang, Rot_Fac_X, Rot_Fac_Y, Angle, Scale = 1
Sub Calc_rotozoom
If Scale < 1 Then Scale = 1
Cos_Ang = Cos(Angle)*Scale
Sin_Ang = Sin(Angle)*Scale
End Sub
screenRes 800,600, 32,,0
'' find image dimensions
Open Img_Name For Binary As #1
Get #1, 19, Img_Wid
Get #1, 23, Img_Hgt
Close #1
'' imagecreate sprite and load image to sprite
Dim Shared As Uinteger Ptr Img_Buffer
Img_Buffer = ImageCreate (Img_Wid, Img_Hgt)
Bload (Img_Name, Img_Buffer)
'' imagecreate "black" sprite
Dim Shared As Uinteger Ptr Cls_Buffer
Cls_Buffer = ImageCreate (Img_Wid, Img_Hgt, 0)
'' dim array to hold image. Note: pixel (0, 0) is in the center
Img_Rgt = (Img_Wid-1)\2
Img_Lft = -Img_Rgt
Img_Btm = (Img_Hgt-1)\2
Img_Top = -Img_Btm
Dim As Uinteger P(Img_Lft To Img_Rgt, Img_Top To Img_Btm)
'' load image from sprite to array
X_Mid = Img_wid\2
Y_Mid = Img_hgt\2
For Y = Img_Top To Img_Btm
For X = Img_Lft To Img_Rgt
P(x, y) = Img_Buffer[8+((X+X_Mid) + (Y+Y_Mid)*Img_Wid)]
Next X
Next Y
calc_rotozoom
'' main program loop
Do
'' scale 1 % in/out with uparrow/downarrow
If Multikey(80) Then
Scale *= 1.01
Calc_Rotozoom
Elseif Multikey(72) Then
Scale *= 0.99
Calc_Rotozoom
End If
'' rotate 1 deg left/right with leftarrow/rightarrow
If Multikey(77) Then
Angle -= 0.00175
Calc_Rotozoom
Elseif Multikey(75) Then
Angle += 0.00175
Calc_Rotozoom
End If
'' draw pixel in center of image
Img_Buffer[8+(X_Mid+Y_Mid*Img_wid)] = P(0, 0)
'' draw all other pixels - 4 at a time
For Y = Img_Top To 0
'' calculate a few vars that only depend on Y outside inner loop
Y1 = (Y_Mid+Y)*Img_wid
Y2 = (Y_Mid-Y)*Img_wid
Y3 = X_Mid+Y
Y4 = X_Mid-Y
Y_Sin = Y*Sin_Ang
Y_Cos = Y*Cos_Ang
For X = Img_Lft To -1
'' find pixel position x 4
P1 = 8+((X_Mid+X)+Y1)
P2 = 8+((X_Mid-X)+Y2)
P3 = 8+(Y3+(Y_Mid-X)*Img_wid)
P4 = 8+(Y4+(Y_Mid+X)*Img_wid)
'' rotate and zoom
Rot_Fac_X = X*Cos_Ang-Y_Sin
Rot_Fac_Y = X*Sin_Ang+Y_Cos
'' check if pixel exists
If _
(Rot_Fac_X < Img_Lft Or Rot_Fac_X > Img_Rgt) Or _
(Rot_Fac_Y < Img_Top Or Rot_Fac_Y > Img_Btm) _
Then
'' if no, then paint pixel with background color x 4
Img_Buffer[P1] = RGB(255, 0, 255)
Img_Buffer[P2] = RGB(255, 0, 255)
Img_Buffer[P3] = RGB(255, 0, 255)
Img_Buffer[P4] = RGB(255, 0, 255)
Else
'' if yes, draw new pixel x 4
Img_Buffer[P1] = P(Rot_Fac_X, Rot_Fac_Y)
Img_Buffer[P2] = P(-Rot_Fac_X, -Rot_Fac_Y)
Img_Buffer[P3] = P(Rot_Fac_Y, -Rot_Fac_X)
Img_Buffer[P4] = P(-Rot_Fac_Y, Rot_Fac_X)
End If
Next X
Next Y
ScreenLock
Put (50, 50), Cls_Buffer, Pset
Put (50, 50), Img_Buffer, Trans
ScreenUnlock
Loop Until Multikey(1)
ImageDestroy Img_Buffer
ImageDestroy Cls_Buffer
End
|
|
|