front_processing/extern/TUIO_JAVA/src/TUIO/TuioObject.java
changeset 9 0f44b7360c8d
parent 0 6fefd4afe506
child 10 925b7ee746e3
equal deleted inserted replaced
8:e4e7db2435f8 9:0f44b7360c8d
     1 /*
     1 /*
     2 	TUIO Java backend - part of the reacTIVision project
     2     TUIO Java backend - part of the reacTIVision project
     3 	http://reactivision.sourceforge.net/
     3     http://reactivision.sourceforge.net/
     4 
     4 
     5 	Copyright (c) 2005-2009 Martin Kaltenbrunner <mkalten@iua.upf.edu>
     5     Copyright (c) 2005-2009 Martin Kaltenbrunner <mkalten@iua.upf.edu>
     6 
     6 
     7     This program is free software; you can redistribute it and/or modify
     7     This program is free software; you can redistribute it and/or modify
     8     it under the terms of the GNU General Public License as published by
     8     it under the terms of the GNU General Public License as published by
     9     the Free Software Foundation; either version 2 of the License, or
     9     the Free Software Foundation; either version 2 of the License, or
    10     (at your option) any later version.
    10     (at your option) any later version.
    25  *
    25  *
    26  * @author Martin Kaltenbrunner
    26  * @author Martin Kaltenbrunner
    27  * @version 1.4
    27  * @version 1.4
    28  */ 
    28  */ 
    29 public class TuioObject extends TuioContainer {
    29 public class TuioObject extends TuioContainer {
    30 	
    30     
    31 	/**
    31     /**
    32 	 * The individual symbol ID number that is assigned to each TuioObject.
    32      * The individual symbol ID number that is assigned to each TuioObject.
    33 	 */ 
    33      */ 
    34 	protected int symbol_id;
    34     protected int symbol_id;
    35 	/**
    35     /**
    36 	 * The rotation angle value.
    36      * The rotation angle value.
    37 	 */ 
    37      */ 
    38 	protected float angle;
    38     protected float angle;
    39 	/**
    39     /**
    40 	 * The rotation speed value.
    40      * The rotation speed value.
    41 	 */ 
    41      */ 
    42 	protected float rotation_speed;
    42     protected float rotation_speed;
    43 	/**
    43     /**
    44 	 * The rotation acceleration value.
    44      * The rotation acceleration value.
    45 	 */ 
    45      */ 
    46 	protected float rotation_accel;
    46     protected float rotation_accel;
    47 	/**
    47     /**
    48 	 * Defines the ROTATING state.
    48      * Defines the ROTATING state.
    49 	 */ 
    49      */ 
    50 	public static final int TUIO_ROTATING = 5;
    50     public static final int TUIO_ROTATING = 5;
    51 	
    51     
    52 	/**
    52     /**
    53 	 * This constructor takes a TuioTime argument and assigns it along with the provided 
    53      * This constructor takes a TuioTime argument and assigns it along with the provided 
    54 	 * Session ID, Symbol ID, X and Y coordinate and angle to the newly created TuioObject.
    54      * Session ID, Symbol ID, X and Y coordinate and angle to the newly created TuioObject.
    55 	 *
    55      *
    56 	 * @param	ttime	the TuioTime to assign
    56      * @param    ttime    the TuioTime to assign
    57 	 * @param	si	the Session ID  to assign
    57      * @param    si    the Session ID  to assign
    58 	 * @param	sym	the Symbol ID  to assign
    58      * @param    sym    the Symbol ID  to assign
    59 	 * @param	xp	the X coordinate to assign
    59      * @param    xp    the X coordinate to assign
    60 	 * @param	yp	the Y coordinate to assign
    60      * @param    yp    the Y coordinate to assign
    61 	 * @param	a	the angle to assign
    61      * @param    a    the angle to assign
    62 	 */
    62      */
    63 	public TuioObject (TuioTime ttime, long si, int sym, float xp, float yp, float a) {
    63     public TuioObject (TuioTime ttime, long si, int sym, float xp, float yp, float a) {
    64 		super(ttime, si,xp,yp);
    64         super(ttime, si,xp,yp);
    65 		symbol_id = sym;
    65         symbol_id = sym;
    66 		angle = a;
    66         angle = a;
    67 		rotation_speed = 0.0f;
    67         rotation_speed = 0.0f;
    68 		rotation_accel = 0.0f;
    68         rotation_accel = 0.0f;
    69 	}
    69     }
    70 
    70 
    71 	/**
    71     /**
    72 	 * This constructor takes the provided Session ID, Symbol ID, X and Y coordinate 
    72      * This constructor takes the provided Session ID, Symbol ID, X and Y coordinate 
    73 	 * and angle, and assigs these values to the newly created TuioObject.
    73      * and angle, and assigs these values to the newly created TuioObject.
    74 	 *
    74      *
    75 	 * @param	si	the Session ID  to assign
    75      * @param    si    the Session ID  to assign
    76 	 * @param	sym	the Symbol ID  to assign
    76      * @param    sym    the Symbol ID  to assign
    77 	 * @param	xp	the X coordinate to assign
    77      * @param    xp    the X coordinate to assign
    78 	 * @param	yp	the Y coordinate to assign
    78      * @param    yp    the Y coordinate to assign
    79 	 * @param	a	the angle to assign
    79      * @param    a    the angle to assign
    80 	 */	
    80      */    
    81 	public TuioObject (long si, int sym, float xp, float yp, float a) {
    81     public TuioObject (long si, int sym, float xp, float yp, float a) {
    82 		super(si,xp,yp);
    82         super(si,xp,yp);
    83 		symbol_id = sym;
    83         symbol_id = sym;
    84 		angle = angle;
    84         angle = angle;
    85 		rotation_speed = 0.0f;
    85         rotation_speed = 0.0f;
    86 		rotation_accel = 0.0f;
    86         rotation_accel = 0.0f;
    87 	}
    87     }
    88 
    88 
    89 	/**
    89     /**
    90 	 * This constructor takes the atttibutes of the provided TuioObject 
    90      * This constructor takes the atttibutes of the provided TuioObject 
    91 	 * and assigs these values to the newly created TuioObject.
    91      * and assigs these values to the newly created TuioObject.
    92 	 *
    92      *
    93 	 * @param	tobj	the TuioObject to assign
    93      * @param    tobj    the TuioObject to assign
    94 	 */
    94      */
    95 	public TuioObject (TuioObject tobj) {
    95     public TuioObject (TuioObject tobj) {
    96 		super(tobj);
    96         super(tobj);
    97 		symbol_id = tobj.getSymbolID();
    97         symbol_id = tobj.getSymbolID();
    98 		angle = tobj.getAngle();
    98         angle = tobj.getAngle();
    99 		rotation_speed = 0.0f;
    99         rotation_speed = 0.0f;
   100 		rotation_accel = 0.0f;
   100         rotation_accel = 0.0f;
   101 	}
   101     }
   102 
   102 
   103 	/**
   103     /**
   104 	 * Takes a TuioTime argument and assigns it along with the provided 
   104      * Takes a TuioTime argument and assigns it along with the provided 
   105 	 * X and Y coordinate, angle, X and Y velocity, motion acceleration,
   105      * X and Y coordinate, angle, X and Y velocity, motion acceleration,
   106 	 * rotation speed and rotation acceleration to the private TuioObject attributes.
   106      * rotation speed and rotation acceleration to the private TuioObject attributes.
   107 	 *
   107      *
   108 	 * @param	ttime	the TuioTime to assign
   108      * @param    ttime    the TuioTime to assign
   109 	 * @param	xp	the X coordinate to assign
   109      * @param    xp    the X coordinate to assign
   110 	 * @param	yp	the Y coordinate to assign
   110      * @param    yp    the Y coordinate to assign
   111 	 * @param	a	the angle coordinate to assign
   111      * @param    a    the angle coordinate to assign
   112 	 * @param	xs	the X velocity to assign
   112      * @param    xs    the X velocity to assign
   113 	 * @param	ys	the Y velocity to assign
   113      * @param    ys    the Y velocity to assign
   114 	 * @param	rs	the rotation velocity to assign
   114      * @param    rs    the rotation velocity to assign
   115 	 * @param	ma	the motion acceleration to assign
   115      * @param    ma    the motion acceleration to assign
   116 	 * @param	ra	the rotation acceleration to assign
   116      * @param    ra    the rotation acceleration to assign
   117 	 */
   117      */
   118 	public void update (TuioTime ttime, float xp, float yp, float a, float xs, float ys, float rs, float ma, float ra) {
   118     public void update (TuioTime ttime, float xp, float yp, float a, float xs, float ys, float rs, float ma, float ra) {
   119 		super.update(ttime,xp,yp,xs,ys,ma);
   119         super.update(ttime,xp,yp,xs,ys,ma);
   120 		angle = a;
   120         angle = a;
   121 		rotation_speed = rs;
   121         rotation_speed = rs;
   122 		rotation_accel = ra;
   122         rotation_accel = ra;
   123 		if ((rotation_accel!=0) && (state!=TUIO_STOPPED)) state = TUIO_ROTATING;
   123         if ((rotation_accel!=0) && (state!=TUIO_STOPPED)) state = TUIO_ROTATING;
   124 	}
   124     }
   125 
   125 
   126 	/**
   126     /**
   127 	 * Assigns the provided X and Y coordinate, angle, X and Y velocity, motion acceleration
   127      * Assigns the provided X and Y coordinate, angle, X and Y velocity, motion acceleration
   128 	 * rotation velocity and rotation acceleration to the private TuioContainer attributes.
   128      * rotation velocity and rotation acceleration to the private TuioContainer attributes.
   129 	 * The TuioTime time stamp remains unchanged.
   129      * The TuioTime time stamp remains unchanged.
   130 	 *
   130      *
   131 	 * @param	xp	the X coordinate to assign
   131      * @param    xp    the X coordinate to assign
   132 	 * @param	yp	the Y coordinate to assign
   132      * @param    yp    the Y coordinate to assign
   133 	 * @param	a	the angle coordinate to assign
   133      * @param    a    the angle coordinate to assign
   134 	 * @param	xs	the X velocity to assign
   134      * @param    xs    the X velocity to assign
   135 	 * @param	ys	the Y velocity to assign
   135      * @param    ys    the Y velocity to assign
   136 	 * @param	rs	the rotation velocity to assign
   136      * @param    rs    the rotation velocity to assign
   137 	 * @param	ma	the motion acceleration to assign
   137      * @param    ma    the motion acceleration to assign
   138 	 * @param	ra	the rotation acceleration to assign
   138      * @param    ra    the rotation acceleration to assign
   139 	 */
   139      */
   140 	public void update (float xp, float yp, float a, float xs, float ys, float rs, float ma, float ra) {
   140     public void update (float xp, float yp, float a, float xs, float ys, float rs, float ma, float ra) {
   141 		super.update(xp,yp,xs,ys,ma);
   141         super.update(xp,yp,xs,ys,ma);
   142 		angle = a;
   142         angle = a;
   143 		rotation_speed = rs;
   143         rotation_speed = rs;
   144 		rotation_accel = ra;
   144         rotation_accel = ra;
   145 		if ((rotation_accel!=0) && (state!=TUIO_STOPPED)) state = TUIO_ROTATING;
   145         if ((rotation_accel!=0) && (state!=TUIO_STOPPED)) state = TUIO_ROTATING;
   146 	}
   146     }
   147 	
   147     
   148 	/**
   148     /**
   149 	 * Takes a TuioTime argument and assigns it along with the provided 
   149      * Takes a TuioTime argument and assigns it along with the provided 
   150 	 * X and Y coordinate and angle to the private TuioObject attributes.
   150      * X and Y coordinate and angle to the private TuioObject attributes.
   151 	 * The speed and accleration values are calculated accordingly.
   151      * The speed and accleration values are calculated accordingly.
   152 	 *
   152      *
   153 	 * @param	ttime	the TuioTime to assign
   153      * @param    ttime    the TuioTime to assign
   154 	 * @param	xp	the X coordinate to assign
   154      * @param    xp    the X coordinate to assign
   155 	 * @param	yp	the Y coordinate to assign
   155      * @param    yp    the Y coordinate to assign
   156 	 * @param	a	the angle coordinate to assign
   156      * @param    a    the angle coordinate to assign
   157 	 */
   157      */
   158 	public void update (TuioTime ttime, float xp, float yp, float a) {
   158     public void update (TuioTime ttime, float xp, float yp, float a) {
   159 		TuioPoint lastPoint = path.lastElement();
   159         TuioPoint lastPoint = path.lastElement();
   160 		super.update(ttime,xp,yp);
   160         super.update(ttime,xp,yp);
   161 
   161 
   162 		TuioTime diffTime = currentTime.subtract(lastPoint.getTuioTime());
   162         TuioTime diffTime = currentTime.subtract(lastPoint.getTuioTime());
   163 		float dt = diffTime.getTotalMilliseconds()/1000.0f;
   163         float dt = diffTime.getTotalMilliseconds()/1000.0f;
   164 		float last_angle = angle;
   164         float last_angle = angle;
   165 		float last_rotation_speed = rotation_speed;
   165         float last_rotation_speed = rotation_speed;
   166 		angle = a;
   166         angle = a;
   167 		
   167         
   168 		float da = (this.angle-last_angle)/(2.0f*(float)Math.PI);
   168         float da = (this.angle-last_angle)/(2.0f*(float)Math.PI);
   169 		if (da>0.75f) da-=1.0f;
   169         if (da>0.75f) da-=1.0f;
   170 		else if (da<-0.75f) da+=1.0f;
   170         else if (da<-0.75f) da+=1.0f;
   171 		
   171         
   172 		rotation_speed = da/dt;
   172         rotation_speed = da/dt;
   173 		rotation_accel = (rotation_speed - last_rotation_speed)/dt;
   173         rotation_accel = (rotation_speed - last_rotation_speed)/dt;
   174 		if ((rotation_accel!=0) && (state!=TUIO_STOPPED)) state = TUIO_ROTATING;
   174         if ((rotation_accel!=0) && (state!=TUIO_STOPPED)) state = TUIO_ROTATING;
   175 	}
   175     }
   176 	
   176     
   177 	/**
   177     /**
   178 	 * Takes the atttibutes of the provided TuioObject 
   178      * Takes the atttibutes of the provided TuioObject 
   179 	 * and assigs these values to this TuioObject.
   179      * and assigs these values to this TuioObject.
   180 	 * The TuioTime time stamp of this TuioContainer remains unchanged.
   180      * The TuioTime time stamp of this TuioContainer remains unchanged.
   181 	 *
   181      *
   182 	 * @param	tobj	the TuioContainer to assign
   182      * @param    tobj    the TuioContainer to assign
   183 	 */	
   183      */    
   184 	public void update (TuioObject tobj) {
   184     public void update (TuioObject tobj) {
   185 		super.update(tobj);
   185         super.update(tobj);
   186 		angle = tobj.getAngle();
   186         angle = tobj.getAngle();
   187 		rotation_speed = tobj.getRotationSpeed();
   187         rotation_speed = tobj.getRotationSpeed();
   188 		rotation_accel = tobj.getRotationAccel();
   188         rotation_accel = tobj.getRotationAccel();
   189 		if ((rotation_accel!=0) && (state!=TUIO_STOPPED)) state = TUIO_ROTATING;
   189         if ((rotation_accel!=0) && (state!=TUIO_STOPPED)) state = TUIO_ROTATING;
   190 	}
   190     }
   191 	
   191     
   192 	/**
   192     /**
   193 	 * This method is used to calculate the speed and acceleration values of a
   193      * This method is used to calculate the speed and acceleration values of a
   194 	 * TuioObject with unchanged position and angle.
   194      * TuioObject with unchanged position and angle.
   195 	 *
   195      *
   196 	 * @param	ttime	the TuioTime to assign
   196      * @param    ttime    the TuioTime to assign
   197 	 */
   197      */
   198 	public void stop (TuioTime ttime) {
   198     public void stop (TuioTime ttime) {
   199 		update(ttime,xpos,ypos, angle);
   199         update(ttime,xpos,ypos, angle);
   200 	}
   200     }
   201 
   201 
   202 	/**
   202     /**
   203 	 * Returns the symbol ID of this TuioObject.
   203      * Returns the symbol ID of this TuioObject.
   204 	 * @return	the symbol ID of this TuioObject
   204      * @return    the symbol ID of this TuioObject
   205 	 */
   205      */
   206 	public int getSymbolID() {
   206     public int getSymbolID() {
   207 		return symbol_id;
   207         return symbol_id;
   208 	}
   208     }
   209 		
   209         
   210 	/**
   210     /**
   211 	 * Returns the rotation angle of this TuioObject.
   211      * Returns the rotation angle of this TuioObject.
   212 	 * @return	the rotation angle of this TuioObject
   212      * @return    the rotation angle of this TuioObject
   213 	 */
   213      */
   214 	public float getAngle() {
   214     public float getAngle() {
   215 		return angle;
   215         return angle;
   216 	}
   216     }
   217 
   217 
   218 	/**
   218     /**
   219 	 * Returns the rotation angle in degrees of this TuioObject.
   219      * Returns the rotation angle in degrees of this TuioObject.
   220 	 * @return	the rotation angle in degrees of this TuioObject
   220      * @return    the rotation angle in degrees of this TuioObject
   221 	 */
   221      */
   222 	public float getAngleDegrees() {
   222     public float getAngleDegrees() {
   223 		return angle/(float)Math.PI*180.0f;
   223         return angle/(float)Math.PI*180.0f;
   224 	}
   224     }
   225 	
   225     
   226 	/**
   226     /**
   227 	 * Returns the rotation speed of this TuioObject.
   227      * Returns the rotation speed of this TuioObject.
   228 	 * @return	the rotation speed of this TuioObject
   228      * @return    the rotation speed of this TuioObject
   229 	 */
   229      */
   230 	public float getRotationSpeed() {
   230     public float getRotationSpeed() {
   231 		return rotation_speed;
   231         return rotation_speed;
   232 	}
   232     }
   233 		
   233         
   234 	/**
   234     /**
   235 	 * Returns the rotation acceleration of this TuioObject.
   235      * Returns the rotation acceleration of this TuioObject.
   236 	 * @return	the rotation acceleration of this TuioObject
   236      * @return    the rotation acceleration of this TuioObject
   237 	 */
   237      */
   238 	public float getRotationAccel() {
   238     public float getRotationAccel() {
   239 		return rotation_accel;
   239         return rotation_accel;
   240 	}
   240     }
   241 
   241 
   242 	/**
   242     /**
   243 	 * Returns true of this TuioObject is moving.
   243      * Returns true of this TuioObject is moving.
   244 	 * @return	true of this TuioObject is moving
   244      * @return    true of this TuioObject is moving
   245 	 */
   245      */
   246 	public boolean isMoving() { 
   246     public boolean isMoving() { 
   247 		if ((state==TUIO_ACCELERATING) || (state==TUIO_DECELERATING) || (state==TUIO_ROTATING)) return true;
   247         if ((state==TUIO_ACCELERATING) || (state==TUIO_DECELERATING) || (state==TUIO_ROTATING)) return true;
   248 		else return false;
   248         else return false;
   249 	}
   249     }
   250 	
   250     
   251 }
   251 }