mirror of
https://github.com/dschmenk/PLASMA.git
synced 2026-04-27 03:18:02 +00:00
Use fractional coordinates to improve angular movement accuracy
This commit is contained in:
1 parent
1286daff45
commit
f987458a15
3 files changed
+17
-9
No files matched your search
Binary file not shown.
Binary file not shown.
+17
-9
@@ -7,7 +7,7 @@ const CLIP_RIGHT = 2
|
|||||||
const CLIP_TOP = 4
|
const CLIP_TOP = 4
|
||||||
const CLIP_BOTTOM = 8
|
const CLIP_BOTTOM = 8
|
||||||
|
|
||||||
var turtleX, turtleY, turtleAngle, drawLine
|
var turtleXp4, turtleYp4, turtleAngle, drawLine
|
||||||
byte pen
|
byte pen
|
||||||
var clipLeft, clipRight, clipTop, clipBottom
|
var clipLeft, clipRight, clipTop, clipBottom
|
||||||
|
|
||||||
@@ -35,7 +35,7 @@ def lerp(a1, b1, a2, b2, n)#1
|
|||||||
word[2] i32
|
word[2] i32
|
||||||
|
|
||||||
if b2 == b1; return b1; fin // Horizontal lerp
|
if b2 == b1; return b1; fin // Horizontal lerp
|
||||||
if a2 == a1; return n; fin // Vertical lerp
|
if a2 == a1; return n; fin // Vertical lerp
|
||||||
loadi16(b2 - b1)
|
loadi16(b2 - b1)
|
||||||
muli16(n - a1)
|
muli16(n - a1)
|
||||||
divi16(a2 - a1)
|
divi16(a2 - a1)
|
||||||
@@ -105,8 +105,8 @@ end
|
|||||||
export def initTurtle(width, height, linefunc)#0
|
export def initTurtle(width, height, linefunc)#0
|
||||||
drawLine = linefunc
|
drawLine = linefunc
|
||||||
clipRect(0, 0, width - 1, height - 1)
|
clipRect(0, 0, width - 1, height - 1)
|
||||||
turtleX = width / 2
|
turtleXp4 = width << 3
|
||||||
turtleY = height / 2
|
turtleYp4 = height << 3
|
||||||
turtleAngle = 0
|
turtleAngle = 0
|
||||||
pen = 1
|
pen = 1
|
||||||
end
|
end
|
||||||
@@ -127,18 +127,26 @@ end
|
|||||||
|
|
||||||
export def moveTo(x, y)#0
|
export def moveTo(x, y)#0
|
||||||
if pen
|
if pen
|
||||||
clipLine(turtleX, turtleY, x, y)
|
clipLine(turtleXp4 >> 4, turtleYp4 >> 4, x, y)
|
||||||
fin
|
fin
|
||||||
turtleX = x
|
turtleXp4 = x << 4
|
||||||
turtleY = y
|
turtleYp4 = y << 4
|
||||||
end
|
end
|
||||||
|
|
||||||
export def moveForward(dist)#0
|
export def moveForward(dist)#0
|
||||||
moveTo(turtleX + mulcos(dist, turtleAngle), turtleY + mulsin(dist, turtleAngle))
|
var oldX, oldY
|
||||||
|
|
||||||
|
oldX = turtleXp4 >> 4
|
||||||
|
oldY = turtleYp4 >> 4
|
||||||
|
turtleXp4 = turtleXp4 + mulcos(dist << 4, turtleAngle)
|
||||||
|
turtleYp4 = turtleYp4 + mulsin(dist << 4, turtleAngle)
|
||||||
|
if pen
|
||||||
|
clipLine(turtleXp4 >> 4, turtleYp4 >> 4, oldX, oldY)
|
||||||
|
fin
|
||||||
end
|
end
|
||||||
|
|
||||||
export def moveBackward(dist)#0
|
export def moveBackward(dist)#0
|
||||||
moveTo(turtleX - mulcos(dist, turtleAngle), turtleY - mulsin(dist, turtleAngle))
|
moveForward(-dist)
|
||||||
end
|
end
|
||||||
|
|
||||||
export def penUp#0
|
export def penUp#0
|
||||||
|
|||||||
Reference in new issue
Block a user