Ticket #122: stereo.tcl

File stereo.tcl, 3.8 KB (added by gregcouch@…, 3 years ago)
Line 
1#!/bin/sh
2# the next line restarts using tclsh \
3exec tclsh "$0" "$@"
4
5# $Id: stereo.tcl,v 1.10 2009/02/07 07:04:50 gregcouch Exp $
6
7# Togl - a Tk OpenGL widget
8# Copyright (C) 1996  Brian Paul and Ben Bederson
9# Copyright (C) 2006-2009  Greg Couch
10# See the LICENSE file for copyright details.
11
12# add parent directory to path to find Togl's pkgIndex in current directory
13if { [file exists pkgIndex.tcl] } {
14    set auto_path [linsert $auto_path 0 ..]
15}
16# following load also loads Tk and Togl packages
17load [file dirname [info script]]/stereo[info sharedlibextension]
18
19# create ::stereo namespace
20namespace eval ::stereo {
21}
22
23variable stereo::mode none
24proc stereo::setup {} {
25        grid rowconfigure . 0 -weight 1 -minsize 200p
26        grid columnconfigure . 1 -weight 1 -minsize 200p
27        labelframe .c -text "Stereo mode:"
28        grid .c -padx 2 -pady 2 -ipadx 2 -ipady 1
29        # add "nvidia" to list below when it works
30        foreach {b} {none native sgioldstyle anaglyph cross-eye wall-eye DTI "left eye" "right eye" } {
31                set name [string map {- _ " " _} $b]
32                radiobutton .c.b$name -text "$b" -command "::stereo::makeGraphics {$b}" -variable stereo::mode -value "$b"
33                pack .c.b$name -padx 2 -pady 1 -anchor w
34        }
35        scale .sx -label {X Axis} -from 0 -to 360 -command {::stereo::setAngle x} -orient horizontal
36        grid .sx -columnspan 2 -sticky ew
37        scale .sy -label {Y Axis} -from 0 -to 360 -command {::stereo::setAngle y} -orient horizontal
38        grid .sy -columnspan 2 -sticky ew
39        if {[string first IRIX $::tcl_platform(os)] != -1} {
40                label .irix -justify left -wraplength 250p -text "Use /usr/gfx/setmon or /usr/bin/X11/xsetmon to change video mode for native stereo (eg., 1024x768_120s) or sgioldstyle stereo (eg., str_bot) and back."
41                grid .irix -sticky new -columnspan 2
42        }
43        button .quit -text Close -command exit
44        grid .quit -sticky se -columnspan 2 -padx 2 -pady 2
45        frame .f -relief groove -borderwidth 2 -bg black
46        grid .f -row 0 -column 1 -sticky news
47        bind . <Key-Escape> {exit}
48        label .f.error -wraplength 100p -bg black -fg white
49        ::stereo::makeGraphics $stereo::mode
50}
51
52set stereo::count 0
53set stereo::oldname ""
54proc stereo::makeGraphics {mode} {
55        incr stereo::count
56        set name .f.gr$stereo::count
57        set width 200
58        set height 200
59        if { "$mode" == "nvidia" } {
60                set mode "nvidia consumer stereo"
61                set name ".gr$stereo::count"
62                foreach s [grid slaves .] {
63                        grid forget $s
64                }
65                wm attributes . -fullscreen 1
66                set width [winfo screenwidth .]
67                set height [winfo screenheight .]
68        }
69        if { [catch { togl $name -width $width -height $height -rgba true -stereo "$mode" -double true -depth true -sharelist main -create create_cb -display display_cb -reshape reshape_cb -eyeseparation 0.05 -convergence 2.0 } error] } {
70                pack forget $stereo::oldname
71                .f.error configure -text "$error\n\nMake another choice from the stereo modes on the left."
72                pack .f.error -expand 1 -fill both
73        } else {
74                pack forget .f.error
75                $name configure -ident main
76                if { "$stereo::oldname" != "" } {
77                        destroy $stereo::oldname
78                }
79                set stereo::oldname $name
80                pack $name -expand 1 -fill both
81                bind $name <B1-Motion> {
82                        ::stereo::motion_event %W \
83                                [lindex [%W config -width] 4] \
84                                [lindex [%W config -height] 4] %x %y
85                }
86        }
87}
88
89# This is called when mouse button 1 is pressed and moved
90proc stereo::motion_event { widget width height x y } {
91    setXrot $widget [expr 360.0 * $y / $height]
92    setYrot $widget [expr 360.0 * ($width - $x) / $width]
93
94#    .sx set [expr 360.0 * $y / $height]
95#    .sy set [expr 360.0 * ($width - $x) / $width]
96
97    .sx set [getXrot]
98    .sy set [getYrot]
99}
100
101# This is called when a slider is changed.
102proc stereo::setAngle {axis value} {
103    global xAngle yAngle zAngle
104
105    # catch because .f.gr might be a label instead of a Togl widget
106    catch {
107            switch -exact $axis {
108                x {setXrot .f.gr $value}
109                y {setYrot .f.gr $value}
110            }
111    }
112}
113
114if { [info script] == $argv0 } {
115        ::stereo::setup
116}