/* TUIO C# Library - part of the reacTIVision project Copyright (c) 2005-2014 Martin Kaltenbrunner This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 3.0 of the License, or (at your option) any later version. This library 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 Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library. */ using System; using System.Collections.Generic; namespace TUIO { /** * * The TuioBlob class encapsulates /tuio/2Dblb TUIO objects. * * * @author Martin Kaltenbrunner * @version 1.1.5 */ public class TuioBlob : TuioContainer { /** * * The individual symbol ID number that is assigned to each TuioBlob. */ protected int blob_id; /** * * The rotation angle value. */ protected float angle; /** * * The blob width value. */ protected float width; /** * * The blob height value. */ protected float height; /** * * The blob area value. */ protected float area; /** * * The rotation speed value. */ protected float rotation_speed; /** * * The rotation acceleration value. */ protected float rotation_accel; #region State Enumeration Values /** * * Defines the ROTATING state. */ public static readonly int TUIO_ROTATING = 5; #endregion #region Constructors /** * * 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 TuioBlob. * * the TuioTime to assign * the Session ID to assign * the Blob ID to assign * the X coordinate to assign * the Y coordinate to assign * the angle to assign * the width to assign * the height to assign * the area to assign */ public TuioBlob(TuioTime ttime, long si, int bi, float xp, float yp, float a, float w, float h, float f) : base(ttime, si, xp, yp) { blob_id = bi; angle = a; width = w; height = h; area = f; 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 TuioBlob. * * the Session ID to assign * the Symbol ID to assign * the X coordinate to assign * the Y coordinate to assign * the angle to assign * the width to assign * the height to assign * the area to assign */ public TuioBlob(long si, int bi, float xp, float yp, float a, float w, float h, float f) : base(si, xp, yp) { blob_id = bi; angle = a; width = w; height = h; area = f; rotation_speed = 0.0f; rotation_accel = 0.0f; } /** * * This constructor takes the atttibutes of the provided TuioBlob * and assigs these values to the newly created TuioBlob. * * the TuioBlob to assign */ public TuioBlob(TuioBlob tblb) : base(tblb) { blob_id = tblb.BlobID; angle = tblb.Angle; width = tblb.Width; height = tblb.Height; area = tblb.Area; rotation_speed = 0.0f; rotation_accel = 0.0f; } #endregion #region Update Methods /** * * 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 TuioBlob attributes. * * the TuioTime to assign * the X coordinate to assign * the Y coordinate to assign * the angle coordinate to assign * the width to assign * the height to assign * the area to assign * the X velocity to assign * the Y velocity to assign * the rotation velocity to assign * the motion acceleration to assign * the rotation acceleration to assign */ public void update(TuioTime ttime, float xp, float yp, float a, float w, float h, float f, float xs, float ys, float rs, float ma, float ra) { base.update(ttime, xp, yp, xs, ys, ma); angle = a; width = w; height = h; area = f; 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. * * the X coordinate to assign * the Y coordinate to assign * the angle coordinate to assign * the width to assign * the height to assign * the area to assign * the X velocity to assign * the Y velocity to assign * the rotation velocity to assign * the motion acceleration to assign * the rotation acceleration to assign */ public void update(float xp, float yp, float a, float w, float h, float f, float xs, float ys, float rs, float ma, float ra) { base.update(xp, yp, xs, ys, ma); angle = a; width = w; height = h; area = f; 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 TuioBlob attributes. * The speed and accleration values are calculated accordingly. * * the TuioTime to assign * the X coordinate to assign * the Y coordinate to assign * the angle coordinate to assign * the width to assign * the height to assign * the area to assign */ public void update(TuioTime ttime, float xp, float yp, float a,float w, float h, float f) { TuioPoint lastPoint = path[path.Count - 1]; base.update(ttime, xp, yp); width = w; height = h; area = f; TuioTime diffTime = currentTime - lastPoint.TuioTime; float dt = diffTime.TotalMilliseconds / 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 TuioBlob * and assigs these values to this TuioBlob. * The TuioTime time stamp of this TuioContainer remains unchanged. * * the TuioContainer to assign */ public void update(TuioBlob tblb) { base.update(tblb); angle = tblb.Angle; width = tblb.Width; height = tblb.Height; area = tblb.Area; rotation_speed = tblb.RotationSpeed; rotation_accel = tblb.RotationAccel; if ((rotation_accel != 0) && (state != TUIO_STOPPED)) state = TUIO_ROTATING; } /** * * This method is used to calculate the speed and acceleration values of a * TuioBlob with unchanged position and angle. */ public new void stop(TuioTime ttime) { update(ttime, this.xpos, this.ypos, this.angle, this.width, this.height, this.area); } #endregion #region Properties & Getter/Setter Methods /** * * Returns the symbol ID of this TuioBlob. * the symbol ID of this TuioBlob */ public int BlobID { get { return blob_id; } } [Obsolete("This method is provided only for compatability with legacy code. Use of the property instead is recommended.")] public int getBlobID() { return BlobID; } /** * * Returns the width of this TuioBlob. * the width of this TuioBlob */ public float Width { get { return width; } } [Obsolete("This method is provided only for compatability with legacy code. Use of the property instead is recommended.")] public float getWidth() { return Width; } /** * * Returns the height of this TuioBlob. * the heigth of this TuioBlob */ public float Height { get { return height; } } [Obsolete("This method is provided only for compatability with legacy code. Use of the property instead is recommended.")] public float getHeight() { return Height; } /** * * Returns the area of this TuioBlob. * the area of this TuioBlob */ public float Area { get { return area; } } [Obsolete("This method is provided only for compatability with legacy code. Use of the property instead is recommended.")] public float getArea() { return Area; } /** * * Returns the rotation angle of this TuioBlob. * the rotation angle of this TuioBlob */ public float Angle { get { return angle; } } [Obsolete("This method is provided only for compatability with legacy code. Use of the property instead is recommended.")] public float getAngle() { return Angle; } /** * * Returns the rotation angle in degrees of this TuioBlob. * the rotation angle in degrees of this TuioBlob */ public float AngleDegrees { get { return angle / (float)Math.PI * 180.0f; } } [Obsolete("This method is provided only for compatability with legacy code. Use of the property instead is recommended.")] public float getAngleDegrees() { return AngleDegrees; } /** * * Returns the rotation speed of this TuioBlob. * the rotation speed of this TuioBlob */ public float RotationSpeed { get { return rotation_speed; } } [Obsolete("This method is provided only for compatability with legacy code. Use of the property instead is recommended.")] public float getRotationSpeed() { return RotationSpeed; } /** * * Returns the rotation acceleration of this TuioBlob. * the rotation acceleration of this TuioBlob */ public float RotationAccel { get { return rotation_accel; } } [Obsolete("This method is provided only for compatability with legacy code. Use of the property instead is recommended.")] public float getRotationAccel() { return RotationAccel; } /** * * Returns true of this TuioBlob is moving. * true of this TuioBlob is moving */ public override bool isMoving { get { if ((state == TUIO_ACCELERATING) || (state == TUIO_DECELERATING) || (state == TUIO_ROTATING)) return true; else return false; } } #endregion } }