Skip to content

Commit cdb3376

Browse files
committed
make arrow width proportional to length
1 parent 7a16fb2 commit cdb3376

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

lib/PDL/Graphics/OpenGLQ.pd

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,11 @@ pp_addhdr('
4747
to[1] = -(v1[0]*v2[2] - v2[0]*v1[2]); \
4848
to[2] = v1[0]*v2[1] - v2[0]*v1[1]; \
4949
}
50+
#define PDL_3D_VECLEN(v) \
51+
sqrtf(v[0]*v[0] + v[1]*v[1] + v[2]*v[2])
5052
#define PDL_3D_SETVECLEN(v, newlen) \
5153
{ \
52-
float len = sqrtf(v[0]*v[0] + v[1]*v[1] + v[2]*v[2]), fac = newlen/len; \
54+
float len = PDL_3D_VECLEN(v), fac = newlen/len; \
5355
int i; \
5456
for (i = 0; i < 3; i++) v[i] *= fac; \
5557
}
@@ -186,8 +188,9 @@ loop(n) %{
186188
%}
187189
PDL_3D_CROSS(norm, tmp1, tmp2);
188190
PDL_3D_CROSS(norm2, tmp1, norm);
189-
PDL_3D_SETVECLEN(norm, w);
190-
PDL_3D_SETVECLEN(norm2, w);
191+
float wthis = w*PDL_3D_VECLEN(tmp1);
192+
PDL_3D_SETVECLEN(norm, wthis);
193+
PDL_3D_SETVECLEN(norm2, wthis);
191194
PDL_3D_SETVECLEN(tmp1, 1);
192195
loop(tri) %{ $trivertices(nv=>nvbase+0) = $coords(v => b); %}
193196
loop(tri) %{ $trivertices(nv=>nvbase+1) = partback[tri] + norm[tri]; %}

0 commit comments

Comments
 (0)