Code: Select all
#define pi 3.14159
Dim As Double x, y, vx, vy, d, t
Dim As Integer mx, my, mb, emx, emy
ScreenRes 1024, 720, 32, 2
x = 512 : y = 380 : d = 0
ScreenSet 1, 0
SetMouse x, y, 0
emx = x : emy = y
t = Timer
Do
If Timer >= t + .03 Then
Dim As Byte framex, framey
GetMouse mx, my, , mb
Line (0, 16)-(1023, 719), 0, BF
If mx <> 512 Or my <> 380 Then
mx = mx - 512
my = 380 - my
vx += mx / 10
vy += my / 10
d = ATn(-vy / vx)
If mx < 0 Then '2nd or 3rd quadrant
d += pi
ElseIf mx > 0 And my < 0 Then '4th quadrant
d += 2 * pi
End If
d -= pi / 2
If d < 0 Then d += 2 * pi
Locate 1, 1
Print mx; " "; my; " "
Print Int(d * 180 / pi); " "; 12 * d / pi; " ";
End If
x += vx
y -= vy
If x < 0 Then x = 0
If y < 0 Then y = 0
If x > 1023 Then x = 1023
If y > 719 Then y = 719
framex = 12 * d / pi
framey = framex \ 8
framex = framex Mod 8
Circle (x, y), 20, RGB(50, 250, 200), , , , F
ScreenCopy 1, 0
SetMouse 512, 380
t = Timer
End If
Loop Until Len(InKey)
End
Move the circle with the mouse and use ESC to exit. The movement is not perfect, but that's not the problem. See how, when you gather some speed, the movement is no longer smooth. On my computer, I can see two circles at the same time and I can clearly see the jump between a frame and the next even though the frequency is relatively high. If I change to a higher frequency, the problem persists, although it becomes harder to control the circle.
In DOS, I used to sync my drawing with the vertical retrace, but in Linux and Windows, as far as I know, that can't be done. The OS takes care of that part. When I capture the screen, the resulting picture always shows one circle only, which means I'm seeing the screen sweeping, not the actual contents of the window. This makes sense, since I'm working on a parallel screen and also, FB does its own double-buffering, if I'm not mistaken. Because I'm only drawing one rectangle (albeit big) and one circle, I would be surprised if this were taking more time to draw than the duration of a cycle. If I remove the ScreenCopy and ScreenSet statements, the movement becomes "heavier", but the display problem is still noticeable.
What is going on here? What can I do?