/* 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; namespace TUIO { /** * The TuioPoint class on the one hand is a simple container and utility class to handle TUIO positions in general, * on the other hand the TuioPoint is the base class for the TuioCursor and TuioObject classes. * * @author Martin Kaltenbrunner * @version 1.1.5 */ public class TuioPoint { #region Member Variables /** * * X coordinate, representated as a floating point value in a range of 0..1 */ protected float xpos; /** * * Y coordinate, representated as a floating point value in a range of 0..1 */ protected float ypos; /** * * The time stamp of the last update represented as TuioTime (time since session start) */ protected TuioTime currentTime; /** * * The creation time of this TuioPoint represented as TuioTime (time since session start) */ protected TuioTime startTime; #endregion #region Constructors /** * * The default constructor takes no arguments and sets * its coordinate attributes to zero and its time stamp to the current session time. */ public TuioPoint() { xpos = 0.0f; ypos = 0.0f; currentTime = TuioTime.SessionTime; startTime = new TuioTime(currentTime); } /** * * This constructor takes two floating point coordinate arguments and sets * its coordinate attributes to these values and its time stamp to the current session time. * * the X coordinate to assign * the Y coordinate to assign */ public TuioPoint(float xp, float yp) { xpos = xp; ypos = yp; currentTime = TuioTime.SessionTime; startTime = new TuioTime(currentTime); } /** * * This constructor takes a TuioPoint argument and sets its coordinate attributes * to the coordinates of the provided TuioPoint and its time stamp to the current session time. * * the TuioPoint to assign */ public TuioPoint(TuioPoint tpoint) { xpos = tpoint.X; ypos = tpoint.Y; currentTime = TuioTime.SessionTime; startTime = new TuioTime(currentTime); } /** * * This constructor takes a TuioTime object and two floating point coordinate arguments and sets * its coordinate attributes to these values and its time stamp to the provided TUIO time object. * * the TuioTime to assign * the X coordinate to assign * the Y coordinate to assign */ public TuioPoint(TuioTime ttime, float xp, float yp) { xpos = xp; ypos = yp; currentTime = new TuioTime(ttime); startTime = new TuioTime(currentTime); } #endregion #region Update Methods /** * * Takes a TuioPoint argument and updates its coordinate attributes * to the coordinates of the provided TuioPoint and leaves its time stamp unchanged. * * the TuioPoint to assign */ public void update(TuioPoint tpoint) { xpos = tpoint.X; ypos = tpoint.Y; } /** * * Takes two floating point coordinate arguments and updates its coordinate attributes * to the coordinates of the provided TuioPoint and leaves its time stamp unchanged. * * the X coordinate to assign * the Y coordinate to assign */ public void update(float xp, float yp) { xpos = xp; ypos = yp; } /** * * Takes a TuioTime object and two floating point coordinate arguments and updates its coordinate attributes * to the coordinates of the provided TuioPoint and its time stamp to the provided TUIO time object. * * the TuioTime to assign * the X coordinate to assign * the Y coordinate to assign */ public void update(TuioTime ttime, float xp, float yp) { xpos = xp; ypos = yp; currentTime = new TuioTime(ttime); } #endregion #region Properties & Getter/Setter Methods /** * * Returns the X coordinate of this TuioPoint. * the X coordinate of this TuioPoint */ public float X { get { return xpos; } } [Obsolete("This method is provided only for compatability with legacy code. Use of the property instead is recommended.")] public float getX() { return X; } /** * * Returns the Y coordinate of this TuioPoint. * the Y coordinate of this TuioPoint */ public float Y { get { return ypos; } } [Obsolete("This method is provided only for compatability with legacy code. Use of the property instead is recommended.")] public float getY() { return Y; } /** * * Returns the distance to the provided coordinates * * the X coordinate of the distant point * the Y coordinate of the distant point * the distance to the provided coordinates */ public float getDistance(float x, float y) { float dx = xpos - x; float dy = ypos - y; return (float)Math.Sqrt(dx * dx + dy * dy); } /** * * Returns the distance to the provided TuioPoint * * the distant TuioPoint * the distance to the provided TuioPoint */ public float getDistance(TuioPoint tpoint) { return getDistance(tpoint.X, tpoint.Y); } /** * * Returns the angle to the provided coordinates * * the X coordinate of the distant point * the Y coordinate of the distant point * the angle to the provided coordinates */ public float getAngle(float xp, float yp) { float side = xp - xpos; float height = yp - ypos; float distance = getDistance(xp, yp); float angle = (float)(Math.Asin(side / distance) + Math.PI / 2); if (height < 0) angle = 2.0f * (float)Math.PI - angle; return angle; } /** * * Returns the angle to the provided TuioPoint * * the distant TuioPoint * the angle to the provided TuioPoint */ public float getAngle(TuioPoint tpoint) { return getAngle(tpoint.X, tpoint.Y); } /** * * Returns the angle in degrees to the provided coordinates * * the X coordinate of the distant point * the Y coordinate of the distant point * the angle in degrees to the provided TuioPoint */ public float getAngleDegrees(float xp, float yp) { return (getAngle(xp, yp) / (float)Math.PI) * 180.0f; } /** * * Returns the angle in degrees to the provided TuioPoint * * the distant TuioPoint * the angle in degrees to the provided TuioPoint */ public float getAngleDegrees(TuioPoint tpoint) { return (getAngle(tpoint) / (float)Math.PI) * 180.0f; } /** * * Returns the X coordinate in pixels relative to the provided screen width. * * the screen width * the X coordinate of this TuioPoint in pixels relative to the provided screen width */ public int getScreenX(int width) { return (int)Math.Round(xpos * width); } /** * * Returns the Y coordinate in pixels relative to the provided screen height. * * the screen height * the Y coordinate of this TuioPoint in pixels relative to the provided screen height */ public int getScreenY(int height) { return (int)Math.Round(ypos * height); } /** * * Returns the time stamp of this TuioPoint as TuioTime. * * the time stamp of this TuioPoint as TuioTime */ public TuioTime TuioTime { get { return new TuioTime(currentTime); } } [Obsolete("This method is provided only for compatability with legacy code. Use of the property instead is recommended.")] public TuioTime getTuioTime() { return TuioTime; } /** * * Returns the start time of this TuioPoint as TuioTime. * * the start time of this TuioPoint as TuioTime */ public TuioTime StartTime { get { return new TuioTime(startTime); } } [Obsolete("This method is provided only for compatability with legacy code. Use of the property instead is recommended.")] public TuioTime getStartTime() { return StartTime; } #endregion } }