示例#1
0
        public static HolojamObject FromView(HolojamView view)
        {
            HolojamObject o = new HolojamObject(view.Label);

            o.position  = view.RawPosition;
            o.rotation  = view.RawRotation;
            o.bits      = view.Bits;
            o.blob      = view.Blob;
            o.isTracked = view.IsTracked;

            return(o);
        }
示例#2
0
        public void UpdateManagedObjects(HolojamView[] views)
        {
            lock (lockObject) {
                managedObjects.Clear();

                foreach (HolojamView view in views)
                {
                    HolojamObject o = HolojamObject.FromView(view);
                    managedObjects[o.label] = o;
                }
            }
        }
示例#3
0
 public bool GetObject(string key, out HolojamObject holoObject)
 {
     holoObject = null;
     lock (lockObject) {
         if (managedObjects.ContainsKey(key))
         {
             holoObject = managedObjects[key];
             return(true);
         }
         else
         {
             return(false);
         }
     }
 }
示例#4
0
        public void Receive()
        {
            Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);

            socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, 1);
            socket.Bind(new IPEndPoint(IPAddress.Any, port));
            socket.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.AddMembership,
                                   new MulticastOption(IPAddress.Parse(address)));
            socket.ReceiveTimeout = 1000;

            int nBytesReceived = 0;

            while (isRunning)
            {
                nBytesReceived = socket.Receive(currentPacket.bytes);
                currentPacket.stream.Position = 0;

                update = Serializer.Deserialize <update_protocol_v3.Update>(
                    new MemoryStream(currentPacket.bytes, 0, nBytesReceived)
                    );

                //currentPacket.frame = update.mod_version;
                //if(currentPacket.frame>previousPacket.frame){

                packetCount++;

                previousPacket.stream.Position = 0;
                currentPacket.stream.Position  = 0;
                tempPacket.copyFrom(previousPacket);
                previousPacket.copyFrom(currentPacket);
                currentPacket.copyFrom(tempPacket);
                lock (lockObject) {
                    //managedObjects.Clear();

                    for (int j = 0; j < update.live_objects.Count; j++)
                    {
                        LiveObject or    = update.live_objects[j];
                        string     label = or.label;

                        objectTimers[label] = 0;                       //Reset timer--we received data for this object

                        HolojamObject ho;

                        //Reform managedObjects every frame.
                        //Inefficient for now, but will allow us to determine
                        //if an object is registered.

                        ho = new HolojamObject(label);
                        managedObjects[label] = ho;

                        if (update.lhs_frame)
                        {
                            ho.position = new Vector3(-(float)or.x, (float)or.y, (float)or.z);
                            ho.rotation = new Quaternion(-(float)or.qx,
                                                         (float)or.qy,
                                                         (float)or.qz,
                                                         -(float)or.qw);
                        }
                        else
                        {
                            ho.position = new Vector3((float)or.x, (float)or.y, (float)or.z);
                            ho.rotation = new Quaternion((float)or.qx,
                                                         (float)or.qy,
                                                         (float)or.qz,
                                                         (float)or.qw);
                        }
                        ho.bits = or.button_bits;

                        //Get blob if it's there. Inefficient
                        ho.blob = or.extra_data;

                        ho.isTracked = or.is_tracked;
                    }
                }

                if (!isRunning)
                {
                    socket.Close();
                    break;
                }
            }
        }