Ejemplo n.º 1
0
        private void toasst_Click(object sender, EventArgs e)
        {
            ToastWindow toastWindow = new ToastWindow();

            Global.toastString = "测试输出";
            toastWindow.Show();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 接收消息
        /// </summary>
        /// <param name="clientSocket"></param>
        private static void UdpReceiveMessage(byte[] buffer, int length)
        {
            try
            {
                //弹窗提示消息
                string receiveStr1 = Encoding.UTF8.GetString(buffer);
                //string receiveStr1 = Encoding.UTF8.GetString(buffer);


                string[] dataStrs = receiveStr1.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);

                foreach (var dataStr in dataStrs)
                {
                    try
                    {
                        //判断语音flag
                        if (dataStr.Length >= 6)
                        {
                            if (dataStr.Substring(0, 6).Equals("voice,"))
                            {
                                var voicestr = dataStr.Substring(6, dataStr.Length - 6);


                                if (voicestr.Contains("打开水果忍者"))
                                {
                                    StartHelper.OpenGame();
                                }
                                else if (voicestr.Contains("关闭水果忍者"))
                                {
                                    StartHelper.CloseGame(_mainform);
                                }
                                else if (voicestr.Contains("请问"))
                                {
                                    if (voicestr.Contains("时间") || voicestr.Contains("几点"))
                                    {
                                        Global.toastString = "现在是北京时间:凌晨2点";
                                    }
                                    else if (voicestr.Contains("天气"))
                                    {
                                        Global.toastString = "今天多云,27摄氏度至35摄氏度微风,空气质量良好。";
                                    }
                                    ToastWindow toastWindow = new ToastWindow();
                                    toastWindow.Show();
                                }
                                else
                                {
                                    //设置到剪贴板
                                    _mainform.Invoke((MethodInvoker) delegate
                                    {
                                        Clipboard.SetText(voicestr);
                                        SendKeys.Send("^{V}");
                                    });
                                }



                                //MessageBox.Show("粘贴成功:"+voicestr);
                                return;
                            }
                        }

                        if (dataStr.Equals("mouse_on"))
                        {
                            mousePosUpdater.startTrigger();
                        }
                        else if (dataStr.Equals("mouse_off"))
                        {
                            mousePosUpdater.stopTrigger();
                        }
                        else if (dataStr.Equals("mouse_down"))
                        {
                            //鼠标点下
                            isMouseDown = true;
                            mouse_event(MOUSEEVENTF_LEFTDOWN, (uint)lastMouseX, (uint)lastMouseY, 1, 1);
                            return;
                        }
                        else if (dataStr.Equals("mouse_up"))
                        {
                            //鼠标抬起
                            isMouseDown = false;
                            mouse_event(MOUSEEVENTF_LEFTUP, (uint)lastMouseX, (uint)lastMouseY, 1, 1);
                            return;
                        }
                        else if (dataStr.Equals("eyecare_on"))
                        {
                            _mainform.Invoke((MethodInvoker) delegate
                            {
                                _mainform.Visible = true;
                            });
                            headPosUpdater.startTrigger();
                        }
                        else if (dataStr.Equals("eyecare_off"))
                        {
                            _mainform.Invoke((MethodInvoker) delegate
                            {
                                _mainform.Visible = false;
                            });
                            headPosUpdater.stopTrigger();
                        }
                        else if (dataStr.Equals("3d_on"))
                        {
                            rotateUpdater.startTrigger();
                        }
                        else if (dataStr.Equals("3d_off"))
                        {
                            rotateUpdater.stopTrigger();
                        }
                        else if (dataStr.Equals("game_start"))
                        {
                            //调用打开水果忍者
                            StartHelper.OpenGame();
                        }
                        else if (dataStr.Equals("app_confirm"))
                        {
                            StartHelper.KeyEnter(_mainform);
                        }
                        else if (dataStr.Equals("app_exit"))
                        {
                            StartHelper.CloseGame(_mainform);
                        }
                        else if (dataStr.Equals("note_open"))
                        {
                            StartHelper.OpenNote();
                        }
                        else if (dataStr.Equals("app_save"))
                        {
                            StartHelper.KeySave(_mainform);
                        }
                        else if (dataStr.Equals("open_office"))
                        {
                            StartHelper.OpenOffice();
                        }
                        else if (dataStr.Equals("play_ppt"))
                        {
                            StartHelper.KeyPlayPPT(_mainform);
                        }
                        else if (dataStr.Equals("ppt_painter"))
                        {
                            StartHelper.KeyToPaint(_mainform);
                        }
                        else if (dataStr.Equals("ppt_laser"))
                        {
                            StartHelper.KeyToLaser(_mainform);
                        }
                        else if (dataStr.Equals("key_left"))
                        {
                            StartHelper.KeyLeft(_mainform);
                        }
                        else if (dataStr.Equals("key_right"))
                        {
                            StartHelper.KeyRight(_mainform);
                        }
                        else if (dataStr.Equals("play_video"))
                        {
                            StartHelper.PlayVideo();
                        }
                        else if (dataStr.Equals("open_3d"))
                        {
                            _mainform.Invoke((MethodInvoker) delegate
                            {
                                StartHelper.Open3DView();
                            });
                        }
                        else if (dataStr.Equals("close_3d"))
                        {
                            _mainform.Invoke((MethodInvoker) delegate
                            {
                                StartHelper.Close3DView();
                            });
                        }



                        String str0 = dataStr.Split(',')[0];
                        String str1 = dataStr.Split(',')[1];
                        String str2 = dataStr.Split(',')[2];

                        if (str0.Equals("ol"))
                        {
                            String str3 = "";
                            String str4 = "";

                            str3 = dataStr.Split(',')[3];

                            str4 = dataStr.Split(',')[4];

                            var thisRX = float.Parse(str1) - initRotate_X;
                            var thisRY = float.Parse(str2) - initRotate_Y;
                            var thisRZ = float.Parse(str3) - initRotate_Z;

                            rotateUpdater.postValue(new float[] { thisRX, thisRZ, thisRY, 0 });
                            //rotateUpdater.postValue(new float[] { thisRX + (float)Math.PI / 2f, thisRZ + (float)Math.PI, thisRY });
                            //rotateUpdater.startTrigger();
                            //Global.Viewer3DCamera[0] = thisRZ;
                            //Global.Viewer3DCamera[1] = thisRX;

                            var xx = (float)(thisRX);
                            var yy = (float)(thisRY);
                            var zz = (float)(thisRZ);



                            //这里改代码

                            float act_screenBottomHeight = 0.874f; //投影幕布底部距离地面距离
                            float act_screenLeft         = 0.686f; //投影幕布左侧距离坐标原点的水平距离


                            float posX = (float)Global.Position[0];
                            float posY = (float)Global.Position[1];
                            float posZ = (float)Global.Position[2];

                            Global.Viewer3DCamera = new double[] { posX, posY, posZ };


                            float act_screen_width  = 2.584f;
                            float act_screen_height = 1.632f;

                            float pix_screen_width  = 1920f;
                            float pix_screen_height = 1080f;

                            float act_start_x = posY - act_screenLeft;
                            float act_start_y = posZ - act_screenBottomHeight;


                            float act_screen_distance = posX;//距离屏幕距离

                            float pix_start_x = act_start_x / act_screen_width * pix_screen_width;
                            float pix_start_y = act_start_y / act_screen_height * pix_screen_height;

                            float act_pix_ratio_x = pix_screen_width / act_screen_width;
                            float act_pix_ratio_y = pix_screen_height / act_screen_height;

                            float mul_x = act_screen_distance * act_pix_ratio_x;
                            float mul_y = act_screen_distance * act_pix_ratio_y;

                            int corsorX = (int)Math.Round(pix_start_x - mul_x * Math.Tan(thisRZ));
                            int corsorY = (int)Math.Round(pix_screen_height - pix_start_y - mul_y * Math.Tan(thisRX));

                            //Global.XMovingAverage.Push(corsorX);
                            //Global.YMovingAverage.Push(corsorY);


                            //int realCursorX = (int)Global.XMovingAverage.Current;
                            //int realCursorY = (int)Global.YMovingAverage.Current;

                            mousePosUpdater.postValue(new float[] { (float)corsorX, (float)corsorY });
                            //mousePosUpdater.startTrigger();//开始事件通知

                            //if (str4.Equals("1"))
                            //{
                            //    //1代表按下瞬间
                            //    mouse_event(MOUSEEVENTF_LEFTDOWN, (uint)corsorX, (uint)corsorY, 1, 1);
                            //}
                            //else if (str4.Equals("2"))
                            //{
                            //    mouse_event(MOUSEEVENTF_LEFTUP, (uint)corsorX, (uint)corsorY, 1, 1);
                            //}

                            return;
                        }
                        //else if (str0.Equals("ax"))
                        //{

                        //    String str3 = "";
                        //    String str4 = "";

                        //    str3 = dataStr.Split(',')[3];

                        //    str4 = dataStr.Split(',')[4];

                        //    var thisRX = float.Parse(str1);
                        //    var thisRY = float.Parse(str2);
                        //    var thisRZ = float.Parse(str3);
                        //    var thisRW = float.Parse(str4);

                        //    //接受轴向角的信息
                        //    rotateUpdater.postValue(new float[] { thisRX, thisRY, thisRZ, thisRW });

                        //    return;


                        //}
                        else if (str0.Equals("m"))
                        {
                            //String str3 = "";

                            //if (dataStr.Split(',').Length > 3)
                            //    str3 = dataStr.Split(',')[3];


                            ////鼠标移动定位的代码应该就在这里
                            //_mainform.Invoke((MethodInvoker)delegate
                            //{
                            //    if (str3 != "")
                            //    {
                            //        _mainform.Width = Int32.Parse(str3);
                            //        _mainform.Height = Int32.Parse(str3);
                            //    }
                            //    try
                            //    {
                            //        //SetPosition((int)(Int32.Parse(str1) - _mainform.Width / 2f), (int)(Int32.Parse(str2) - _mainform.Height / 2f));

                            //        float mul = 1920f / 1.12f; //这是2.14是距离屏幕的距离


                            //        SetCursorPos((int)(Int32.Parse(str1) - _mainform.Width / 2f), (int)(Int32.Parse(str2) - _mainform.Height / 2f));
                            //    }
                            //    catch (Exception ex)
                            //    {
                            //    }

                            //});
                        }
                        else if (str0.Equals("b"))
                        {
                            //if (Global.shouldShowHideBlock == false)
                            //    return;
                            // EyeCare 接受坐标
                            String str3 = "";

                            if (dataStr.Split(',').Length > 3)
                            {
                                str3 = dataStr.Split(',')[3];
                            }


                            //post 窗口位置和大小
                            if (str3 != "")
                            {
                                //配置窗口宽度
                                float w = float.Parse(str3);
                                float h = float.Parse(str3);

                                float X = float.Parse(str1);
                                float Y = float.Parse(str2);

                                float thisX = X - w / 2f;
                                float thisY = Y - h / 2f;

                                //更新记录最新坐标
                                lastMouseX = thisX;
                                lastMouseY = thisY;
                                headPosUpdater.postValue(new float[] { thisX, thisY, float.Parse(str3) });
                                //headPosUpdater.startTrigger();//当识别到人就触发窗口更新
                            }
                        }
                        else if (str0.Equals("nb"))
                        {
                            //当未识别到人就隐藏黑块
                            //shouldBlockShow = false;

                            _mainform.Invoke((MethodInvoker) delegate
                            {
                                //_mainform.Visible = false;
                                //headPosUpdater.stopTrigger();//当没识别到人就停止出发窗口更新
                            });
                        }
                        else if (str0.Equals("reset"))
                        {
                            //执行校准
                            String str3 = "";
                            String str4 = "";

                            str3 = dataStr.Split(',')[3];

                            str4 = dataStr.Split(',')[4];
                            //initRotate_X = float.Parse(str1);
                            //initRotate_Y = float.Parse(str2);
                            //initRotate_Z = float.Parse(str3);


                            initRotate_X = 0;
                            initRotate_Y = 0;
                            initRotate_Z = float.Parse(str3);

                            if (str4.Equals("1"))
                            {
                                iskeydown = 1;
                            }
                            else
                            {
                                iskeydown = 0;
                            }
                        }
                        else if (str0.Equals("dp"))
                        {
                            //执行校准
                            String str3 = "";
                            String str4 = "";

                            str3 = dataStr.Split(',')[3];

                            str4 = dataStr.Split(',')[4];
                            //initRotate_X = float.Parse(str1);
                            //initRotate_Y = float.Parse(str2);
                            //initRotate_Z = float.Parse(str3);

                            //这里调用景深
                            float depth = float.Parse(str3);

                            Constant.SendViewer3DDistance(depth);
                            return;
                        }
                    }
                    catch (Exception ex)
                    {
                        ;
                    }
                }
            }
            catch (Exception ex)
            {
                /*
                 * Console.WriteLine(ex.Message);
                 *
                 * myClientSocket.Shutdown(SocketShutdown.Both);//禁止发送和上传
                 * myClientSocket.Close();//关闭Socket并释放资源
                 * break;*/
            }
            //Thread.Sleep(1);
        }