2025-07-06 02:49:38 +01:00
|
|
|
structure Ndc =
|
|
|
|
|
struct
|
|
|
|
|
(* ndc = normalised device coordinates *)
|
2025-07-06 03:21:18 +01:00
|
|
|
|
2025-07-06 02:49:38 +01:00
|
|
|
fun ltrbToVertex (left, top, right, bottom) =
|
|
|
|
|
#[ left, bottom
|
|
|
|
|
, right, bottom
|
|
|
|
|
, left, top
|
|
|
|
|
|
|
|
|
|
, left, top
|
|
|
|
|
, right, bottom
|
|
|
|
|
, right, top
|
|
|
|
|
]
|
|
|
|
|
|
2025-07-12 19:00:24 +01:00
|
|
|
fun ltrbToVertexRgb (startX, startY, endX, endY, r, g, b) =
|
|
|
|
|
#[ startX, endY, r, g, b
|
|
|
|
|
, endX, endY, r, g, b
|
|
|
|
|
, startX, startY, r, g, b
|
2025-07-06 02:49:38 +01:00
|
|
|
|
2025-07-12 19:00:24 +01:00
|
|
|
, startX, startY, r, g, b
|
|
|
|
|
, endX, endY, r, g, b
|
|
|
|
|
, endX, startY, r, g, b
|
2025-07-06 02:49:38 +01:00
|
|
|
]
|
2025-07-06 03:21:18 +01:00
|
|
|
|
|
|
|
|
fun fromPixelX (xpos, windowWidth, windowHeight) =
|
|
|
|
|
let
|
2025-07-11 03:48:04 +01:00
|
|
|
val halfWidth = Real32.fromInt windowWidth / 2.0
|
2025-07-06 03:21:18 +01:00
|
|
|
in
|
2025-07-13 01:40:57 +01:00
|
|
|
(xpos - halfWidth) / halfWidth
|
2025-07-06 03:21:18 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
fun fromPixelY (ypos, windowWidth, windowHeight) =
|
|
|
|
|
let
|
2025-07-11 03:48:04 +01:00
|
|
|
val halfHeight = Real32.fromInt windowHeight / 2.0
|
2025-07-06 03:21:18 +01:00
|
|
|
in
|
2025-07-13 01:40:57 +01:00
|
|
|
~((ypos - halfHeight) / halfHeight)
|
2025-07-06 03:21:18 +01:00
|
|
|
end
|
2025-07-06 02:49:38 +01:00
|
|
|
end
|