Skip to content

Commit

Permalink
Move files around
Browse files Browse the repository at this point in the history
  • Loading branch information
w0rm committed Dec 8, 2023
1 parent b21731d commit 900d5f4
Show file tree
Hide file tree
Showing 9 changed files with 93 additions and 83 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
16 changes: 8 additions & 8 deletions src/Main.elm
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ type Model
type Msg
= WindowResized (Rectangle2d Pixels ScreenCoordinates)
| GotBallTexture Int (Result WebGL.Texture.Error (Material.Texture Color))
| GotRoughnessTexture (Result WebGL.Texture.Error (Material.Texture Float))
| GotBallRoughnessTexture (Result WebGL.Texture.Error (Material.Texture Float))
| GotTable (Result String Table)
| RunningMsg Game.Msg
| StartNewGameButtonClicked
Expand Down Expand Up @@ -130,12 +130,12 @@ init unsafeFlags =
)
(List.range 1 15)
)
, Task.attempt GotRoughnessTexture (Material.load (assetsPath ++ "img/roughness.jpg"))
, Task.attempt GotBallRoughnessTexture (Material.load (assetsPath ++ "img/balls/roughness.jpg"))
, Task.attempt GotTable
(Table.load
{ colorTexture = assetsPath ++ "img/billiard-table-color.png"
, roughnessTexture = assetsPath ++ "img/billiard-table-roughness.png"
, metallicTexture = assetsPath ++ "img/billiard-table-metallic.png"
{ colorTexture = assetsPath ++ "img/table/color.png"
, roughnessTexture = assetsPath ++ "img/table/roughness.png"
, metallicTexture = assetsPath ++ "img/table/metallic.png"
, mesh = assetsPath ++ "/billiard-table.obj.txt"
}
)
Expand Down Expand Up @@ -249,8 +249,8 @@ fontStyle path =
"""
@font-face {
font-family: 'Teko';
src: url('""" ++ path ++ """assets/Teko-Medium.woff2') format('woff2'),
url('""" ++ path ++ """assets/Teko-Medium.woff') format('woff');
src: url('""" ++ path ++ """font/Teko-Medium.woff2') format('woff2'),
url('""" ++ path ++ """font/Teko-Medium.woff') format('woff');
font-weight: 500;
font-style: normal;
font-display: block;
Expand Down Expand Up @@ -282,7 +282,7 @@ update msg model =
Err _ ->
Failed "Failed to load ball texture"

( GotRoughnessTexture maybeTexture, Loading loadingModel ) ->
( GotBallRoughnessTexture maybeTexture, Loading loadingModel ) ->
case maybeTexture of
Ok texture ->
loadComplete
Expand Down
160 changes: 85 additions & 75 deletions src/Table.elm
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,91 @@ type alias Table =
}


length : Length
length =
Length.meters 2.26


width : Length
width =
Length.meters 1.24


{-| Anywhere on the table. This where the cue ball should be placed after it goes in a pocket
or after the failure to hit the object ball.
-}
areaBallInHand : Rectangle3d Meters WorldCoordinates
areaBallInHand =
let
xOffset =
Quantity.half length |> Quantity.minus Ball.radius

yOffset =
Quantity.half width |> Quantity.minus Ball.radius
in
Rectangle3d.on SketchPlane3d.xy
(Rectangle2d.from
(Point2d.xy (Quantity.negate xOffset) (Quantity.negate yOffset))
(Point2d.xy xOffset yOffset)
)
|> Rectangle3d.translateIn Direction3d.z (Length.millimeters 1)


{-| The foot spot is the place where you “spot the ball”, it is also
the place where the top object ball is placed when racking a game
-}
footSpot : Point2d Meters WorldCoordinates
footSpot =
Point2d.xy
(Quantity.half (Quantity.half length))
Quantity.zero


{-| The area where you break from, and where you must place the cue ball after a scratch.
-}
areaBehindTheHeadString : Rectangle3d Meters WorldCoordinates
areaBehindTheHeadString =
let
yOffset =
Quantity.half width |> Quantity.minus Ball.radius

xMin =
Quantity.half length |> Quantity.minus Ball.radius |> Quantity.negate

xMax =
Quantity.half (Quantity.half length) |> Quantity.negate
in
Rectangle3d.on SketchPlane3d.xy
(Rectangle2d.from
(Point2d.xy xMin (Quantity.negate yOffset))
(Point2d.xy xMax yOffset)
)
|> Rectangle3d.translateIn Direction3d.z (Length.millimeters 1)


{-| Highlight the area behind the head string when the ball should be placed there
-}
areaBehindTheHeadStringEntity : Entity WorldCoordinates
areaBehindTheHeadStringEntity =
case Rectangle3d.vertices areaBehindTheHeadString of
[ v1, v2, v3, v4 ] ->
Scene3d.quad
(Material.nonmetal
{ baseColor = Color.rgb255 131 146 34
, roughness = 1
}
)
v1
v2
v3
v4

_ ->
Scene3d.nothing


{-| Load the visual entity and the collider bodies for the table from the obj file and texture files
-}
load : { colorTexture : String, roughnessTexture : String, metallicTexture : String, mesh : String } -> Task String Table
load urls =
Http.task
Expand Down Expand Up @@ -146,78 +231,3 @@ startsWith prefix decoder =
|> List.map (\name -> Obj.Decode.object name decoder)
|> Obj.Decode.combine
)


areaBallInHand : Rectangle3d Meters WorldCoordinates
areaBallInHand =
let
xOffset =
Quantity.half length |> Quantity.minus Ball.radius

yOffset =
Quantity.half width |> Quantity.minus Ball.radius
in
Rectangle3d.on SketchPlane3d.xy
(Rectangle2d.from
(Point2d.xy (Quantity.negate xOffset) (Quantity.negate yOffset))
(Point2d.xy xOffset yOffset)
)
|> Rectangle3d.translateIn Direction3d.z (Length.millimeters 1)


length : Length
length =
Length.meters 2.26


width : Length
width =
Length.meters 1.24


footSpot : Point2d Meters WorldCoordinates
footSpot =
Point2d.xy
(Quantity.half (Quantity.half length))
Quantity.zero


areaBehindTheHeadString : Rectangle3d Meters WorldCoordinates
areaBehindTheHeadString =
let
yOffset =
Quantity.half width |> Quantity.minus Ball.radius

xMin =
Quantity.half length |> Quantity.minus Ball.radius |> Quantity.negate

xMax =
Quantity.half (Quantity.half length) |> Quantity.negate
in
Rectangle3d.on SketchPlane3d.xy
(Rectangle2d.from
(Point2d.xy xMin (Quantity.negate yOffset))
(Point2d.xy xMax yOffset)
)
|> Rectangle3d.translateIn Direction3d.z (Length.millimeters 1)


{-| Highlight the area where the ball should be placed
-}
areaBehindTheHeadStringEntity : Entity WorldCoordinates
areaBehindTheHeadStringEntity =
case Rectangle3d.vertices areaBehindTheHeadString of
[ v1, v2, v3, v4 ] ->
Scene3d.quad
(Material.nonmetal
{ baseColor = Color.rgb255 131 146 34
, roughness = 1
}
)
v1
v2
v3
v4

_ ->
Scene3d.nothing

0 comments on commit 900d5f4

Please sign in to comment.