|
@@ -11,30 +11,85 @@ using bbiwarg.Utility;
|
|
|
|
|
|
namespace TUIO
|
|
|
{
|
|
|
+ /// <summary>
|
|
|
+ /// Tuio server class to send tuio cursors and objects to tuio clients.
|
|
|
+ /// </summary>
|
|
|
class TuioServer
|
|
|
{
|
|
|
+ /// <summary>
|
|
|
+ /// the maximum packet size
|
|
|
+ /// </summary>
|
|
|
const int MAX_PACKET_SIZE = 65535 - 8;
|
|
|
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// transmitter to send packages over udp
|
|
|
+ /// </summary>
|
|
|
private OSCTransmitter transmitter = null;
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// server ip address
|
|
|
+ /// </summary>
|
|
|
private String host = "127.0.0.1";
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// server port
|
|
|
+ /// </summary>
|
|
|
private int port = 3333;
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// tuio session id
|
|
|
+ /// </summary>
|
|
|
private long sessionID = 0;
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// current tuio time
|
|
|
+ /// </summary>
|
|
|
private TuioTime currentFrameTime;
|
|
|
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// list of generated cursors
|
|
|
+ /// </summary>
|
|
|
private List<TuioCursor> cursorList;
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// list of cursors updated in the current frame
|
|
|
+ /// </summary>
|
|
|
private List<TuioCursor> updatedCursorList;
|
|
|
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// list of all generated objects
|
|
|
+ /// </summary>
|
|
|
private List<TuioObject> objectList;
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// list of objects updated in the current frame
|
|
|
+ /// </summary>
|
|
|
private List<TuioObject> updatedObjectList;
|
|
|
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// Creates a tuio server with default ip and port.
|
|
|
+ /// </summary>
|
|
|
public TuioServer() { init(); }
|
|
|
|
|
|
+ /// <summary>
|
|
|
+ /// Creates a tuio server with default ip.
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="port">server port</param>
|
|
|
public TuioServer(int port)
|
|
|
{
|
|
|
this.port = port;
|
|
|
init();
|
|
|
}
|
|
|
|
|
|
+ /// <summary>
|
|
|
+ /// Creates a tuio server.
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="host">server ip</param>
|
|
|
+ /// <param name="port">server port</param>
|
|
|
public TuioServer(String host, int port)
|
|
|
{
|
|
|
this.host = host;
|
|
@@ -42,6 +97,9 @@ namespace TUIO
|
|
|
init();
|
|
|
}
|
|
|
|
|
|
+ /// <summary>
|
|
|
+ /// Initializes the server, cursors and objects.
|
|
|
+ /// </summary>
|
|
|
private void init()
|
|
|
{
|
|
|
TuioTime.initSession();
|
|
@@ -50,12 +108,20 @@ namespace TUIO
|
|
|
transmitter = new OSCTransmitter(host, port);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
+ /// <summary>
|
|
|
+ /// Closes the transmission.
|
|
|
+ /// </summary>
|
|
|
public void close()
|
|
|
{
|
|
|
transmitter.Close();
|
|
|
}
|
|
|
|
|
|
+ /// <summary>
|
|
|
+ /// Adds and returns a tuio cursor.
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="xp">x position of the cursor</param>
|
|
|
+ /// <param name="yp">y position of the cursor</param>
|
|
|
+ /// <returns>the added cursor</returns>
|
|
|
public TuioCursor addTuioCursor(float xp, float yp)
|
|
|
{
|
|
|
TuioCursor tcur = new TuioCursor(sessionID, cursorList.Count, xp, yp);
|
|
@@ -66,6 +132,12 @@ namespace TUIO
|
|
|
return tcur;
|
|
|
}
|
|
|
|
|
|
+ /// <summary>
|
|
|
+ /// Updates a tui cursor.
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="tcur">the cursor to update</param>
|
|
|
+ /// <param name="xp">new x position</param>
|
|
|
+ /// <param name="yp">new y position</param>
|
|
|
public void updateTuioCursor(TuioCursor tcur, float xp, float yp)
|
|
|
{
|
|
|
tcur.update(currentFrameTime, xp, yp);
|
|
@@ -73,11 +145,22 @@ namespace TUIO
|
|
|
updatedCursorList.Add(tcur);
|
|
|
}
|
|
|
|
|
|
+ /// <summary>
|
|
|
+ /// Removes a tuio cursor.
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="tcur">the cursor to remove</param>
|
|
|
public void removeTuioCursor(TuioCursor tcur)
|
|
|
{
|
|
|
cursorList.Remove(tcur);
|
|
|
}
|
|
|
|
|
|
+ /// <summary>
|
|
|
+ /// Adds and returns tuio object.
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="xp">x position of the object</param>
|
|
|
+ /// <param name="yp">y position of the object</param>
|
|
|
+ /// <param name="angle">angle of the object</param>
|
|
|
+ /// <returns>the added object</returns>
|
|
|
public TuioObject addTuioObject(float xp, float yp, float angle)
|
|
|
{
|
|
|
TuioObject tobj = new TuioObject(sessionID, objectList.Count, xp, yp, angle);
|
|
@@ -88,6 +171,12 @@ namespace TUIO
|
|
|
return tobj;
|
|
|
}
|
|
|
|
|
|
+ /// <summary>
|
|
|
+ /// Updates a tuio object.
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="tobj">the object to update</param>
|
|
|
+ /// <param name="xp">new x position</param>
|
|
|
+ /// <param name="yp">new y position</param>
|
|
|
public void updateTuioObject(TuioObject tobj, float xp, float yp)
|
|
|
{
|
|
|
tobj.update(currentFrameTime, xp, yp);
|
|
@@ -95,11 +184,18 @@ namespace TUIO
|
|
|
updatedObjectList.Add(tobj);
|
|
|
}
|
|
|
|
|
|
+ /// <summary>
|
|
|
+ /// Removes a tuio object.
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="tobj">the object to remove</param>
|
|
|
public void removeTuioObject(TuioObject tobj)
|
|
|
{
|
|
|
objectList.Remove(tobj);
|
|
|
}
|
|
|
|
|
|
+ /// <summary>
|
|
|
+ /// Initializes cursor and object lists for sending information for a new frame.
|
|
|
+ /// </summary>
|
|
|
public void initFrame()
|
|
|
{
|
|
|
currentFrameTime = TuioTime.getSessionTime();
|
|
@@ -107,16 +203,27 @@ namespace TUIO
|
|
|
updatedObjectList = new List<TuioObject>();
|
|
|
}
|
|
|
|
|
|
+ /// <summary>
|
|
|
+ /// Sends cursors and objects which were updated in the current frame.
|
|
|
+ /// </summary>
|
|
|
public void commitFrame()
|
|
|
{
|
|
|
sendMessage(updatedCursorList, updatedObjectList);
|
|
|
}
|
|
|
|
|
|
+ /// <summary>
|
|
|
+ /// Sends all cursors and objects.
|
|
|
+ /// </summary>
|
|
|
public void sendFullMessages()
|
|
|
{
|
|
|
sendMessage(cursorList, objectList);
|
|
|
}
|
|
|
|
|
|
+ /// <summary>
|
|
|
+ /// Sends cursors and objects.
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="cursorList">list of cursors to send</param>
|
|
|
+ /// <param name="objectList">list of objects to send</param>
|
|
|
private void sendMessage(List<TuioCursor> cursorList, List<TuioObject> objectList)
|
|
|
{
|
|
|
OSCBundle packet = new OSCBundle();
|
|
@@ -136,15 +243,6 @@ namespace TUIO
|
|
|
currentMessage.Append(tcur.getXSpeed());
|
|
|
currentMessage.Append(tcur.getYSpeed());
|
|
|
currentMessage.Append(tcur.getMotionAccel());
|
|
|
-
|
|
|
- /*if (Marshal.SizeOf(packet) + Marshal.SizeOf(currentOscElement) >= MAX_PACKET_SIZE)
|
|
|
- {
|
|
|
- packet.AddElement(new OscElement("/tuio/2Dcur", new Object[] { "fseq", -1 }));
|
|
|
- udpwriter.Send(packet);
|
|
|
-
|
|
|
- packet = new OscBundle();
|
|
|
- addAliveCursorMessagesToBundle(packet);
|
|
|
- }*/
|
|
|
packet.Append(currentMessage);
|
|
|
}
|
|
|
currentMessage = new OSCMessage("/tuio/2Dcur");
|
|
@@ -185,6 +283,10 @@ namespace TUIO
|
|
|
transmitter.Send(packet);
|
|
|
}
|
|
|
|
|
|
+ /// <summary>
|
|
|
+ /// Adds a tuio cursor alive message to a packet.
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="packet">packet to add the message to</param>
|
|
|
private void addAliveCursorMessagesToBundle(OSCBundle packet)
|
|
|
{
|
|
|
OSCMessage mssg = new OSCMessage("/tuio/2Dcur");
|
|
@@ -196,6 +298,10 @@ namespace TUIO
|
|
|
packet.Append(mssg);
|
|
|
}
|
|
|
|
|
|
+ /// <summary>
|
|
|
+ /// Adds a tuio object alive message to a packet.
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="packet">packet to add the message to</param>
|
|
|
private void addAliveObjectMessagesToBundle(OSCBundle packet)
|
|
|
{
|
|
|
OSCMessage mssg = new OSCMessage("/tuio/2Dobj");
|