begin merging files which were previously in temp-squares directory into main
This commit is contained in:
56
fcore/ndc.sml
Normal file
56
fcore/ndc.sml
Normal file
@@ -0,0 +1,56 @@
|
||||
structure Ndc =
|
||||
struct
|
||||
(* ndc = normalised device coordinates *)
|
||||
|
||||
fun ltrbToVertex (left, top, right, bottom) =
|
||||
#[ left, bottom
|
||||
, right, bottom
|
||||
, left, top
|
||||
|
||||
, left, top
|
||||
, right, bottom
|
||||
, right, top
|
||||
]
|
||||
|
||||
fun ltrbToVertexRgb (left, top, right, bottom, r, g, b) =
|
||||
#[ left, bottom, r, g, b
|
||||
, right, bottom, r, g, b
|
||||
, left, top, r, g, b
|
||||
|
||||
, left, top, r, g, b
|
||||
, right, bottom, r, g, b
|
||||
, right, top, r, g, b
|
||||
]
|
||||
|
||||
fun fromPixelX (xpos, windowWidth, windowHeight) =
|
||||
let
|
||||
val halfWidth = Real32.fromInt (windowWidth div 2)
|
||||
val xpos = xpos - halfWidth
|
||||
in
|
||||
if windowWidth > windowHeight then
|
||||
let
|
||||
val difference = windowWidth - windowHeight
|
||||
val offset = Real32.fromInt (difference div 2)
|
||||
in
|
||||
xpos / (halfWidth - offset)
|
||||
end
|
||||
else
|
||||
xpos / halfWidth
|
||||
end
|
||||
|
||||
fun fromPixelY (ypos, windowWidth, windowHeight) =
|
||||
let
|
||||
val halfHeight = Real32.fromInt (windowHeight div 2)
|
||||
val ypos = ~(ypos - halfHeight)
|
||||
in
|
||||
if windowHeight > windowWidth then
|
||||
let
|
||||
val difference = windowHeight - windowWidth
|
||||
val offset = Real32.fromInt (difference div 2)
|
||||
in
|
||||
ypos / (halfHeight - offset)
|
||||
end
|
||||
else
|
||||
ypos / halfHeight
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user