Graphics.NewbieCubeSpinWithTcl - lordmundi/wikidoctest GitHub Wiki

Newbie Cube Spin with Tcl

« Spin The Cube | NewbieIndex | Spin With Trick »

Goal

Instead of using a C plugin, use a Tcl script.

Douglish

Doug wraps a graphics package called DSP in a Tcl interpreter. This allows Doug developers to write scripts which can directly manipulate and query the rendered scene.

Create Tcl Script For Spinning Cube

| spincube.tcl | || | #!/usr/bin/tclsh proc spincube { } { set pitch [expr [doug.node CUBE get -pitch] + 0.1] set yaw [expr [doug.node CUBE get -yaw] + 0.1] set roll [expr [doug.node CUBE get -roll] + 0.1]

        doug.node CUBE set -pitch $pitch -roll $roll -yaw $yaw
}

doug.callback add timer -delay 0.001 "spincube" |

| % cd ${USERDATA}/gui % vi spincube.tcl # Make file with contents seen above |

Add GUI Element To User Config File

| | || | DOUG { GUI { spincube "${USERDATA}/gui/spincube.tcl" } } | | % vi ${USERDATA}/user.cfg % Add the block shown above into the DISPLAY { CUBE {}} block. |

Note, you will need to undo the changes from the last section, if you haven't already. One thing that's easy to do while you're doing these tutorials is to save off different userdata.(saved_state) directories. That way you can always go back to them just by setting your USERDATA environment variable back to a saved state, like this example:

% setenv USERDATA ${DOUG_HOME}/userdata.spin_plugin

Well now that you've configured everything, and saved old states because you care about history, go ahead and run, making sure you have your current USERDATA environment…

Run

% cd ${DOUG_HOME}
 % ./run_graphics ; # the cube should spin

« Spin The Cube | NewbieIndex | Spin With Trick »