Determine bug in bezier curve rendering

This commit is contained in:
jgk
2021-03-13 12:58:20 +01:00
parent 9aa6fec418
commit 8f3b5d0bfe
5 changed files with 37 additions and 22 deletions
+22 -9
View File
@@ -1,6 +1,6 @@
#version 430 core
layout (triangles) in;
layout (triangle_strip, max_vertices = 4) out;
layout (triangle_strip, max_vertices = 5) out;
in vec4 vColor[];
in float vRad[];
out vec4 gColor;
@@ -8,8 +8,11 @@ out float gRadStart;
out float gRadEnd;
out vec3 gBoundingBox;
vec3 normV (vec3 v)
{ return vec3(v.y,-v.x,v.z) ;
vec2 normV2 (vec2 v)
{ return vec2(-v.y,v.x) ;
}
float lhs (vec2 da, vec2 db)
{ return sign(dot(da, normV2(db))) ;
}
void main()
@@ -21,21 +24,31 @@ void main()
gRadStart = vRad[0];
gRadEnd = vRad[2];
vec2 ab = (pa.xy - pb.xy);
vec2 cb = (pc.xy - pb.xy);
float dir = lhs( cb,ab);
gBoundingBox = vec3 (0.9,0.1,0);
gColor = vColor[0];
gl_Position = vec4 (pa.xy + dir * 2 * gRadStart * normV2(ab) , pa.z , 1);
EmitVertex();
gBoundingBox = vec3 (0.1,0.9,0);
gColor = vColor[2];
// gl_Position = vec4 (pc.xy + dir * gRadEnd * (normV2 (pb.xy-pc.xy)), pa.z , 1);
gl_Position = vec4 (pc.xy - dir * 2 * gRadEnd * normV2(cb) , pc.z , 1);
EmitVertex();
gBoundingBox = vec3 (1,0,1);
gColor = vColor[0];
gl_Position = vec4 (pa + normV (pa-pb) , 1);
EmitVertex();
gl_Position = vec4 (pa, 1);
EmitVertex();
gBoundingBox = vec3 (0,0,0);
gColor = vColor[1];
gl_Position = vec4 (pb, 1);
EmitVertex();
gBoundingBox = vec3 (0,1,1);
gColor = vColor[2];
gl_Position = vec4 (pc, 1);
EmitVertex();
gBoundingBox = vec3 (0,0,0);
gColor = vColor[1];
gl_Position = vec4 (pb, 1);
EmitVertex();
EndPrimitive();
}
-1
View File
@@ -364,7 +364,6 @@ startCr = basicCreature
,hvAutoGun
,teslaGun
,latchkey 0
,frontArmour
,miniGun
,medkit 50
,bezierGun
+1 -1
View File
@@ -122,7 +122,7 @@ worldPictures w
testPic :: World -> [Picture]
testPic w = --[blank]
[setLayer 1 $ onLayerL [99] $ bezierQuad white red 20 50 (-200,0) (0,0) (200,50) ]
[setLayer 1 $ onLayerL [99] $ bezierQuad white red 20 20 (00,00) (200,200) (200,000) ]
-- $ uncurry translate (mouseWorldPos w)
+1 -1
View File
@@ -548,7 +548,7 @@ deadEndRoom = Room
]
, _rmLinks = lnks
, _rmPath = []
, _rmPS = [PS (0,-10) 0 basicLS]
, _rmPS = [PS (0,-20) 0 basicLS]
, _rmBound = rectNSWE 20 (-20) (-30) 30
}
where lnks = [((0,30) ,0)
+13 -10
View File
@@ -70,19 +70,22 @@ polygonCol :: [(Point2,RGBA)] -> Picture
polygonCol = PolygonCol 0
-- note that much of work computing the width of the bezier curve is done here
-- not sure that moving the control point does much...
bezierQuad :: Color -> Color -> Float -> Float -> Point2 -> Point2 -> Point2 -> Picture
bezierQuad cola colc ra rc a b c = BezierQuad 0 [(aX,cola ,raX)
,(bx,mixColors 0.5 0.5 cola colc,1)
,(bX,mixColors 0.5 0.5 cola colc,1)
,(cX,colc ,rcX)]
where v = a -.- c
nv = normalizeV v
aX = a +.+ ra * 0.5 *.* nv
cX = c -.- rc * 0.5 *.* nv
raX = ra / magV (aX -.- cX)
rcX = rc / magV (aX -.- cX)
bx = b +.+ (0.5 * ra *.* normalizeV (b -.- a))
+.+ (0.5 * rc *.* normalizeV (b -.- c))
where b2a | isLHS a b c = b -.- a
| otherwise = a -.- b
nb2a = normalizeV $ vNormal b2a
aX = a +.+ ra * 0.5 *.* nb2a
b2c | isLHS a b c = c -.- b
| otherwise = b -.- c
nb2c = normalizeV $ vNormal b2c
cX = c +.+ rc * 0.5 *.* nb2c
raX = ra / magV (aX -.- bX)
rcX = rc / magV (cX -.- bX)
bX = b +.+ (0.5 * ra *.* nb2a)
+.+ (0.5 * rc *.* nb2c)
color :: RGBA -> Picture -> Picture
{-# INLINE color #-}