OUTPUT BUFFER:
# Copyright: 2006-2010 Paul Obermeier (obermeier@tcl3d.org) # # See the file "Tcl3D_License.txt" for information on # usage and redistribution of this file, and for a # DISCLAIMER OF ALL WARRANTIES. # # Module: Tcl3D -> tcl3dOde # Filename: odeGravity.tcl # # Author: Paul Obermeier # # Description: Tcl3D Ode example: Bodies influenced by gravity. # Based on PyODE Tutorial 1 By Matthias Baas. package require Tk package require tcl3d 0.5.0 if { [info procs tcl3dHaveOde] ne "" } { if { ![tcl3dHaveOde] } { tk_messageBox -icon error -type ok -title "Error" \ -message "You do not have ODE installed." exit } } # Show errors occuring in the Togl callbacks. proc bgerror { msg } { tk_messageBox -icon error -type ok -message "Error: $msg\n\n$::errorInfo" exit } # Print info message into widget a the bottom of the window. proc PrintInfo { msg } { if { [winfo exists .fr.info] } { .fr.info configure -text $msg } } proc Cleanup {} { .fr.toglwin delete $::id1 $::id2 } proc ExitProg {} { exit } proc StartAnimation {} { if { [info exists ::animateId] } { return } set x1 0 set y1 2 set z1 0 set x2 1 set y2 2 set z2 0 set ::world [dWorldCreate] dWorldSetGravity $::world 0 -9.81 0 set body1 [dBodyCreate $::world] set body2 [dBodyCreate $::world] set M [new_dMass] dMassSetZero $M dMassSetSphere $M 2500 0.05 dMassAdjust $M 1.0 dBodySetMass $body1 $M dMassAdjust $M 1.5 dBodySetMass $body2 $M dBodySetPosition $body1 $x1 $y1 $z1 dBodyAddForce $body1 0 200 0 dBodySetPosition $body2 $x2 $y2 $z2 dBodyAddForce $body2 0 200 0 set ::total_time 0.0 set ::dt 0.04 animate $body1 $body2 } proc StopAnimation {} { if { [info exists ::animateId] } { after cancel $::animateId unset ::animateId } } proc animate { body1 body2 } { set pos [dBodyGetPosition $body1] set x1 [dReal_getitem $pos 0] set y1 [dReal_getitem $pos 1] set z1 [dReal_getitem $pos 2] .fr.toglwin coords $::id1 \ [expr 200 + $x1*100-5] [expr 600 - $y1*100-5] \ [expr 200 + $x1*100+5] [expr 600 - $y1*100+5] set pos [dBodyGetPosition $body2] set x2 [dReal_getitem $pos 0] set y2 [dReal_getitem $pos 1] set z2 [dReal_getitem $pos 2] .fr.toglwin coords $::id2 \ [expr 200 + $x2*100-5] [expr 600 - $y2*100-5] \ [expr 200 + $x2*100+5] [expr 600 - $y2*100+5] dWorldStep $::world $::dt set ::total_time [expr $::total_time + $::dt] update idletasks after 100 if { $y1 < 0.0 || $y2 < 0.0 } { StopAnimation } set ::animateId [tcl3dAfterIdle "animate $body1 $body2"] } # Master frame. Needed to integrate demo into Tcl3D Starpack presentation. frame .fr pack .fr -expand 1 -fill both canvas .fr.toglwin -width 400 -height 600 -bg white label .fr.info grid .fr.toglwin -row 0 -column 0 -sticky news grid .fr.info -row 1 -column 0 -sticky news grid rowconfigure .fr 0 -weight 1 grid columnconfigure .fr 0 -weight 1 # Watch For ESC Key And Quit Messages wm protocol . WM_DELETE_WINDOW "ExitProg" bind .