;; Fu Jie Huang, Feb 2003
;; this script shows how to use Timer sensor for animation
;; a timer sensor is attached to the rotation object
;; after each second, the sensor modifies the rotation object value

(libload "inventor/inventor")
(libload "inventor/inventorxt")

(setq mywindow (soxt_init "lush"))
(setq root  (new soseparator ()))
(setq mymaterial (new somaterial ()))
(setq mylight   (new sodirectionallight ()))
(setq mycone (new socone ()))
(setq myrotation (new sorotation ()))

(==> root ref)
(==> root addChild :mylight:p)
(==> (==> mymaterial getmf_diffusecolor) setvalue 1.0 0.0 0.0)
(==> root addChild :mymaterial:p)
(==> root addChild :myrotation:p)
(==> root addChild :mycone:p)

(setq myviewer (new soxtexaminerviewer mywindow "test" 1 1 1 ()))
(==> myviewer setscenegraph :root:p)
(==> myviewer show)

(de rotatingsensorcb ( data sensor )
  (cpheader "#include <Inventor/nodes/SoRotation.h>")
  ((-gptr-) data)
  ((-gptr- "SoSensor *") sensor)
  #{ {
          SoRotation *myRotation = (SoRotation *)$data;
          SbRotation currentRotation = myRotation->rotation.getValue();
          currentRotation = SbRotation(SbVec3f(0,0,1), M_PI/90.0) * 
                                                   currentRotation;
          myRotation->rotation.setValue(currentRotation);
  } #}
  ())
(dhc-make-with-c++ () ()  rotatingsensorcb)

;;**********************************************************************
(setq mysensor (new SoTimerSensor ()  (gptr rotatingsensorcb) :myrotation:p ))
(let ((intv (new sbtime ())))
  (==> intv setvalue 1.0)
  (==> mysensor setinterval :intv:p))
(==> mysensor schedule)
;;**********************************************************************

(soxt_show mywindow)

