home *** CD-ROM | disk | FTP | other *** search
/ Best Tools for JAVA / Best Tools for JAVA.iso / JAVA_ALL / IDE / SUBARTIC / RELEASE.ZIP / sub_arctic / anim / simple_transition.java < prev    next >
Encoding:
Java Source  |  1996-10-04  |  4.9 KB  |  161 lines

  1. package sub_arctic.anim;
  2.  
  3. import sub_arctic.input.event;
  4.  
  5. /**
  6.  * This is a version of the transition object which knows how to 
  7.  * talk to objects which are of type simple_animatable.<p>
  8.  *
  9.  * @author Ian Smith
  10.  */
  11. public class simple_transition extends transition  {
  12.  
  13.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  14.    
  15.   /**
  16.    * This is the object we are going to animate. The "target" of this
  17.    * transition is null since we are not using the animatable
  18.    * interface.
  19.    */
  20.   protected simple_animatable _simple_target;
  21.  
  22.   /**
  23.    * The simple target of this transition is the simple_animatable
  24.    * object with whom we are communicating.
  25.    */
  26.   public simple_animatable simple_target() { return _simple_target;}
  27.  
  28.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  29.    
  30.   /**
  31.    * Create a simple transition given a simple_animatable object, 
  32.    * a time interval, and a trajectory.<p>
  33.    *
  34.    * @param simple_animatable i the target of the animation or transition
  35.    * @param time_interval t the time interval over which this transition occurs
  36.    * @param trajectory j the trajectory over which this transition is mapped
  37.    */
  38.   public simple_transition(simple_animatable i, time_interval t,
  39.                trajectory j) {
  40.     super(null,t,j);
  41.     _simple_target=i;
  42.   }
  43.  
  44.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  45.    
  46.   /**
  47.    * Start a transition. This is where the work gets done of calling the
  48.    * start_transition function on the interactor.
  49.    * 
  50.    * @param event e the animation event that caused things to get going
  51.    * @param Object user_info the object passed to the animation agent when 
  52.    *                         the animatable joined its focus set
  53.    */
  54.   public void start(event e,Object user_info) {
  55.     Object result;
  56.  
  57.     /* set the last time seen */
  58.     _last_time=0.0;
  59.  
  60.     /* compute the result using the trajectory */
  61.     if (traj()==null) {
  62.       result=null;
  63.     } else {
  64.       result=traj().object_for_parm(0.0);
  65.     }
  66.  
  67.     /* make the call to start him */
  68.     simple_target().start_transition(result);
  69.   }
  70.  
  71.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  72.    
  73.   /**
  74.    * Perform a step... this sends the transition_step message to the
  75.    * interactor.<p>
  76.    * 
  77.    * @param event e the animation event for this step
  78.    * @param Object user_info the object passed to the animation agent when 
  79.    *                         the animatable joined its focus set
  80.    * @param long current_time the time it is "now" for this time step
  81.    */
  82.   public void step(event e, Object user_info, long current_time) {
  83.     Object start_result, end_result;
  84.     double c_time;
  85.     time_interval i=interval();
  86.     long diff_time;
  87.  
  88.     /* how far past the start are we*/
  89.     diff_time=current_time-(i.start_time());
  90.  
  91.     /* are we past the end or at it?*/
  92.     if (current_time>=i.end_time()) {
  93.  
  94.       /* set the flag that we are finished */
  95.       _finished=true;
  96.       return;
  97.     }
  98.  
  99.     /* compute the actual time as a real */
  100.     c_time=(double)diff_time/((double)(i.duration()));
  101.  
  102.     /* now compute the two objects via the trajectory */
  103.     if (traj()==null) {
  104.       start_result=null;
  105.       end_result=null;
  106.     } else {
  107.       start_result=traj().object_for_parm(_last_time);
  108.       end_result=traj().object_for_parm(c_time);
  109.     }
  110.  
  111.     /* send the message to the interactor */
  112.     simple_target().transition_step(start_result,end_result);
  113.  
  114.     /* now reset what time we have seen */
  115.     _last_time=c_time;
  116.   }
  117.  
  118.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  119.    
  120.   /**
  121.    * Send the end message to the interactor.
  122.    * @param event e the animation event for this step
  123.    * @param Object user_info the object passed to the animation agent when 
  124.    *                         the animatable joined its focus set
  125.    */
  126.   public void end(event e, Object user_info) {
  127.     Object start_result, end_result;
  128.  
  129.     /* compute the two objects via the trajectory */
  130.     if (traj()==null) {
  131.       start_result=null;
  132.       end_result=null;
  133.     } else {
  134.       start_result=traj().object_for_parm(_last_time);
  135.       end_result=traj().object_for_parm(1.0);
  136.     }
  137.  
  138.     /* send the message to the interactor */
  139.     simple_target().end_transition(start_result,end_result);
  140.   }
  141.  
  142.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  143.    
  144. }
  145. /*=========================== COPYRIGHT NOTICE ===========================
  146.  
  147. This file is part of the subArctic user interface toolkit.
  148.  
  149. Copyright (c) 1996 Scott Hudson and Ian Smith
  150. All rights reserved.
  151.  
  152. The subArctic system is freely available for most uses under the terms
  153. and conditions described in 
  154.   http://www.cc.gatech.edu/gvu/ui/sub_arctic/sub_arctic/doc/usage.html 
  155. and appearing in full in the lib/interactor.java source file.
  156.  
  157. The current release and additional information about this software can be 
  158. found starting at: http://www.cc.gatech.edu/gvu/ui/sub_arctic/
  159.  
  160. ========================================================================*/
  161.