sourceextensions/scene/lib/Scene.xtl

1⍝# Scene.xtl -- the facade of the scene extension: retained 3D line and 2⍝# point scenes in a native window, patched by id, the mouse orbiting. 3⍝# Import: "sc:" u_se< "Scene" 4⍝# Run with xetal-x, which links scene and serves its windows on the main 5⍝# thread (xetal-x --ext DIR puts this directory on XETAL_PATH). 6⍝# Each signature line is written out by the binding macro (lib/Ffi.xtlm). 7 8ᶠᶠⁱ⁼u̲se< "Ffi" 9 10⍝# title sc:o_pen! width height: a scene window that size (points); its id. 11"o_pen! : text float -> int" ᶠᶠⁱb̲ind< "scene/open"
ᶠᶠⁱb̲ind< expands to
ˡo̲pen! ← { a b →
  pa ← a ⎕N̲PUT "ext:scene/open?text"
  pb ← (f̲ormat r̲avel f̲loat b) ⎕N̲PUT "ext:scene/open?float=" c̲at f̲ormat s̲hape b
  f̲loor f̲irst n̲umbers ⎕N̲GET "ext:scene/open"
}
12⍝# (scene c_at object c_at red green blue) sc:p_olyline! points: put 13⍝# object (an id of your choice) as points joined in order; points are an 14⍝# n by 3 matrix (x y z), colors 0 to 1. Putting an id again replaces it. 15"p_olyline! : float float -> int" ᶠᶠⁱb̲ind< "scene/polyline"
ᶠᶠⁱb̲ind< expands to
ˡp̲olyline! ← { a b →
  pa ← (f̲ormat r̲avel f̲loat a) ⎕N̲PUT "ext:scene/polyline?float=" c̲at f̲ormat s̲hape a
  pb ← (f̲ormat r̲avel f̲loat b) ⎕N̲PUT "ext:scene/polyline?float=" c̲at f̲ormat s̲hape b
  f̲loor f̲irst n̲umbers ⎕N̲GET "ext:scene/polyline"
}
16⍝# header sc:s_egments! points: the points taken in pairs, each a segment. 17"s_egments! : float float -> int" ᶠᶠⁱb̲ind< "scene/segments"
ᶠᶠⁱb̲ind< expands to
ˡs̲egments! ← { a b →
  pa ← (f̲ormat r̲avel f̲loat a) ⎕N̲PUT "ext:scene/segments?float=" c̲at f̲ormat s̲hape a
  pb ← (f̲ormat r̲avel f̲loat b) ⎕N̲PUT "ext:scene/segments?float=" c̲at f̲ormat s̲hape b
  f̲loor f̲irst n̲umbers ⎕N̲GET "ext:scene/segments"
}
18⍝# header sc:d_ots! points: each point a dot. 19"d_ots! : float float -> int" ᶠᶠⁱb̲ind< "scene/dots"
ᶠᶠⁱb̲ind< expands to
ˡd̲ots! ← { a b →
  pa ← (f̲ormat r̲avel f̲loat a) ⎕N̲PUT "ext:scene/dots?float=" c̲at f̲ormat s̲hape a
  pb ← (f̲ormat r̲avel f̲loat b) ⎕N̲PUT "ext:scene/dots?float=" c̲at f̲ormat s̲hape b
  f̲loor f̲irst n̲umbers ⎕N̲GET "ext:scene/dots"
}
20⍝# header sc:q_uads! points: the points taken in fours, each the corners 21⍝# of a filled quad in order round it (4n by 3); shaded by how it faces 22⍝# the light, nearer quads hiding farther ones; lines and dots draw over. 23"q_uads! : float float -> int" ᶠᶠⁱb̲ind< "scene/quads"
ᶠᶠⁱb̲ind< expands to
ˡq̲uads! ← { a b →
  pa ← (f̲ormat r̲avel f̲loat a) ⎕N̲PUT "ext:scene/quads?float=" c̲at f̲ormat s̲hape a
  pb ← (f̲ormat r̲avel f̲loat b) ⎕N̲PUT "ext:scene/quads?float=" c̲at f̲ormat s̲hape b
  f̲loor f̲irst n̲umbers ⎕N̲GET "ext:scene/quads"
}
24⍝# scene sc:f_og! near far: quads fade into the background between those 25⍝# depths (scene units from the camera); far <= near: no fog. 26"f_og! : float float -> int" ᶠᶠⁱb̲ind< "scene/fog"
ᶠᶠⁱb̲ind< expands to
ˡf̲og! ← { a b →
  pa ← (f̲ormat r̲avel f̲loat a) ⎕N̲PUT "ext:scene/fog?float=" c̲at f̲ormat s̲hape a
  pb ← (f̲ormat r̲avel f̲loat b) ⎕N̲PUT "ext:scene/fog?float=" c̲at f̲ormat s̲hape b
  f̲loor f̲irst n̲umbers ⎕N̲GET "ext:scene/fog"
}
27⍝# scene sc:e_ye! x y z yaw pitch: a first-person camera at the eye, 28⍝# looking along yaw (0 toward -z, turning right toward +x) and pitch (up 29⍝# positive), radians; sc:c_amera! goes back to orbiting. 30"e_ye! : float float -> int" ᶠᶠⁱb̲ind< "scene/eye"
ᶠᶠⁱb̲ind< expands to
ˡe̲ye! ← { a b →
  pa ← (f̲ormat r̲avel f̲loat a) ⎕N̲PUT "ext:scene/eye?float=" c̲at f̲ormat s̲hape a
  pb ← (f̲ormat r̲avel f̲loat b) ⎕N̲PUT "ext:scene/eye?float=" c̲at f̲ormat s̲hape b
  f̲loor f̲irst n̲umbers ⎕N̲GET "ext:scene/eye"
}
31⍝# scene sc:c_urve! radius: a curved horizon for the first-person 32⍝# camera -- the world lowered by d^2 / 2R at a distance d along the 33⍝# ground from the eye, as on a small planet; 0 turns it off. 34"c_urve! : float float -> int" ᶠᶠⁱb̲ind< "scene/curve"
ᶠᶠⁱb̲ind< expands to
ˡc̲urve! ← { a b →
  pa ← (f̲ormat r̲avel f̲loat a) ⎕N̲PUT "ext:scene/curve?float=" c̲at f̲ormat s̲hape a
  pb ← (f̲ormat r̲avel f̲loat b) ⎕N̲PUT "ext:scene/curve?float=" c̲at f̲ormat s̲hape b
  f̲loor f̲irst n̲umbers ⎕N̲GET "ext:scene/curve"
}
35⍝# scene sc:s_ky! red green blue: the background, which fog fades to 36⍝# (0 to 1); -1 -1 -1 goes back to the dark default. 37"s_ky! : float float -> int" ᶠᶠⁱb̲ind< "scene/sky"
ᶠᶠⁱb̲ind< expands to
ˡs̲ky! ← { a b →
  pa ← (f̲ormat r̲avel f̲loat a) ⎕N̲PUT "ext:scene/sky?float=" c̲at f̲ormat s̲hape a
  pb ← (f̲ormat r̲avel f̲loat b) ⎕N̲PUT "ext:scene/sky?float=" c̲at f̲ormat s̲hape b
  f̲loor f̲irst n̲umbers ⎕N̲GET "ext:scene/sky"
}
38⍝# sc:c_ontrols scene: how far the mouse was dragged since last asked (x 39⍝# y, pixels), then 1 or 0 for each key held -- w a s d space shift and 40⍝# the arrows left right up down. Headless, XETAL_EVENTS may hold 41⍝# "keydown w", "keyup w" and "drag 10 0". 42"c_ontrols : float -> floats" ᶠᶠⁱb̲ind< "scene/controls"
ᶠᶠⁱb̲ind< expands to
ˡc̲ontrols ← { a →
  pa ← (f̲ormat r̲avel f̲loat a) ⎕N̲PUT "ext:scene/controls?float=" c̲at f̲ormat s̲hape a
  v ← n̲umbers ⎕N̲GET "ext:scene/controls"
  (f̲loor n̲umbers ⎕N̲GET "ext:scene/controls?shape") r̲eshape v
}
43⍝# scene sc:r_emove! object: 1 if it was there, else 0. 44"r_emove! : float float -> int" ᶠᶠⁱb̲ind< "scene/remove"
ᶠᶠⁱb̲ind< expands to
ˡr̲emove! ← { a b →
  pa ← (f̲ormat r̲avel f̲loat a) ⎕N̲PUT "ext:scene/remove?float=" c̲at f̲ormat s̲hape a
  pb ← (f̲ormat r̲avel f̲loat b) ⎕N̲PUT "ext:scene/remove?float=" c̲at f̲ormat s̲hape b
  f̲loor f̲irst n̲umbers ⎕N̲GET "ext:scene/remove"
}
45⍝# scene sc:c_amera! yaw pitch distance spin: where the camera orbits from 46⍝# (radians, scene units) and how fast it turns by itself (radians a second). 47"c_amera! : float float -> int" ᶠᶠⁱb̲ind< "scene/camera"
ᶠᶠⁱb̲ind< expands to
ˡc̲amera! ← { a b →
  pa ← (f̲ormat r̲avel f̲loat a) ⎕N̲PUT "ext:scene/camera?float=" c̲at f̲ormat s̲hape a
  pb ← (f̲ormat r̲avel f̲loat b) ⎕N̲PUT "ext:scene/camera?float=" c̲at f̲ormat s̲hape b
  f̲loor f̲irst n̲umbers ⎕N̲GET "ext:scene/camera"
}
48⍝# sc:n_ext! scene: the next event, waiting at most a frame (1/60 s): 49⍝# "frame", "key Space", "key q", "close". Dragging orbits by itself. 50"n_ext! : float -> text" ᶠᶠⁱb̲ind< "scene/next"
ᶠᶠⁱb̲ind< expands to
ˡn̲ext! ← { a →
  pa ← (f̲ormat r̲avel f̲loat a) ⎕N̲PUT "ext:scene/next?float=" c̲at f̲ormat s̲hape a
  ⎕N̲GET "ext:scene/next"
}
51⍝# sc:c_lose! scene: close the window; 1. 52"c_lose! : float -> int" ᶠᶠⁱb̲ind< "scene/close"
ᶠᶠⁱb̲ind< expands to
ˡc̲lose! ← { a →
  pa ← (f̲ormat r̲avel f̲loat a) ⎕N̲PUT "ext:scene/close?float=" c̲at f̲ormat s̲hape a
  f̲loor f̲irst n̲umbers ⎕N̲GET "ext:scene/close"
}
53 54⍝# The native package behind these functions. 55ˡpackage ← "scene"