Fix bug with knot mesh not closing loop, tweak constants
This commit is contained in:
parent
f5a304e4f2
commit
b8d3c40413
29
Torus.elm
29
Torus.elm
@ -34,6 +34,11 @@ type alias Model =
|
|||||||
, time : Float
|
, time : Float
|
||||||
, winSize : Window.Size }
|
, winSize : Window.Size }
|
||||||
|
|
||||||
|
totalLinePoints = 250
|
||||||
|
ringRadius = 0.1
|
||||||
|
ringVerts = 40
|
||||||
|
knotScale = 0.2
|
||||||
|
|
||||||
init: ( Model , Cmd Msg )
|
init: ( Model , Cmd Msg )
|
||||||
init =
|
init =
|
||||||
-- ( { p = 1 , q = 0 , time = 0.0 , winSize = (Window.Size 1 1)
|
-- ( { p = 1 , q = 0 , time = 0.0 , winSize = (Window.Size 1 1)
|
||||||
@ -124,10 +129,10 @@ torusPoints p q =
|
|||||||
interpolatedCircle totalLinePoints
|
interpolatedCircle totalLinePoints
|
||||||
|> List.map
|
|> List.map
|
||||||
(\ t ->
|
(\ t ->
|
||||||
let r = 0.5 * (2 + sin (q * t))
|
let r = 2 + sin (q * t)
|
||||||
in vec3
|
in vec3
|
||||||
(cos (t * p) * r)
|
(cos (t * p) * r)
|
||||||
(cos (t * q) * r * 0.5)
|
(cos (t * q) * r * 0.25)
|
||||||
(sin (t * p) * r) )
|
(sin (t * p) * r) )
|
||||||
|
|
||||||
|
|
||||||
@ -136,9 +141,11 @@ torusRings verts =
|
|||||||
verts
|
verts
|
||||||
|> List.map
|
|> List.map
|
||||||
(\ (p1, p2)->
|
(\ (p1, p2)->
|
||||||
(List.map circlePoint <| interpolatedCircle ringVerts)
|
ringVerts
|
||||||
|
|> interpolatedCircle
|
||||||
|
|> List.map circlePoint
|
||||||
|> List.map (\ p ->
|
|> List.map (\ p ->
|
||||||
let (mid , dir) = (Vec3.add p1 p2 |> Vec3.scale 0.5 , Vec3.sub p2 p1 |> Vec3.normalize)
|
let (mid , dir) = (Vec3.add p1 p2 |> Vec3.scale knotScale , Vec3.sub p2 p1 |> Vec3.normalize)
|
||||||
p_ = Vec3.toRecord p
|
p_ = Vec3.toRecord p
|
||||||
dir_ = Vec3.toRecord dir
|
dir_ = Vec3.toRecord dir
|
||||||
u = Vec3.cross dir Vec3.j |> Vec3.normalize
|
u = Vec3.cross dir Vec3.j |> Vec3.normalize
|
||||||
@ -168,7 +175,12 @@ circlePoint: Float -> Vec3
|
|||||||
circlePoint x = vec3 (cos x) (sin x) 0
|
circlePoint x = vec3 (cos x) (sin x) 0
|
||||||
|
|
||||||
makePairs: List a -> List (a ,a)
|
makePairs: List a -> List (a ,a)
|
||||||
makePairs ps = List.map2 (,) ps (List.drop 1 ps)
|
makePairs ps1 =
|
||||||
|
case ps1 of
|
||||||
|
[] -> []
|
||||||
|
h::tail ->
|
||||||
|
let ps2 = tail ++ [h]
|
||||||
|
in List.map2 (,) ps1 ps2
|
||||||
|
|
||||||
closedPairs: List a -> List (a ,a)
|
closedPairs: List a -> List (a ,a)
|
||||||
closedPairs xs =
|
closedPairs xs =
|
||||||
@ -197,6 +209,10 @@ colorToVec3 color =
|
|||||||
c = Color.toRgb color
|
c = Color.toRgb color
|
||||||
in vec3 (to01 c.red) (to01 c.green) (to01 c.blue)
|
in vec3 (to01 c.red) (to01 c.green) (to01 c.blue)
|
||||||
|
|
||||||
|
-------------
|
||||||
|
-- Shaders
|
||||||
|
-------------
|
||||||
|
|
||||||
type alias DiffuseColor =
|
type alias DiffuseColor =
|
||||||
{ projection : Mat4
|
{ projection : Mat4
|
||||||
, view : Mat4
|
, view : Mat4
|
||||||
@ -248,6 +264,3 @@ diffuseFS =
|
|||||||
gl_FragColor = vec4(color * vlightWeight, 1.0);
|
gl_FragColor = vec4(color * vlightWeight, 1.0);
|
||||||
}
|
}
|
||||||
|]
|
|]
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user