TuioObject.cs 9.2 KB

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