diff options
| author | Skip Montanaro <[email protected]> | 2021-02-16 14:40:46 -0600 |
|---|---|---|
| committer | Skip Montanaro <[email protected]> | 2021-02-16 14:40:46 -0600 |
| commit | a19a216bc60160c162e616145ef091dd18ce4e61 (patch) | |
| tree | fa4bdff21f9b04a125c84a2bfab8a1c738359e15 /demo/sgi/gl_panel/twoview | |
| download | python-0.9.1-patched-QoL-a19a216bc60160c162e616145ef091dd18ce4e61.tar.xz python-0.9.1-patched-QoL-a19a216bc60160c162e616145ef091dd18ce4e61.zip | |
Python 0.9.1 as posted in alt.sources
Diffstat (limited to 'demo/sgi/gl_panel/twoview')
| -rw-r--r-- | demo/sgi/gl_panel/twoview/block.py | 73 | ||||
| -rw-r--r-- | demo/sgi/gl_panel/twoview/camera.s | 55 | ||||
| -rw-r--r-- | demo/sgi/gl_panel/twoview/observer.s | 98 | ||||
| -rw-r--r-- | demo/sgi/gl_panel/twoview/topview.s | 47 | ||||
| -rwxr-xr-x | demo/sgi/gl_panel/twoview/twoview.py | 395 |
5 files changed, 668 insertions, 0 deletions
diff --git a/demo/sgi/gl_panel/twoview/block.py b/demo/sgi/gl_panel/twoview/block.py new file mode 100644 index 0000000..9ac518d --- /dev/null +++ b/demo/sgi/gl_panel/twoview/block.py @@ -0,0 +1,73 @@ +# module 'block' imported by twoview demo. + +from gl import n3f, bgnpolygon, varray, endpolygon, lmbind +from GL import MATERIAL + +# Draw a single 2x2x2 block with its center at (0, 0, 0) +# Arguments are the material indices (0 = don't call lmbind) +# +def block(m_front, m_back, m_left, m_right, m_top, m_bottom): + # + # Distances defining the sides + # + x_left = -1.0 + x_right = 1.0 + y_top = 1.0 + y_bottom = -1.0 + z_front = 1.0 + z_back = -1.0 + # + # Top surface points: A, B, C, D + # + A = x_right, y_top, z_front + B = x_right, y_top, z_back + C = x_left, y_top, z_back + D = x_left, y_top, z_front + # + # Bottom surface points: E, F, G, H + # + E = x_right, y_bottom, z_front + F = x_right, y_bottom, z_back + G = x_left, y_bottom, z_back + H = x_left, y_bottom, z_front + # + # Draw front face + # + if m_front: lmbind(MATERIAL, m_front) + n3f(0.0, 0.0, 1.0) + face(H, E, A, D) + # + # Draw back face + # + if m_back: lmbind(MATERIAL, m_back) + n3f(0.0, 0.0, -1.0) + face(G, F, B, C) + # + # Draw left face + # + if m_left: lmbind(MATERIAL, m_left) + n3f(-1.0, 0.0, 0.0) + face(G, H, D, C) + # + # Draw right face + # + if m_right: lmbind(MATERIAL, m_right) + n3f(1.0, 0.0, 0.0) + face(F, E, A, B) + # + # Draw top face + # + if m_top: lmbind(MATERIAL, m_top) + n3f(0.0, 1.0, 0.0) + face(A, B, C, D) + # + # Draw bottom face + # + if m_bottom: lmbind(MATERIAL, m_bottom) + n3f(0.0, -1.0, 0.0) + face(E, F, G, H) + +def face(points): + bgnpolygon() + varray(points) + endpolygon() diff --git a/demo/sgi/gl_panel/twoview/camera.s b/demo/sgi/gl_panel/twoview/camera.s new file mode 100644 index 0000000..f61a58e --- /dev/null +++ b/demo/sgi/gl_panel/twoview/camera.s @@ -0,0 +1,55 @@ +;;; This file was automatically generated by the panel editor. +;;; If you read it into gnu emacs, it will automagically format itself. + +(panel (prop help creator:user-panel-help) +(prop user-panel #t) +(label "Camera Control") +(x 1010) +(y 589) +(al (pnl_wide_button (name "quitbutton") +(prop help creator:user-act-help) +(label "quit") +(x 3.5) +(y 1) +(w 0.94) +(downfunc move-then-resize) +) +(pnl_filled_hslider (name "farclip") +(prop help creator:user-act-help) +(label "far clipping plane") +(x 1.25) +(y 3.5) +(w 3.3) +(h 0.4) +(val 0.752) +(downfunc move-then-resize) +) +(pnl_filled_hslider (name "nearclip") +(prop help creator:user-act-help) +(label "near clipping plane") +(x 1.25) +(y 4.5) +(w 3.3) +(h 0.4) +(val 0.17) +(downfunc move-then-resize) +) +(pnl_filled_vslider (name "zoom") +(prop help creator:user-act-help) +(label "zoom") +(x 0.2) +(y 1.25) +(w 0.4) +(h 3.9) +(val 0.344) +(downfunc move-then-resize) +) +) +) +;;; Local Variables: +;;; mode: scheme +;;; eval: (save-excursion (goto-char (point-min)) (kill-line 3)) +;;; eval: (save-excursion (goto-char (point-min)) (replace-regexp "[ \n]*)" ")")) +;;; eval: (indent-region (point-min) (point-max) nil) +;;; eval: (progn (kill-line -3) (delete-backward-char 1) (save-buffer)) +;;; End: diff --git a/demo/sgi/gl_panel/twoview/observer.s b/demo/sgi/gl_panel/twoview/observer.s new file mode 100644 index 0000000..ddcfe7a --- /dev/null +++ b/demo/sgi/gl_panel/twoview/observer.s @@ -0,0 +1,98 @@ +;;; This file was automatically generated by the panel editor. +;;; If you read it into gnu emacs, it will automagically format itself. + +(panel (prop help creator:user-panel-help) +(prop user-panel #t) +(label "Observer Control") +(x 876) +(y 10) +(al (pnl_right_arrow_button (name "right") +(prop help creator:user-act-help) +(x 3.2) +(y 2.09) +(downfunc move-then-resize) +) +(pnl_up_double_arrow_button (name "fast_forward") +(prop help creator:user-act-help) +(label "step forward") +(x 2.66) +(y 3.13) +(h 0.45) +(labeltype 4) +(downfunc move-then-resize) +) +(pnl_up_arrow_button (name "forward") +(prop help creator:user-act-help) +(x 2.66) +(y 2.64) +(downfunc move-then-resize) +) +(pnl_down_arrow_button (name "reverse") +(prop help creator:user-act-help) +(x 2.66) +(y 1.49) +(h 0.45) +(labeltype 12) +(downfunc move-then-resize) +) +(pnl_down_double_arrow_button (name "fast_reverse") +(prop help creator:user-act-help) +(label "step back") +(x 2.66) +(y 1) +(labeltype 12) +(downfunc move-then-resize) +) +(pnl_left_arrow_button (name "left") +(prop help creator:user-act-help) +(x 2.11) +(y 2.09) +(downfunc move-then-resize) +) +(pnl_right_double_arrow_button (name "fast_right") +(prop help creator:user-act-help) +(label "turn right") +(x 3.75) +(y 2.09) +(downfunc move-then-resize) +) +(pnl_left_double_arrow_button (name "fast_left") +(prop help creator:user-act-help) +(label "turn left") +(x 1.57) +(y 2.09) +(labeltype 8) +(downfunc move-then-resize) +) +(pnl_vslider (name "ypos") +(prop help creator:user-act-help) +(x 6.25) +(y 1) +(w 0.4) +(h 2.9) +(val 0.0758) +(downfunc move-then-resize) +) +(pnl_down_arrow_button (name "down") +(prop help creator:user-act-help) +(label "eye height") +(x 6.25) +(y 0.5) +(labeltype 12) +(downfunc move-then-resize) +) +(pnl_up_arrow_button (name "up") +(prop help creator:user-act-help) +(x 6.25) +(y 4) +(downfunc move-then-resize) +) +) +) +;;; Local Variables: +;;; mode: scheme +;;; eval: (save-excursion (goto-char (point-min)) (kill-line 3)) +;;; eval: (save-excursion (goto-char (point-min)) (replace-regexp "[ \n]*)" ")")) +;;; eval: (indent-region (point-min) (point-max) nil) +;;; eval: (progn (kill-line -3) (delete-backward-char 1) (save-buffer)) +;;; End: diff --git a/demo/sgi/gl_panel/twoview/topview.s b/demo/sgi/gl_panel/twoview/topview.s new file mode 100644 index 0000000..0e380cc --- /dev/null +++ b/demo/sgi/gl_panel/twoview/topview.s @@ -0,0 +1,47 @@ +;;; This file was automatically generated by the panel editor. +;;; If you read it into gnu emacs, it will automagically format itself. + +(panel (prop help creator:user-panel-help) +(prop user-panel #t) +(label "Top View Control") +(x 1020) +(y 287) +(al (pnl_hslider (name "xpos") +(prop help creator:user-act-help) +(label "X") +(x 2) +(y 0.5) +(w 3.85) +(h 0.4) +(val 0.5) +(downfunc move-then-resize) +) +(pnl_vslider (name "zpos") +(prop help creator:user-act-help) +(label "Z") +(x 1.25) +(y 1.3) +(w 0.4) +(h 3.6) +(val 0.5) +(downfunc move-then-resize) +) +(pnl_dial (name "direction") +(prop help creator:user-act-help) +(label "looking direction") +(x 2.15) +(y 1.4) +(w 3.5) +(h 3.45) +(val 0.5) +(downfunc move-then-resize) +) +) +) +;;; Local Variables: +;;; mode: scheme +;;; eval: (save-excursion (goto-char (point-min)) (kill-line 3)) +;;; eval: (save-excursion (goto-char (point-min)) (replace-regexp "[ \n]*)" ")")) +;;; eval: (indent-region (point-min) (point-max) nil) +;;; eval: (progn (kill-line -3) (delete-backward-char 1) (save-buffer)) +;;; End: diff --git a/demo/sgi/gl_panel/twoview/twoview.py b/demo/sgi/gl_panel/twoview/twoview.py new file mode 100755 index 0000000..eea7c75 --- /dev/null +++ b/demo/sgi/gl_panel/twoview/twoview.py @@ -0,0 +1,395 @@ +#! /ufs/guido/bin/sgi/python + +# A demo of GL's viewing transformations, showing two views on one scene. +# Requires the NASA AMES Panel Library. Requires Z buffer. + +from gl import * +from GL import * +import panel +from math import sin, cos, pi + +inf = 1000000.0 +far = 1000.0 +near = 100.0 + +def main(): + foreground() + # + keepaspect(1, 1) + prefposition(10, 610, 10, 610) + obswid = winopen('Observer View') + doublebuffer() + RGBmode() + gconfig() + # + keepaspect(1, 1) + prefposition(10, 310, 650, 950) + topwid = winopen('Top View') + doublebuffer() + RGBmode() + gconfig() + # + panels = panel.defpanellist('observer.s') + panels = panels + panel.defpanellist('camera.s') + panels = panels + panel.defpanellist('topview.s') + # + p = panels[0] + q = panels[1] + r = panels[2] + # + p.farclip = q.farclip + p.nearclip = q.nearclip + p.zoom = q.zoom + p.quitbutton = q.quitbutton + # + p.xpos = r.xpos + p.zpos = r.zpos + p.direction = r.direction + # + p.direction.winds = 1.0 # allow full rotation + # + def quit(act): + import sys + sys.exit(0) + p.quitbutton.downfunc = quit + # + p.left.back = p + p.fast_left.back = p + p.right.back = p + p.fast_right.back = p + p.forward.back = p + p.fast_forward.back = p + p.reverse.back = p + p.fast_reverse.back = p + p.up.back = p + p.down.back = p + # + p.left.activefunc = left + p.fast_left.activefunc = fast_left + p.right.activefunc = right + p.fast_right.activefunc = fast_right + p.forward.activefunc = forward + p.fast_forward.activefunc = fast_forward + p.reverse.activefunc = reverse + p.fast_reverse.activefunc = fast_reverse + p.up.activefunc = up + p.down.activefunc = down + # + makeobjects() + # + drawall(p, obswid, topwid) + panel.needredraw() + while 1: + act = panel.dopanel() + if panel.userredraw() or act: + drawall(p, obswid, topwid) + +def left(a): + doturn(a.back, 0.01) + +def fast_left(a): + doturn(a.back, 0.1) + +def right(a): + doturn(a.back, -0.01) + +def fast_right(a): + doturn(a.back, -0.1) + +def doturn(p, angle): + alpha = lookangle(p) + angle + # Reverse the following assignment: + # alpha = pi*1.5 - p.direction.val*2.0*pi + val = (pi*1.5 - alpha) / 2.0 / pi + while val < 0.0: val = val + 1.0 + while val > 1.0: val = val - 1.0 + p.direction.val = val + p.direction.fixact() + +def forward(a): + dostep(a.back, 1.0) + +def fast_forward(a): + dostep(a.back, 10.0) + +def reverse(a): + dostep(a.back, -1.0) + +def fast_reverse(a): + dostep(a.back, -10.0) + +def dostep(p, step): + x, y, z = observerpos(p) + alpha = lookangle(p) + x = x + step*cos(alpha) + z = z - step*sin(alpha) + # Reverse the following assignments: + # x = 2.0 * p.xpos.val * near - near + # z = near - 2.0 * p.zpos.val * near + p.xpos.val = (x + near) / 2.0 / near + p.zpos.val = - (z - near) / 2.0 / near + p.xpos.fixact() + p.zpos.fixact() + +def up(a): + doup(a.back, 0.2) + +def down(a): + doup(a.back, -0.2) + +def doup(p, step): + x, y, z = observerpos(p) + y = y + step + # Reverse: + # y = p.ypos.val * near + p.ypos.val = y/near + p.ypos.fixact() + +def drawall(p, obswid, topwid): + # + winset(obswid) + obsview(p) + drawscene() + swapbuffers() + # + winset(topwid) + topview(p) + drawscene() + drawobserver(p) + swapbuffers() + +def drawobserver(p): + x, y, z = observerpos(p) + alpha = lookangle(p) + fov = 2.0 + 1798.0 * p.zoom.val + beta = fov*pi/3600.0 # Half fov, expressed in radians + # + c3i(0, 255, 0) + # + move(x, y, z) + x1 = x + inf*cos(alpha+beta) + y1 = y + z1 = z - inf*sin(alpha+beta) + draw(x1, y1, z1) + # + move(x, y, z) + x1 = x + inf*cos(alpha-beta) + y1 = y + z1 = z - inf*sin(alpha-beta) + draw(x1, y1, z1) + +def observerlookat(p): + x, y, z = observerpos(p) + alpha = lookangle(p) + return x, y, z, x+near*cos(alpha), y, z-near*sin(alpha), 0 + +def observerpos(p): + x = 2.0 * p.xpos.val * near - near + y = p.ypos.val * near + z = near - 2.0 * p.zpos.val * near + return x, y, z + +def lookangle(p): + return pi*1.5 - p.direction.val*2.0*pi + +idmat = 1,0,0,0, 0,1,0,0, 0,0,1,0, 0,0,0,1 + +def topview(p): + mmode(MVIEWING) + ortho(-far, far, -far, far, far, -far) + loadmatrix(idmat) + rotate(900, 'x') + +def obsview(p): + fov = 2.0 + 1798.0 * p.zoom.val + nearclip = p.nearclip.val * 10.0 + farclip = p.farclip.val * 10.0*far + aspectratio = 1.0 + mmode(MVIEWING) + perspective(int(fov), aspectratio, nearclip, farclip) + loadmatrix(idmat) + lookat(observerlookat(p)) + +def drawscene(): + # + # clear window + # + c3i(0, 0, 0) + clear() + # + # turn on z buffering and clear it + # + zbuffer(TRUE) + zclear() + # + # dark blue sky (depending on your gamma value!) + # + c3i(0, 0, 150) + callobj(41) + # + # bright red near and far units circle + # (use rotate since circ() always draws in x-y plane) + # + c3i(255, 0, 0) + pushmatrix() + rotate(900, 'x') + circ(0.0, 0.0, near) + circ(0.0, 0.0, far) + popmatrix() + # + # bright white striping + # + c3i(255, 255, 200) + callobj(42) + # + # building (does its own colors) + # + building() + # + # some other objects + # + dice() + +def makeobjects(): + # + # sky object + # + makeobj(41) + pmv(-inf, 0.0, -far) + pdr(inf, 0.0, -far) + pdr(inf, inf, -far) + pdr(-inf, inf, -far) + pclos() + closeobj() + # + # road stripes object + # + makeobj(42) + stripes() + closeobj() + # + # lighting model definitions + # + deflight() + +def stripes(): + # + # left line + # + botrect(-11, -10, far, -far) + # + # right line + # + botrect(10, 11, far, -far) + # + # center lines + # + z = far + while z > -far: + botrect(-0.5, 0.5, z, z - 4.0) + z = z - 10.0 + +def dice(): + from block import block + uselight() + pushmatrix() + translate(0.0, 1.0, -20.0) + rotate(200, 'y') + block(1, 0, 0, 0, 0, 0) + translate(1.0, 0.0, 3.0) + rotate(500, 'y') + block(2, 0, 0, 0, 0, 0) + popmatrix() + +def deflight(): + # Material for first die (red) + lmdef(DEFMATERIAL, 1, (DIFFUSE, 1.0, 0.0, 0.0)) + # Material for second die (green) + lmdef(DEFMATERIAL, 2, (DIFFUSE, 0.0, 1.0, 0.0)) + # First light source (default: white, from front) + lmdef(DEFLIGHT, 1, ()) + # Second light source (red, from back) + lmdef(DEFLIGHT, 2, (POSITION, 0.0, 1.0, -1.0, 0.0)) + lmdef(DEFLIGHT, 2, (LCOLOR, 1.0, 0.0, 0.0)) + # Lighting model + lmdef(DEFLMODEL, 1, (AMBIENT, 0.0, 0.0, 1.0)) + +def uselight(): + lmbind(LIGHT0, 1) + lmbind(LIGHT1, 2) + lmbind(LMODEL, 1) + # (materials are bound later) + +def building(): + # + c3i(0, 255, 255) + # + # house bounding coordinates + # + x1 = 20.0 + x1a = 25.0 + x2 = 30.0 + y1 = 0.0 + y2 = 15.0 + y2a = 20.0 + z1 = -40.0 + z2 = -55.0 + # + # door y and z coordinates + # + dy1 = 0.0 + dy2 = 4.0 + dz1 = -45.0 + dz2 = -47.0 + # + # front side (seen from origin) + # + A1 = (x1, y1, z1) + B1 = (x2, y1, z1) + C1 = (x2, y2, z1) + D1 = (x1a, y2a, z1) + E1 = (x1, y2, z1) + # + # back size + # + A2 = (x1, y1, z2) + B2 = (x2, y1, z2) + C2 = (x2, y2, z2) + D2 = (x1a, y2a, z2) + E2 = (x1, y2, z2) + # + # door in the left side + # + P = x1, dy1, dz2 + Q = x1, dy2, dz2 + R = x1, dy2, dz1 + S = x1, dy1, dz1 + # + # draw it + # + concave(TRUE) + c3i(255, 0, 0) + face(A1, B1, C1, D1, E1) + c3i(127, 127, 0) + face(A1, E1, E2, A2, P, Q, R, S) + c3i(0, 255, 0) + face(E1, D1, D2, E2) + c3i(0, 127, 127) + face(D1, C1, C2, D2) + c3i(0, 0, 255) + face(C1, B1, B2, C2) + c3i(127, 0, 127) + face(E2, D2, C2, B2, A2) + concave(FALSE) + +def face(points): + bgnpolygon() + varray(points) + endpolygon() + +# draw a rectangle at y=0.0 +# +def botrect(x1, x2, z1, z2): + polf(x1, 0.0, z1, x2, 0.0, z1, x2, 0.0, z2, x1, 0.0, z2) + +main() |
