Pendant:
PUBLIC
PROC [
context: Context,
view: Matrix,
size: REAL ← .07,
wPos, hPos: REAL ← .7,
names: ARRAY [0..6) OF ROPE ← ALL[NIL]]
~ {
mx: REAL ← 0.0;
v: ARRAY [0..6) OF V;
V: TYPE ~ RECORD[rope: ROPE, vec: Triple];
axes: ARRAY [0..6) OF Triple ~ [[1, 0, 0], [0, 1, 0], [0, 0, 1], [-1, 0, 0], [0, -1, 0], [0, 0, -1]];
c: Pair;
rect: Imager.Rectangle ← [0.0, 0.0, 600.0, 400.0];
rect ← ImagerBackdoor.GetBounds[context ! Imager.Error => CONTINUE];
c ← [rect.w*(1+wPos)/2, rect.h*(1+hPos)/2];
FOR n:
NAT
IN [0..6)
DO
v[n] ← [names[n], Matrix3d.TransformVec[axes[n], view]];
ENDLOOP;
FOR n: NAT IN [0..6) DO mx ← MAX[mx, Vector2.Square[[v[n].vec.x, v[n].vec.y]]]; ENDLOOP;
mx ← MAX[rect.w, rect.h]*size/Real.SqRt[mx];
FOR n: NAT IN [0..6) DO v[n].vec ← Vector3d.Mul[v[n].vec, mx]; ENDLOOP;
DO
-- order v by increasing z:
d: BOOL ← FALSE;
FOR n:
NAT
IN [0..5)
DO
IF v[n].vec.z<v[n+1].vec.z THEN {t: V ← v[n]; v[n] ← v[n+1]; v[n+1] ← t; d ← TRUE};
ENDLOOP;
IF NOT d THEN EXIT;
ENDLOOP;
FOR n:
NAT
IN [0..6)
DO
IF v[n].rope = NIL THEN LOOP;
Imager.SetColor[context, Imager.white];
Imager.MaskRectangle[context, [c.x+v[n].vec.x, c.y+v[n].vec.y-4, 8, 8]];
Imager.SetColor[context, Imager.black];
Draw2d.Label[context, [c.x+v[n].vec.x, c.y+v[n].vec.y-4], v[n].rope];
ENDLOOP;
FOR n:
NAT
IN [0..6)
DO
IF v[n].rope #
NIL
THEN {
a: Pair ←
IF v[n].vec.x = 0
AND v[n].vec.y = 0
THEN [0, 0] ELSE Vector2.Mul[Vector2.Unit[[v[n].vec.x, v[n].vec.y]], 6.0];
Draw2d.Arrow[context, c, [c.x+v[n].vec.x-a.x, c.y+v[n].vec.y-a.y]];
};
ENDLOOP;
};