123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274 |
- /*
- TUIO C# Library - part of the reacTIVision project
- http://reactivision.sourceforge.net/
- Copyright (c) 2005-2009 Martin Kaltenbrunner <mkalten@iua.upf.edu>
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
- using System;
- namespace TUIO
- {
- /**
- * The TuioObject class encapsulates /tuio/2Dobj TUIO objects.
- *
- * @author Martin Kaltenbrunner
- * @version 1.4
- */
- public class TuioObject : TuioContainer
- {
- /**
- * The individual symbol ID number that is assigned to each TuioObject.
- */
- public static readonly int TUIO_ROTATING = 5;
- protected float angle;
- protected float rotation_accel;
- protected float rotation_speed;
- protected int symbol_id;
- /**
- * The rotation angle value.
- */
- /**
- * The rotation speed value.
- */
- /**
- * The rotation acceleration value.
- */
- /**
- * Defines the ROTATING state.
- */
- /**
- * This constructor takes a TuioTime argument and assigns it along with the provided
- * Session ID, Symbol ID, X and Y coordinate and angle to the newly created TuioObject.
- *
- * @param ttime the TuioTime to assign
- * @param si the Session ID to assign
- * @param sym the Symbol ID to assign
- * @param xp the X coordinate to assign
- * @param yp the Y coordinate to assign
- * @param a the angle to assign
- */
- public TuioObject(TuioTime ttime, long si, int sym, float xp, float yp, float a)
- : base(ttime, si, xp, yp)
- {
- symbol_id = sym;
- angle = a;
- rotation_speed = 0.0f;
- rotation_accel = 0.0f;
- }
- /**
- * This constructor takes the provided Session ID, Symbol ID, X and Y coordinate
- * and angle, and assigs these values to the newly created TuioObject.
- *
- * @param si the Session ID to assign
- * @param sym the Symbol ID to assign
- * @param xp the X coordinate to assign
- * @param yp the Y coordinate to assign
- * @param a the angle to assign
- */
- public TuioObject(long si, int sym, float xp, float yp, float a)
- : base(si, xp, yp)
- {
- symbol_id = sym;
- angle = a;
- rotation_speed = 0.0f;
- rotation_accel = 0.0f;
- }
- /**
- * This constructor takes the atttibutes of the provided TuioObject
- * and assigs these values to the newly created TuioObject.
- *
- * @param tobj the TuioObject to assign
- */
- public TuioObject(TuioObject tobj)
- : base(tobj)
- {
- symbol_id = tobj.getSymbolID();
- angle = tobj.getAngle();
- rotation_speed = 0.0f;
- rotation_accel = 0.0f;
- }
- /**
- * Takes a TuioTime argument and assigns it along with the provided
- * X and Y coordinate, angle, X and Y velocity, motion acceleration,
- * rotation speed and rotation acceleration to the private TuioObject attributes.
- *
- * @param ttime the TuioTime to assign
- * @param xp the X coordinate to assign
- * @param yp the Y coordinate to assign
- * @param a the angle coordinate to assign
- * @param xs the X velocity to assign
- * @param ys the Y velocity to assign
- * @param rs the rotation velocity to assign
- * @param ma the motion acceleration to assign
- * @param ra the rotation acceleration to assign
- */
- public float getAngle()
- {
- return angle;
- }
- public float getAngleDegrees()
- {
- return angle / (float)Math.PI * 180.0f;
- }
- public float getRotationAccel()
- {
- return rotation_accel;
- }
- public float getRotationSpeed()
- {
- return rotation_speed;
- }
- public int getSymbolID()
- {
- return symbol_id;
- }
- public new bool isMoving()
- {
- if ((state == TUIO_ACCELERATING) || (state == TUIO_DECELERATING) || (state == TUIO_ROTATING)) return true;
- else return false;
- }
- public new void stop(TuioTime ttime)
- {
- update(ttime, this.xpos, this.ypos, this.angle);
- }
- public void update(TuioTime ttime, float xp, float yp, float a, float xs, float ys, float rs, float ma, float ra)
- {
- base.update(ttime, xp, yp, xs, ys, ma);
- angle = a;
- rotation_speed = rs;
- rotation_accel = ra;
- if ((rotation_accel != 0) && (state != TUIO_STOPPED)) state = TUIO_ROTATING;
- }
- /**
- * Assigns the provided X and Y coordinate, angle, X and Y velocity, motion acceleration
- * rotation velocity and rotation acceleration to the private TuioContainer attributes.
- * The TuioTime time stamp remains unchanged.
- *
- * @param xp the X coordinate to assign
- * @param yp the Y coordinate to assign
- * @param a the angle coordinate to assign
- * @param xs the X velocity to assign
- * @param ys the Y velocity to assign
- * @param rs the rotation velocity to assign
- * @param ma the motion acceleration to assign
- * @param ra the rotation acceleration to assign
- */
- public void update(float xp, float yp, float a, float xs, float ys, float rs, float ma, float ra)
- {
- base.update(xp, yp, xs, ys, ma);
- angle = a;
- rotation_speed = rs;
- rotation_accel = ra;
- if ((rotation_accel != 0) && (state != TUIO_STOPPED)) state = TUIO_ROTATING;
- }
- /**
- * Takes a TuioTime argument and assigns it along with the provided
- * X and Y coordinate and angle to the private TuioObject attributes.
- * The speed and accleration values are calculated accordingly.
- *
- * @param ttime the TuioTime to assign
- * @param xp the X coordinate to assign
- * @param yp the Y coordinate to assign
- * @param a the angle coordinate to assign
- */
- public void update(TuioTime ttime, float xp, float yp, float a)
- {
- TuioPoint lastPoint = path[path.Count - 1];
- base.update(ttime, xp, yp);
- TuioTime diffTime = currentTime - lastPoint.getTuioTime();
- float dt = diffTime.getTotalMilliseconds() / 1000.0f;
- float last_angle = angle;
- float last_rotation_speed = rotation_speed;
- angle = a;
- float da = (angle - last_angle) / (2.0f * (float)Math.PI);
- if (da > 0.75f) da -= 1.0f;
- else if (da < -0.75f) da += 1.0f;
- rotation_speed = da / dt;
- rotation_accel = (rotation_speed - last_rotation_speed) / dt;
- if ((rotation_accel != 0) && (state != TUIO_STOPPED)) state = TUIO_ROTATING;
- }
- /**
- * Takes the atttibutes of the provided TuioObject
- * and assigs these values to this TuioObject.
- * The TuioTime time stamp of this TuioContainer remains unchanged.
- *
- * @param tobj the TuioContainer to assign
- */
- public void update(TuioObject tobj)
- {
- base.update(tobj);
- angle = tobj.getAngle();
- rotation_speed = tobj.getRotationSpeed();
- rotation_accel = tobj.getRotationAccel();
- if ((rotation_accel != 0) && (state != TUIO_STOPPED)) state = TUIO_ROTATING;
- }
- /**
- * This method is used to calculate the speed and acceleration values of a
- * TuioObject with unchanged position and angle.
- */
- /**
- * Returns the symbol ID of this TuioObject.
- * @return the symbol ID of this TuioObject
- */
- /**
- * Returns the rotation angle of this TuioObject.
- * @return the rotation angle of this TuioObject
- */
- /**
- * Returns the rotation angle in degrees of this TuioObject.
- * @return the rotation angle in degrees of this TuioObject
- */
- /**
- * Returns the rotation speed of this TuioObject.
- * @return the rotation speed of this TuioObject
- */
- /**
- * Returns the rotation acceleration of this TuioObject.
- * @return the rotation acceleration of this TuioObject
- */
- /**
- * Returns true of this TuioObject is moving.
- * @return true of this TuioObject is moving
- */
- }
- }
|