add scale parameter for collisions, so that we can easily use collisions when object is larger than normal/native
This commit is contained in:
@@ -630,7 +630,7 @@ struct
|
|||||||
fun mapGrid grid =
|
fun mapGrid grid =
|
||||||
Vector.map (fn yAxis => Vector.map (fn item => mapItem item) yAxis) grid
|
Vector.map (fn yAxis => Vector.map (fn item => mapItem item) yAxis) grid
|
||||||
|
|
||||||
fun toCollisionStringFolder ({x, ex, y, ey, data = _}, acc) =
|
fun toCollisionStringFolder scale ({x, ex, y, ey, data = _}, acc) =
|
||||||
let
|
let
|
||||||
val ex = ex + 1
|
val ex = ex + 1
|
||||||
val ey = if y = ey then ey + 1 else ey
|
val ey = if y = ey then ey + 1 else ey
|
||||||
@@ -640,10 +640,10 @@ struct
|
|||||||
val height = ey - y
|
val height = ey - y
|
||||||
val height = if height = 0 then height + 1 else height
|
val height = if height = 0 then height + 1 else height
|
||||||
|
|
||||||
val x = Int.toString x
|
val x = Int.toString (x * scale)
|
||||||
val y = Int.toString y
|
val y = Int.toString (y * scale)
|
||||||
val width = Int.toString width
|
val width = Int.toString (width * scale)
|
||||||
val height = Int.toString height
|
val height = Int.toString (height * scale)
|
||||||
|
|
||||||
val item = String.concat
|
val item = String.concat
|
||||||
[ "{x = "
|
[ "{x = "
|
||||||
@@ -660,13 +660,15 @@ struct
|
|||||||
item :: acc
|
item :: acc
|
||||||
end
|
end
|
||||||
|
|
||||||
fun toCollisionString (squares, canvasWidth, canvasHeight) =
|
fun toCollisionString (squares, canvasWidth, canvasHeight, scale) =
|
||||||
let
|
let
|
||||||
val size = Int.max (canvasWidth, canvasHeight)
|
val size = Int.max (canvasWidth, canvasHeight)
|
||||||
val qtree = buildTree (0, 0, size, squares)
|
val qtree = buildTree (0, 0, size, squares)
|
||||||
val bintree = merge (qtree, squares)
|
val bintree = merge (qtree, squares)
|
||||||
|
|
||||||
val collisions = BinTree.foldr (toCollisionStringFolder, bintree, [])
|
val scale = if scale = 0 then 1 else scale
|
||||||
|
val f = toCollisionStringFolder scale
|
||||||
|
val collisions = BinTree.foldr (f, bintree, [])
|
||||||
val collisions = String.concatWith ",\n" collisions
|
val collisions = String.concatWith ",\n" collisions
|
||||||
in
|
in
|
||||||
String.concat ["val collisions = #[", collisions, "]\n"]
|
String.concat ["val collisions = #[", collisions, "]\n"]
|
||||||
|
|||||||
55
green.sml
Normal file
55
green.sml
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
structure AAA =
|
||||||
|
struct
|
||||||
|
fun xToNdc (xOffset, xpos, scale, halfWidth) =
|
||||||
|
((xpos * scale + xOffset) - halfWidth) / halfWidth
|
||||||
|
|
||||||
|
fun endXToNdc (xOffset, startX, endX, scale, halfWidth) =
|
||||||
|
(((endX - startX) * scale + xOffset) - halfWidth) / halfWidth
|
||||||
|
|
||||||
|
fun yToNdc (yOffset, ypos, scale, halfHeight) =
|
||||||
|
~(((ypos * scale + yOffset) - halfHeight) / halfHeight)
|
||||||
|
|
||||||
|
fun endYToNdc (yOffset, startY, endY, scale, halfHeight) =
|
||||||
|
~((((endY - startY) * scale + yOffset) - halfHeight) / halfHeight)
|
||||||
|
|
||||||
|
fun lerp (xOffset, yOffset, scale, windowWidth, windowHeight) =
|
||||||
|
let
|
||||||
|
val windowWidth = Real32.fromInt windowWidth
|
||||||
|
val halfWidth = windowWidth / 2.0
|
||||||
|
val windowHeight = Real32.fromInt windowHeight
|
||||||
|
val halfHeight = windowHeight / 2.0
|
||||||
|
in
|
||||||
|
#[
|
||||||
|
xToNdc (xOffset, 1.000000000000000, scale, halfWidth),
|
||||||
|
yToNdc (yOffset, 2.000000000000000, scale, halfHeight),
|
||||||
|
0.000000000000000,
|
||||||
|
0.000000000000000,
|
||||||
|
0.000000000000000,
|
||||||
|
endXToNdc (xOffset, xToNdc (xOffset, 1.000000000000000, scale, halfWidth), 1.000000000000000, scale, halfWidth),
|
||||||
|
yToNdc (yOffset, 2.000000000000000, scale, halfHeight),
|
||||||
|
0.000000000000000,
|
||||||
|
0.000000000000000,
|
||||||
|
0.000000000000000,
|
||||||
|
xToNdc (xOffset, 1.000000000000000, scale, halfWidth),
|
||||||
|
yToNdc (yOffset, 1.000000000000000, scale, halfHeight),
|
||||||
|
0.000000000000000,
|
||||||
|
0.000000000000000,
|
||||||
|
0.000000000000000,
|
||||||
|
xToNdc (xOffset, 1.000000000000000, scale, halfWidth),
|
||||||
|
yToNdc (yOffset, 1.000000000000000, scale, halfHeight),
|
||||||
|
0.000000000000000,
|
||||||
|
0.000000000000000,
|
||||||
|
0.000000000000000,
|
||||||
|
endXToNdc (xOffset, xToNdc (xOffset, 1.000000000000000, scale, halfWidth), 1.000000000000000, scale, halfWidth),
|
||||||
|
yToNdc (yOffset, 2.000000000000000, scale, halfHeight),
|
||||||
|
0.000000000000000,
|
||||||
|
0.000000000000000,
|
||||||
|
0.000000000000000,
|
||||||
|
endXToNdc (xOffset, xToNdc (xOffset, 1.000000000000000, scale, halfWidth), 1.000000000000000, scale, halfWidth),
|
||||||
|
yToNdc (yOffset, 1.000000000000000, scale, halfHeight),
|
||||||
|
0.000000000000000,
|
||||||
|
0.000000000000000,
|
||||||
|
0.000000000000000
|
||||||
|
]
|
||||||
|
end
|
||||||
|
end
|
||||||
Reference in New Issue
Block a user