home *** CD-ROM | disk | FTP | other *** search
/ Virtual Reality Zone / VRZONE.ISO / mac / PC / MISC3D / EEDEMO / TEST3.BOB < prev    next >
Text File  |  1993-08-13  |  2KB  |  143 lines

  1. class Task //the base task class
  2. {
  3.   tsk;
  4.   nframes;
  5.   obj;
  6.   func;
  7.   period;
  8. }
  9. Task::Task( ob, fn, per )
  10. {
  11.   nframes = 0;
  12.   tsk = 0;
  13.   obj = ob;
  14.   func = fn;
  15.   period = per;
  16.   return this;
  17. }
  18. Task::Start()
  19. {
  20.   if( !tsk )
  21.   tsk = ScheduleTask( this, obj, func, period );
  22. }
  23. Task::Kill()
  24. {
  25.   if( tsk ) {
  26.     DeleteTask( tsk );
  27.     tsk = 0;
  28.   }
  29. }
  30.  
  31. class c6 : Task
  32. {
  33.   x; y; z;
  34. }
  35. c6::c6( obj, fn, p )
  36. {
  37.   x = -50;
  38.   Task(obj, fn, p);
  39.   return this;
  40. }
  41. c6::spinner()
  42. {
  43.     Rotate( 0, 15, 0 );
  44.     if( nframes++ == 30 ) {
  45.         Kill();
  46.         func = "mover";
  47.         period = 30;
  48.         Start();
  49.         nframes = 0;
  50.     }
  51. }
  52. c6::mover()
  53. {
  54.     if(nframes++ == 100) {
  55.         Kill();
  56.         func = "spinner";
  57.         Start();
  58.         x *= -1;
  59.         nframes = 0;
  60.     }
  61.     Move( x, 0, 0 );
  62. }
  63.  
  64. moveit()        //the variables used in this function are globals
  65. {               //which were created in main()
  66.     if((nFrame % 30) == 0)
  67.         dy *= -1;
  68.     if((nFrame++ % 20) == 0)
  69.         dx *= -1;
  70.     Move( dx, dy, dz ); 
  71. }
  72.  
  73. spinner()
  74. {
  75.     Rotate( 0, -15, 0 );
  76. }
  77.  
  78. class Vmove : Task
  79. {
  80.   xo, cmcnt, cdx;
  81. }
  82.  
  83. Vmove::Vmove(obj, fn, p)
  84. {
  85.   xo = 0; 
  86.   cdx = 400;
  87.   Task( obj, fn,p );
  88.   return this;
  89. }
  90. Vmove::turn(angle;a,i,n) 
  91. {
  92. a=3;
  93.   n = angle/a;
  94.   if (n<0) n *= -1; //watch out for neg angles
  95.   for( i=0; i<n; i++ ) {
  96.     TurnCamera( 0, a, 0 );
  97.     EventLoop(); //refresh display and collect user input
  98.   }
  99. }
  100. Vmove::move(;area)
  101. {
  102.     if( nframes++ == 60)
  103.         Kill();
  104.     if( (xo < 4500) && (xo > -5500) ) {
  105.         MoveCamera(cdx,0,0);
  106.         xo += cdx;
  107.     }
  108.     else {
  109.         turn(180);
  110.         //cdx *= -1;
  111.         area = GetArea(); //a little test
  112.         PopMsg(area);
  113.         GetKey();
  114.         xo = 0;
  115.     }
  116. }
  117.  
  118. main(;conetsk,cmtsk)
  119. {
  120. // Global Variables
  121. dx = 60; 
  122. dy = 10; 
  123. dz = 0;
  124. nFrame = 0;
  125.  
  126.     // call ScheduleTask with 0 as first parameter when you use
  127.     // a normal function instead of a class object.
  128.     conetsk = ScheduleTask(0,"cone1", "moveit", 80);
  129.     cmtsk = ScheduleTask(0,"mh", "spinner", 10);
  130.  
  131.     // c6tsk is an instance of the c6 class, which inherits from Task...
  132.     c6tsk = new c6("c6", "spinner", 50);
  133.     
  134.     // if your Task doesn't manipulate any objects in space, then pass
  135.     // a bogus name, like "null"
  136.     vm = new Vmove("null","move",30);
  137.  
  138.     // calls the virtual function from base class Task...
  139.     c6tsk->Start();
  140.     vm->Start();
  141. }
  142.  
  143.