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