address one regression, where triangles were no longer being displayed (because calculation changed) after the previous refactoring. I know of only one more regression, which is that the clicked dots do not persist after moving the mouse.

This commit is contained in:
2024-09-19 17:46:40 +01:00
parent 9153217d5f
commit 6a7f11efe6
3 changed files with 45 additions and 7 deletions

View File

@@ -3,7 +3,7 @@ sig
val generate: int * int -> Real32.real vector
val getClickPositionFromMouse: AppType.app_type
-> (Real32.real * Real32.real) option
val getDrawVec:
val getDrawDot:
Real32.real
* Real32.real
* Real32.real
@@ -11,6 +11,10 @@ sig
* Real32.real
* AppType.app_type
-> Real32.real vector
(* two below functions convert pixel coordinates to normalised device coordinates *)
val xposToNdc: Real32.real * int * int * Real32.real -> Real32.real
val yposToNdc: Real32.real * int * int * Real32.real -> Real32.real
end
structure ClickPoints :> CLICK_POINTS =
@@ -53,7 +57,7 @@ struct
| NONE => NONE)
| NONE => NONE
fun getDrawVec (xpos, ypos, r, g, b, app: AppType.app_type) =
fun getDrawDot (xpos, ypos, r, g, b, app: AppType.app_type) =
let
val {windowWidth, windowHeight, ...} = app
@@ -71,4 +75,37 @@ struct
in
Ndc.ltrbToVertex (left, top, right, bottom, r, g, b)
end
fun xposToNdc (xpos, windowWidth, windowHeight, halfWidth) =
let
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 yposToNdc (ypos, windowWidth, windowHeight, halfHeight) =
let
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