scale player.sml in the same way that wall.sml is being scaled, and also: make 'x' and 'y' arguments to Block.lerp Real32.real values rather than int values (with calling code making the necessary changes) as the code was converting between int and real multiple times
This commit is contained in:
@@ -2,8 +2,6 @@ structure Block =
|
|||||||
struct
|
struct
|
||||||
fun lerp (startX, startY, drawWidth, drawHeight, windowWidth, windowHeight, r, g, b) : Real32.real vector =
|
fun lerp (startX, startY, drawWidth, drawHeight, windowWidth, windowHeight, r, g, b) : Real32.real vector =
|
||||||
let
|
let
|
||||||
val startX = Real32.fromInt startX
|
|
||||||
val startY = Real32.fromInt startY
|
|
||||||
val endY = windowHeight - startY
|
val endY = windowHeight - startY
|
||||||
val startY = windowHeight - (startY + drawHeight)
|
val startY = windowHeight - (startY + drawHeight)
|
||||||
val endX = startX + drawWidth
|
val endX = startX + drawWidth
|
||||||
|
|||||||
@@ -238,5 +238,39 @@ struct
|
|||||||
|
|
||||||
(* block is placeholder asset *)
|
(* block is placeholder asset *)
|
||||||
fun getDrawVec ({x, y, ...}: player, width, height) =
|
fun getDrawVec ({x, y, ...}: player, width, height) =
|
||||||
Block.lerp (x, y, realSize, realSize, width, height, 0.5, 0.5, 0.5)
|
let
|
||||||
|
val wratio = width / 1920.0
|
||||||
|
val hratio = height / 1080.0
|
||||||
|
in
|
||||||
|
if wratio < hratio then
|
||||||
|
let
|
||||||
|
val scale = 1080.0 * wratio
|
||||||
|
val yOffset =
|
||||||
|
if height > scale then (height - scale) / 2.0
|
||||||
|
else if height < scale then (scale - height) / 2.0
|
||||||
|
else 0.0
|
||||||
|
|
||||||
|
val x = Real32.fromInt x * wratio
|
||||||
|
val y = Real32.fromInt y * wratio + yOffset
|
||||||
|
|
||||||
|
val realSize = realSize * wratio
|
||||||
|
in
|
||||||
|
Block.lerp (x, y, realSize, realSize, width, height, 0.5, 0.5, 0.5)
|
||||||
|
end
|
||||||
|
else
|
||||||
|
let
|
||||||
|
val scale = 1920.0 * hratio
|
||||||
|
val xOffset =
|
||||||
|
if width > scale then (width - scale) / 2.0
|
||||||
|
else if width < scale then (scale - width) / 2.0
|
||||||
|
else 0.0
|
||||||
|
|
||||||
|
val x = Real32.fromInt x * hratio + xOffset
|
||||||
|
val y = Real32.fromInt y * hratio
|
||||||
|
|
||||||
|
val realSize = realSize * hratio
|
||||||
|
in
|
||||||
|
Block.lerp (x, y, realSize, realSize, width, height, 0.5, 0.5, 0.5)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -14,26 +14,6 @@ struct
|
|||||||
|
|
||||||
fun generateTree wallVec = helpGenerateTree (0, wallVec, QuadTree.empty)
|
fun generateTree wallVec = helpGenerateTree (0, wallVec, QuadTree.empty)
|
||||||
|
|
||||||
val preferredAspectRatio: Real32.real = 1920.0 / 1080.0
|
|
||||||
|
|
||||||
fun helpGetDrawVecPreferred (pos, wallVec, acc, winWidth, winHeight) =
|
|
||||||
if pos = Vector.length wallVec then
|
|
||||||
Vector.concat acc
|
|
||||||
else
|
|
||||||
let
|
|
||||||
val wall = Vector.sub (wallVec, pos)
|
|
||||||
val {x, y, width, height, id = _} = wall
|
|
||||||
val width = Real32.fromInt width
|
|
||||||
val height = Real32.fromInt height
|
|
||||||
|
|
||||||
val block = Block.lerp
|
|
||||||
(x, y, width, height, winWidth, winHeight, 0.0, 0.0, 0.0)
|
|
||||||
val acc = block :: acc
|
|
||||||
in
|
|
||||||
helpGetDrawVecPreferred (pos + 1, wallVec, acc, winWidth, winHeight)
|
|
||||||
end
|
|
||||||
|
|
||||||
(* when actual aspect ratio > preferredAspectRatio *)
|
|
||||||
fun helpGetDrawVecWider
|
fun helpGetDrawVecWider
|
||||||
(pos, wallVec, acc, winWidth, winHeight, ratio, yOffset) =
|
(pos, wallVec, acc, winWidth, winHeight, ratio, yOffset) =
|
||||||
if pos = Vector.length wallVec then
|
if pos = Vector.length wallVec then
|
||||||
@@ -44,10 +24,7 @@ struct
|
|||||||
val {x, y, width, height, id = _} = wall
|
val {x, y, width, height, id = _} = wall
|
||||||
|
|
||||||
val x = Real32.fromInt x * ratio
|
val x = Real32.fromInt x * ratio
|
||||||
val x = Real32.toInt IEEEReal.TO_NEAREST x
|
|
||||||
|
|
||||||
val y = Real32.fromInt y * ratio + yOffset
|
val y = Real32.fromInt y * ratio + yOffset
|
||||||
val y = Real32.toInt IEEEReal.TO_NEAREST y
|
|
||||||
|
|
||||||
val width = Real32.fromInt width * ratio
|
val width = Real32.fromInt width * ratio
|
||||||
val height = Real32.fromInt height * ratio
|
val height = Real32.fromInt height * ratio
|
||||||
@@ -60,7 +37,6 @@ struct
|
|||||||
(pos + 1, wallVec, acc, winWidth, winHeight, ratio, yOffset)
|
(pos + 1, wallVec, acc, winWidth, winHeight, ratio, yOffset)
|
||||||
end
|
end
|
||||||
|
|
||||||
(* when actual aspect ratio < preferredAspectRatio *)
|
|
||||||
fun helpGetDrawVecTaller
|
fun helpGetDrawVecTaller
|
||||||
(pos, wallVec, acc, winWidth, winHeight, ratio, xOffset) =
|
(pos, wallVec, acc, winWidth, winHeight, ratio, xOffset) =
|
||||||
if pos = Vector.length wallVec then
|
if pos = Vector.length wallVec then
|
||||||
@@ -71,10 +47,7 @@ struct
|
|||||||
val {x, y, width, height, id = _} = wall
|
val {x, y, width, height, id = _} = wall
|
||||||
|
|
||||||
val x = Real32.fromInt x * ratio + xOffset
|
val x = Real32.fromInt x * ratio + xOffset
|
||||||
val x = Real32.toInt IEEEReal.TO_NEAREST x
|
|
||||||
|
|
||||||
val y = Real32.fromInt y * ratio
|
val y = Real32.fromInt y * ratio
|
||||||
val y = Real32.toInt IEEEReal.TO_NEAREST y
|
|
||||||
|
|
||||||
val width = Real32.fromInt width * ratio
|
val width = Real32.fromInt width * ratio
|
||||||
val height = Real32.fromInt height * ratio
|
val height = Real32.fromInt height * ratio
|
||||||
|
|||||||
Reference in New Issue
Block a user