public static void CreateMultiMeshBuffer(Vector3 center, Vector3 size, int xCount, int yCount, int zCount, MeshGeometry3D meshGeometry3D,
                                                 out PositionNormalTexture[] vertexBuffer, out int[] indexBuffer)
        {
            // Because we will iterate through Positions, Normals and other collections multiple times,
            // we copy the data into simple arrays because accessing simple arrays is significantly faster then Point3DCollections and other collection
            // (the reason for that is that in each getter in Point3DCollections there is a check if we are on the correct thread - the one that created the collection).
            var positionsCount = meshGeometry3D.Positions.Count;

            var positions = new Point3D[positionsCount];

            meshGeometry3D.Positions.CopyTo(positions, 0);


            if (meshGeometry3D.Normals.Count < positionsCount) // Each position must have its Normal
            {
                throw new Exception("Invalid Normals");
            }

            var normals = new Vector3D[positionsCount];

            meshGeometry3D.Normals.CopyTo(normals, 0);


            // If we do not use textures, we can skip TextureCoordinates
            Point[] textureCoordinates;

            if (meshGeometry3D.TextureCoordinates != null && meshGeometry3D.TextureCoordinates.Count > 0)
            {
                if (meshGeometry3D.TextureCoordinates.Count < positionsCount)
                {
                    throw new Exception("Invalid TextureCoordinates");
                }

                textureCoordinates = new System.Windows.Point[positionsCount];
                meshGeometry3D.TextureCoordinates.CopyTo(textureCoordinates, 0);
            }
            else
            {
                textureCoordinates = null;
            }


            var triangleIndicesCount = meshGeometry3D.TriangleIndices.Count;
            var triangleIndices      = new Int32[triangleIndicesCount];

            meshGeometry3D.TriangleIndices.CopyTo(triangleIndices, 0);



            float xStep = (float)(size.X / xCount);
            float yStep = (float)(size.Y / yCount);
            float zStep = (float)(size.Z / zCount);

            vertexBuffer = new PositionNormalTexture[positionsCount * xCount * yCount * zCount];
            indexBuffer  = new int[triangleIndicesCount * xCount * yCount * zCount];

            int vertexBufferIndex = 0;
            int indexBufferIndex  = 0;

            for (int y = 0; y < yCount; y++)
            {
                float yPos = (float)(center.Y - (size.Y / 2.0) + (y * yStep));

                for (int z = 0; z < zCount; z++)
                {
                    float zPos = (float)(center.Z - (size.Z / 2.0) + (z * zStep));

                    for (int x = 0; x < xCount; x++)
                    {
                        float xPos = (float)(center.X - (size.X / 2.0) + (x * xStep));


                        // Save index for the start of the mesh
                        int vertexBufferStartIndex = vertexBufferIndex;

                        if (textureCoordinates != null)
                        {
                            for (int positionIndex = 0; positionIndex < positionsCount; positionIndex++)
                            {
                                // TODO: We could further optimize this with converting positions, normals and textureCoordinates to Vector3 arrays before entering the loops
                                vertexBuffer[vertexBufferIndex] = new PositionNormalTexture(
                                    new Vector3((float)positions[positionIndex].X + xPos, (float)positions[positionIndex].Y + yPos, (float)positions[positionIndex].Z + zPos),
                                    normals[positionIndex].ToVector3(),
                                    new Vector2((float)textureCoordinates[positionIndex].X, (float)textureCoordinates[positionIndex].Y));

                                vertexBufferIndex++;
                            }
                        }
                        else
                        {
                            for (int positionIndex = 0; positionIndex < positionsCount; positionIndex++)
                            {
                                vertexBuffer[vertexBufferIndex] = new PositionNormalTexture(
                                    new Vector3((float)positions[positionIndex].X + xPos, (float)positions[positionIndex].Y + yPos, (float)positions[positionIndex].Z + zPos),
                                    normals[positionIndex].ToVector3(),
                                    new Vector2(0, 0));

                                vertexBufferIndex++;
                            }
                        }


                        for (int instanceIndex = 0; instanceIndex < triangleIndicesCount; instanceIndex++)
                        {
                            indexBuffer[indexBufferIndex] = triangleIndices[instanceIndex] + vertexBufferStartIndex;
                            indexBufferIndex++;
                        }
                    }
                }
            }
        }
        private void InitializeBombAnimation()
        {
            Image bombDragImage = null;
            Image bombDropImage = null;

            BitmapImage bombDragBitmap;
            BitmapImage bombDropBitmap;

            var fileStream1 = Application.GetResourceStream(new Uri("/PhotoHuntAsianBeauty3;component/Images/ItemImages/icon_item1.png", UriKind.Relative));
            using (var stream = fileStream1.Stream) {
                bombDragBitmap = new BitmapImage();
                bombDragBitmap.SetSource(stream);
            }

            var fileStream2 = Application.GetResourceStream(new Uri("/PhotoHuntAsianBeauty3;component/Images/ItemImages/icon_item1.png", UriKind.Relative));
            using (var stream = fileStream2.Stream) {
                bombDropBitmap = new BitmapImage();
                bombDropBitmap.SetSource(stream);
            }

            var bombGestureService = GestureService.GetGestureListener(BombImage);

            var timer = new DispatcherTimer {Interval = TimeSpan.FromSeconds(3.0)};
            var startPoint = new System.Windows.Point();

            EventHandler timerTickHandler = null;

            var dragCompleteHandler = new EventHandler<DragCompletedGestureEventArgs>(delegate(object sender, DragCompletedGestureEventArgs args) {
                if (timer.IsEnabled) {
                    timer.Stop();
                    timer.Tick -= timerTickHandler;
                }
                if (int.Parse(BombItem.HasObtained) <= 0) return;

                bombDropImage = new Image {
                    RenderTransform = new CompositeTransform(),
                    Width = 90,
                    Height = 80,
                    Source = bombDropBitmap
                };

                var point = new System.Windows.Point();
                if (args != null)
                    point = args.GetPosition(LayoutRoot);
                else {
                    var transform = bombDragImage.RenderTransform as CompositeTransform;
                    point = new System.Windows.Point(startPoint.X + transform.TranslateX, startPoint.Y + transform.TranslateY);
                }

                UpperEffectCanvas.Children.Remove(bombDragImage);

                Canvas.SetLeft(bombDropImage, point.X - bombDropImage.Width / 2);
                Canvas.SetTop(bombDropImage, point.Y - bombDropImage.Height / 2);

                BombItem.HasObtained = int.Parse(BombItem.HasObtained) - 1 + "";
                BombCount.Text = BombItem.HasObtained;

                UpperEffectCanvas.Children.Add(bombDropImage);
                PlayExplodeAnimation(bombDropImage);

                _numBombsUsed += 1;
            });

            var dragDeltaHandler = new EventHandler<DragDeltaGestureEventArgs>(delegate(object sender, DragDeltaGestureEventArgs args) {
                if (int.Parse(BombItem.HasObtained) <= 0) return;
                var transform = bombDragImage.RenderTransform as CompositeTransform;
                if (transform != null) {
                    transform.TranslateX += args.HorizontalChange;
                    transform.TranslateY += args.VerticalChange;
                }
            });

            var dragStartHandler = new EventHandler<DragStartedGestureEventArgs>(delegate(object sender, DragStartedGestureEventArgs args) {
                if (int.Parse(BombItem.HasObtained) <= 0) return;
                bombDragImage = new Image {
                    RenderTransform = new CompositeTransform(),
                    Width = 90,
                    Height = 80,
                    Source = bombDragBitmap
                };

                var point = args.GetPosition(LayoutRoot);
                startPoint = point;

                Canvas.SetLeft(bombDragImage, point.X - bombDragImage.Width / 2);
                Canvas.SetTop(bombDragImage, point.Y - bombDragImage.Height / 2);

                UpperEffectCanvas.Children.Add(bombDragImage);

                timerTickHandler = (o, eventArgs) =>{
                    timer.Stop();
                    timer.Tick -= timerTickHandler;
                    bombGestureService.DragCompleted -= dragCompleteHandler;
                    if (int.Parse(BombItem.HasObtained) <= 0) return;
                    dragCompleteHandler(null, null);
                };
                timer.Tick += timerTickHandler;
                timer.Start();
            });

            bombGestureService.DragStarted += dragStartHandler;
            bombGestureService.DragDelta += dragDeltaHandler;
            bombGestureService.DragCompleted += dragCompleteHandler;
        }
Exemplo n.º 3
0
 internal bool HandleMouseMove(object sender, System.Windows.Point mouseCursor)
 {
     return(stateMachine.HandleMouseMove(sender, mouseCursor));
 }
        private void DrawGrid(WriteableBitmap bitmap)
        {
            if (CentralPoint.X == 0 && CentralPoint.Y == 0)
            {
                CentralPoint = new System.Windows.Point(bitmap.PixelWidth / 2, bitmap.PixelHeight / 2);
            }
            WriteableBitmap tempbitmap = new WriteableBitmap(bitmap.PixelWidth, bitmap.PixelHeight, bitmap.DpiX,
                                                             bitmap.DpiY, PixelFormats.Pbgra32, bitmap.Palette);

            tempbitmap.DrawLine(0, (int)CentralPoint.Y - (StarWindowSize / 2), bitmap.PixelWidth, (int)CentralPoint.Y - (StarWindowSize / 2), Colors.White);
            tempbitmap.DrawLine(0, (int)CentralPoint.Y + (StarWindowSize / 2), bitmap.PixelWidth, (int)CentralPoint.Y + (StarWindowSize / 2), Colors.White);

            tempbitmap.DrawLine((int)CentralPoint.X - (StarWindowSize / 2), 0, (int)CentralPoint.X - (StarWindowSize / 2), bitmap.PixelHeight, Colors.White);
            tempbitmap.DrawLine((int)CentralPoint.X + (StarWindowSize / 2), 0, (int)CentralPoint.X + (StarWindowSize / 2), bitmap.PixelHeight, Colors.White);

            bitmap.Blit(new Rect(0, 0, bitmap.PixelWidth, bitmap.PixelHeight), tempbitmap,
                        new Rect(0, 0, bitmap.PixelWidth, bitmap.PixelHeight));

        }
Exemplo n.º 5
0
        void nui_AllFramesReady(object sender, AllFramesReadyEventArgs e)
        {
            ColorImageFrame cf = e.OpenColorImageFrame();
            DepthImageFrame df = e.OpenDepthImageFrame();
            SkeletonFrame sf = e.OpenSkeletonFrame();

            //            Skeleton[] skeletonData = new Skeleton[sf.SkeletonArrayLength];

            if (cf == null || df == null || sf == null)
            {
                return;
            }


            byte[] ImageBits = new byte[cf.PixelDataLength];
            cf.CopyPixelDataTo(ImageBits);

            BitmapSource src = null;
            src = BitmapSource.Create(cf.Width, cf.Height,
                                        96, 96, PixelFormats.Bgr32, null,
                                        ImageBits,
                                        cf.Width * cf.BytesPerPixel);
            image2.Source = src;



            // Check for image format changes.  The FaceTracker doesn't
            // deal with that so we need to reset.
            if (this.depthImageFormat != df.Format)
            {
                this.ResetFaceTracking();
                this.depthImage = null;
                this.depthImageFormat = df.Format;
            }

            if (this.colorImageFormat != cf.Format)
            {
                this.ResetFaceTracking();
                this.colorImage = null;
                this.colorImageFormat = cf.Format;
            }

            // Create any buffers to store copies of the data we work with
            if (this.depthImage == null)
            {
                this.depthImage = new short[df.PixelDataLength];
            }

            if (this.colorImage == null)
            {
                this.colorImage = new byte[cf.PixelDataLength];
            }

            // Get the skeleton information
            if (this.skeletonData == null || this.skeletonData.Length != sf.SkeletonArrayLength)
            {
                this.skeletonData = new Skeleton[sf.SkeletonArrayLength];
            }

            cf.CopyPixelDataTo(this.colorImage);
            df.CopyPixelDataTo(this.depthImage);
            sf.CopySkeletonDataTo(this.skeletonData);

            foreach (Skeleton skeleton in this.skeletonData)
            {
                if (skeleton.TrackingState == SkeletonTrackingState.Tracked
                    || skeleton.TrackingState == SkeletonTrackingState.PositionOnly)
                {
                    // We want keep a record of any skeleton, tracked or untracked.
                    if (!this.trackedSkeletons.ContainsKey(skeleton.TrackingId))
                    {
                        this.trackedSkeletons.Add(skeleton.TrackingId, new SkeletonFaceTracker());
                    }

                    // Give each tracker the upated frame.
                    SkeletonFaceTracker skeletonFaceTracker;
                    if (this.trackedSkeletons.TryGetValue(skeleton.TrackingId, out skeletonFaceTracker))
                    {
                        skeletonFaceTracker.OnFrameReady(nui2, colorImageFormat, colorImage, depthImageFormat, depthImage, skeleton);
                        skeletonFaceTracker.LastTrackedFrame = sf.FrameNumber;
                    }
                }
            }



            using (DepthImageFrame depthImageFrame = e.OpenDepthImageFrame())
            {
                if (depthImageFrame != null)
                {
                    foreach (Skeleton sd in skeletonData)
                    {
                        if (sd.TrackingState == SkeletonTrackingState.Tracked)
                        {
                            Joint joint = sd.Joints[JointType.Head];

                            DepthImagePoint depthPoint;

                            //                            CoordinateMapper coordinateMapper = new CoordinateMapper(nui);
                            //                            depthPoint = coordinateMapper.MapSkeletonPointToDepthPoint(joint.Position, DepthImageFormat.Resolution320x240Fps30);

                            depthPoint = depthImageFrame.MapFromSkeletonPoint(joint.Position);

                            System.Windows.Point point = new System.Windows.Point((int)(image2.ActualWidth * depthPoint.X
                                                               / depthImageFrame.Width),
                                                    (int)(image2.ActualHeight * depthPoint.Y
                                                               / depthImageFrame.Height));


                            Canvas.SetLeft(ellipse1, (point.X) - ellipse1.Width);
                            Canvas.SetTop(ellipse1, (point.Y) - ellipse1.Height);

                            App thisApp = App.Current as App;

                            Canvas.SetLeft(rect2, thisApp.m_dbX - rect2.Width);
                            Canvas.SetTop(rect2, thisApp.m_dbY - rect2.Height);

                            double GapX, GapY;
                            GapX = point.X - (thisApp.m_dbX - 2) ;
                            GapY = point.Y - (thisApp.m_dbY - 2) ;

                            int siteX = 999, siteY = 999;

                            if (GapX < 30 && GapX > -30)
                                siteX = 1;
                            else if (GapX >= 30)
                                siteX = 0;
                            else if (GapY <= -30)
                                siteX = 2;

                            if (GapY >= -40)
                                siteY = 0;
                            else if (GapY < -40 && GapY > -60)
                                siteY = 1;
                            else if (GapY <= -60)
                                siteY = 2;

                            int site;
                            site = siteX + (siteY * 3);
                            if (site == 0)
                                text2.Text = "좌상";
                            else if (site == 1)
                                text2.Text = "상";
                            else if (site == 2)
                                text2.Text = "우상";
                            else if (site == 3)
                                text2.Text = "좌";
                            else if (site == 4)
                                text2.Text = "정";
                            else if (site == 5)
                                text2.Text = "우";
                            else if (site == 6)
                                text2.Text = "좌하";
                            else if (site == 7)
                                text2.Text = "하";
                            else if (site == 8)
                                text2.Text = "우하";

                            thisApp.nowsite = site;
                            /*
                             
                        rect4.X = facePoints[i].X - 2;
                        rect4.Y = facePoints[i].Y - 2;
                        rect4.Width = 4;
                        rect4.Height = 4;
                             */
                        }
                    }
                }
            }
        }
Exemplo n.º 6
0
        private void KinectSensorOnAllFramesReady(object sender, AllFramesReadyEventArgs e)
        {
            if (frameProccessed[1] == false)
            {
                frameProccessed[1] = true;
            }
            else
            {
                frameProccessed[1] = false;
                return;
            }
            ColorImageFrame colorImageFrame = null;
            DepthImageFrame depthImageFrame = null;
            SkeletonFrame   skeletonFrame   = null;

            try
            {
                colorImageFrame = e.OpenColorImageFrame();
                depthImageFrame = e.OpenDepthImageFrame();
                skeletonFrame   = e.OpenSkeletonFrame();

                if (colorImageFrame == null || depthImageFrame == null || skeletonFrame == null)
                {
                    return;
                }

                if (this.depthImageFormat != depthImageFrame.Format)
                {
                    this.depthImage       = null;
                    this.depthImageFormat = depthImageFrame.Format;
                }

                if (this.colorImageFormat != colorImageFrame.Format)
                {
                    this.colorImage       = null;
                    this.colorImageFormat = colorImageFrame.Format;
                }

                if (this.depthImage == null)
                {
                    this.depthImage = new short[depthImageFrame.PixelDataLength];
                }

                if (this.colorImage == null)
                {
                    this.colorImage = new byte[colorImageFrame.PixelDataLength];
                }

                if (this.skeletonData == null || this.skeletonData.Length != skeletonFrame.SkeletonArrayLength)
                {
                    this.skeletonData = new Skeleton[skeletonFrame.SkeletonArrayLength];
                }

                colorImageFrame.CopyPixelDataTo(this.colorImage);
                depthImageFrame.CopyPixelDataTo(this.depthImage);
                skeletonFrame.CopySkeletonDataTo(this.skeletonData);
            }
            finally
            {
                if (colorImageFrame != null)
                {
                    colorImageFrame.Dispose();
                }

                if (depthImageFrame != null)
                {
                    depthImageFrame.Dispose();
                }

                if (skeletonFrame != null)
                {
                    skeletonFrame.Dispose();
                }

                using (depthImageFrame)
                {
                    if (depthImageFrame != null && skeletonData != null)
                    {
                        foreach (Skeleton sd in skeletonData)
                        {
                            if (sd.TrackingState == SkeletonTrackingState.Tracked || sd.TrackingState == SkeletonTrackingState.PositionOnly)
                            {
                                Joint joint = sd.Joints[JointType.Head];

                                DepthImagePoint  depthPoint;
                                CoordinateMapper coordinateMapper = new CoordinateMapper(frontSensor);
                                depthPoint = coordinateMapper.MapSkeletonPointToDepthPoint(joint.Position, DepthImageFormat.Resolution320x240Fps30);

                                point = new System.Windows.Point((int)(frontSensor.ColorStream.FrameWidth * depthPoint.X
                                                                       / depthImageFrame.Width),
                                                                 (int)(frontSensor.ColorStream.FrameHeight * depthPoint.Y
                                                                       / depthImageFrame.Height));

                                /* textBlock1.Text = string.Format("X:{0:0.00} Y:{1:0.00} Z:{2:0.00}",
                                 *                              point.X,
                                 *                              point.Y,
                                 *                              joint.Position.Z); */

                                Canvas.SetLeft(headEllipse, point.X - headEllipse.Width / 2);
                                Canvas.SetTop(headEllipse, point.Y - headEllipse.Height / 2);

                                if (this.faceTracker == null)
                                {
                                    try
                                    {
                                        this.faceTracker = new FaceTracker(frontSensor);
                                    }
                                    catch (InvalidOperationException)
                                    {
                                        // During some shutdown scenarios the FaceTrack
                                        // is unable to be instantiated.  Catch that exception
                                        // and don't track a face.
                                        this.faceTracker = null;
                                    }
                                }
                                if (this.faceTracker != null)
                                {
                                    FaceTrackFrame frame = this.faceTracker.Track(
                                        colorImageFormat, colorImage, depthImageFormat, depthImage, sd);

                                    if (frame.TrackSuccessful)
                                    {
                                        faceTriangles   = frame.GetTriangles();
                                        this.facePoints = frame.GetProjected3DShape();

                                        var faceModelPts = new List <Point>();
                                        var faceModel    = new List <FaceModelTriangle>();


                                        for (int i = 0; i < this.facePoints.Count; i++)
                                        {
                                            faceModelPts.Add(new Point(this.facePoints[i].X + 0.5f, this.facePoints[i].Y + 0.5f));
                                        }

                                        foreach (var t in faceTriangles)
                                        {
                                            var triangle = new FaceModelTriangle();
                                            triangle.P1 = faceModelPts[t.First];
                                            //triangle.P2 = faceModelPts[t.Second];
                                            //triangle.P3 = faceModelPts[t.Third];
                                            faceModel.Add(triangle);
                                        }

                                        Canvas.SetLeft(noseEllipse, faceModel[108].P1.X - noseEllipse.Width / 2);
                                        Canvas.SetTop(noseEllipse, faceModel[108].P1.Y - noseEllipse.Height / 2);
                                        nosePoint = new Point(faceModel[108].P1.X, faceModel[108].P1.Y);
                                    }
                                }
                            }
                        }
                    }
                }

                getAttentionAngle(nosePoint);
            }
        }
Exemplo n.º 7
0
        public override void PostprocessMouseRightButtonDown(MouseButtonEventArgs e)
        {
            if (_view == null)
            {
                return;
            }

            if (GoToDefinitionCommand.Instance == null ||
                FindAllReferencesCommand.Instance == null ||
                RenameCommand.Instance == null ||
                Reformat.ReformatCommand.Instance == null)
            {
                return;
            }

            // Whack any old values that cursor points to.
            GoToDefinitionCommand.Instance.Enabled        = false;
            GoToDefinitionCommand.Instance.Visible        = false;
            GoToDefinitionCommand.Instance.Symbol         = default(SnapshotSpan);
            GoToDefinitionCommand.Instance.Classification = default(string);
            GoToDefinitionCommand.Instance.View           = default(ITextView);

            FindAllReferencesCommand.Instance.Enabled        = false;
            FindAllReferencesCommand.Instance.Visible        = false;
            FindAllReferencesCommand.Instance.Symbol         = default(SnapshotSpan);
            FindAllReferencesCommand.Instance.Classification = default(string);
            FindAllReferencesCommand.Instance.View           = default(ITextView);

            RenameCommand.Instance.Enabled        = false;
            RenameCommand.Instance.Visible        = false;
            RenameCommand.Instance.Symbol         = default(SnapshotSpan);
            RenameCommand.Instance.Classification = default(string);
            RenameCommand.Instance.View           = default(ITextView);

            Reformat.ReformatCommand.Instance.Enabled = false;
            Reformat.ReformatCommand.Instance.Visible = false;
            RenameCommand.Instance.View = default(ITextView);

            var fp = _view.GetFilePath();

            if (fp != null)
            {
                string suffix = System.IO.Path.GetExtension(fp);
                if (suffix.Equals(".g4") || suffix.Equals(".G4"))
                {
                    GoToDefinitionCommand.Instance.Visible    = true;
                    FindAllReferencesCommand.Instance.Visible = true;
                    RenameCommand.Instance.Visible            = true;
                    Reformat.ReformatCommand.Instance.Enabled = true;
                    Reformat.ReformatCommand.Instance.Visible = true;
                }
            }

            // No matter what, say we handled event, otherwise we get all sorts of pop-up errors.
            e.Handled = true;

            // Find details of the Antlr symbol pointed to.
            _mouseDownAnchorPoint = RelativeToView(e.GetPosition(_view.VisualElement));
            System.Windows.Point point = _mouseDownAnchorPoint ?? default(System.Windows.Point);
            if (point == default(System.Windows.Point))
            {
                return;
            }
            SnapshotPoint?nullable_where = ConvertPointToBufferIndex(point);

            SnapshotPoint where = nullable_where ?? default(SnapshotPoint);
            if (where == default(SnapshotPoint))
            {
                return;
            }
            TextExtent   extent = _navigator.GetExtentOfWord(where);
            SnapshotSpan span   = extent.Span;

            //  Now, check for valid classification type.
            ClassificationSpan[] c1 = _aggregator.GetClassificationSpans(span).ToArray();
            foreach (ClassificationSpan classification in c1)
            {
                var name = classification.ClassificationType.Classification.ToLower();
                if (name == AntlrVSIX.Constants.ClassificationNameTerminal)
                {
                    GoToDefinitionCommand.Instance.Enabled        = true;
                    GoToDefinitionCommand.Instance.Visible        = true;
                    GoToDefinitionCommand.Instance.Symbol         = span;
                    GoToDefinitionCommand.Instance.Classification = AntlrVSIX.Constants.ClassificationNameTerminal;
                    GoToDefinitionCommand.Instance.View           = _view;

                    FindAllReferencesCommand.Instance.Enabled        = true;
                    FindAllReferencesCommand.Instance.Visible        = true;
                    FindAllReferencesCommand.Instance.Symbol         = span;
                    FindAllReferencesCommand.Instance.Classification = AntlrVSIX.Constants.ClassificationNameTerminal;
                    FindAllReferencesCommand.Instance.View           = _view;

                    RenameCommand.Instance.Enabled        = true;
                    RenameCommand.Instance.Visible        = true;
                    RenameCommand.Instance.Symbol         = span;
                    RenameCommand.Instance.Classification = AntlrVSIX.Constants.ClassificationNameTerminal;
                    RenameCommand.Instance.View           = _view;

                    Reformat.ReformatCommand.Instance.Enabled        = true;
                    Reformat.ReformatCommand.Instance.Visible        = true;
                    Reformat.ReformatCommand.Instance.Symbol         = span;
                    Reformat.ReformatCommand.Instance.Classification = AntlrVSIX.Constants.ClassificationNameTerminal;
                    Reformat.ReformatCommand.Instance.View           = _view;
                }
                else if (name == AntlrVSIX.Constants.ClassificationNameNonterminal)
                {
                    GoToDefinitionCommand.Instance.Enabled        = true;
                    GoToDefinitionCommand.Instance.Visible        = true;
                    GoToDefinitionCommand.Instance.Symbol         = span;
                    GoToDefinitionCommand.Instance.Classification = AntlrVSIX.Constants.ClassificationNameNonterminal;
                    GoToDefinitionCommand.Instance.View           = _view;

                    FindAllReferencesCommand.Instance.Enabled        = true;
                    FindAllReferencesCommand.Instance.Visible        = true;
                    FindAllReferencesCommand.Instance.Symbol         = span;
                    FindAllReferencesCommand.Instance.Classification = AntlrVSIX.Constants.ClassificationNameNonterminal;
                    FindAllReferencesCommand.Instance.View           = _view;

                    RenameCommand.Instance.Enabled        = true;
                    RenameCommand.Instance.Visible        = true;
                    RenameCommand.Instance.Symbol         = span;
                    RenameCommand.Instance.Classification = AntlrVSIX.Constants.ClassificationNameNonterminal;
                    RenameCommand.Instance.View           = _view;

                    Reformat.ReformatCommand.Instance.Enabled        = true;
                    Reformat.ReformatCommand.Instance.Visible        = true;
                    Reformat.ReformatCommand.Instance.Symbol         = span;
                    Reformat.ReformatCommand.Instance.Classification = AntlrVSIX.Constants.ClassificationNameNonterminal;
                    Reformat.ReformatCommand.Instance.View           = _view;
                }
                else if (name == AntlrVSIX.Constants.ClassificationNameLiteral)
                {
                    GoToDefinitionCommand.Instance.Enabled        = true;
                    GoToDefinitionCommand.Instance.Visible        = true;
                    GoToDefinitionCommand.Instance.Symbol         = span;
                    GoToDefinitionCommand.Instance.Classification = AntlrVSIX.Constants.ClassificationNameLiteral;
                    GoToDefinitionCommand.Instance.View           = _view;

                    FindAllReferencesCommand.Instance.Enabled        = true;
                    FindAllReferencesCommand.Instance.Visible        = true;
                    FindAllReferencesCommand.Instance.Symbol         = span;
                    FindAllReferencesCommand.Instance.Classification = AntlrVSIX.Constants.ClassificationNameLiteral;
                    FindAllReferencesCommand.Instance.View           = _view;

                    RenameCommand.Instance.Enabled        = true;
                    RenameCommand.Instance.Visible        = true;
                    RenameCommand.Instance.Symbol         = span;
                    RenameCommand.Instance.Classification = AntlrVSIX.Constants.ClassificationNameLiteral;
                    RenameCommand.Instance.View           = _view;

                    Reformat.ReformatCommand.Instance.Enabled        = true;
                    Reformat.ReformatCommand.Instance.Visible        = true;
                    Reformat.ReformatCommand.Instance.Symbol         = span;
                    Reformat.ReformatCommand.Instance.Classification = AntlrVSIX.Constants.ClassificationNameLiteral;
                    Reformat.ReformatCommand.Instance.View           = _view;
                }
            }
        }
Exemplo n.º 8
0
        private void KinectSensorOnAllFramesReady(object sender, AllFramesReadyEventArgs e)
        {
            if (frameProccessed[1] == false)
            {
                frameProccessed[1] = true;
            }
            else
            {
                frameProccessed[1] = false;
                return;
            }
            ColorImageFrame colorImageFrame = null;
            DepthImageFrame depthImageFrame = null;
            SkeletonFrame skeletonFrame = null;

            try
            {

                colorImageFrame = e.OpenColorImageFrame();
                depthImageFrame = e.OpenDepthImageFrame();
                skeletonFrame = e.OpenSkeletonFrame();

                if (colorImageFrame == null || depthImageFrame == null || skeletonFrame == null)
                {
                    return;
                }

                if (this.depthImageFormat != depthImageFrame.Format)
                {
                    this.depthImage = null;
                    this.depthImageFormat = depthImageFrame.Format;
                }

                if (this.colorImageFormat != colorImageFrame.Format)
                {
                    this.colorImage = null;
                    this.colorImageFormat = colorImageFrame.Format;
                }

                if (this.depthImage == null)
                {
                    this.depthImage = new short[depthImageFrame.PixelDataLength];
                }

                if (this.colorImage == null)
                {
                    this.colorImage = new byte[colorImageFrame.PixelDataLength];
                }

                if (this.skeletonData == null || this.skeletonData.Length != skeletonFrame.SkeletonArrayLength)
                {
                    this.skeletonData = new Skeleton[skeletonFrame.SkeletonArrayLength];
                }

                colorImageFrame.CopyPixelDataTo(this.colorImage);
                depthImageFrame.CopyPixelDataTo(this.depthImage);
                skeletonFrame.CopySkeletonDataTo(this.skeletonData);
            }
            finally
            {
                if (colorImageFrame != null)
                {
                    colorImageFrame.Dispose();
                }

                if (depthImageFrame != null)
                {
                    depthImageFrame.Dispose();
                }

                if (skeletonFrame != null)
                {
                    skeletonFrame.Dispose();
                }

                using (depthImageFrame)
                {
                    if (depthImageFrame != null && skeletonData != null)
                    {
                        foreach (Skeleton sd in skeletonData)
                        {
                            if (sd.TrackingState == SkeletonTrackingState.Tracked || sd.TrackingState == SkeletonTrackingState.PositionOnly)
                            {
                                Joint joint = sd.Joints[JointType.Head];

                                DepthImagePoint depthPoint;
                                CoordinateMapper coordinateMapper = new CoordinateMapper(frontSensor);
                                depthPoint = coordinateMapper.MapSkeletonPointToDepthPoint(joint.Position, DepthImageFormat.Resolution320x240Fps30);

                                point = new System.Windows.Point((int)(frontSensor.ColorStream.FrameWidth * depthPoint.X
                                                                   / depthImageFrame.Width),
                                                        (int)(frontSensor.ColorStream.FrameHeight * depthPoint.Y
                                                                   / depthImageFrame.Height));

                                /* textBlock1.Text = string.Format("X:{0:0.00} Y:{1:0.00} Z:{2:0.00}",
                                                                point.X,
                                                                point.Y,
                                                                joint.Position.Z); */

                                Canvas.SetLeft(headEllipse, point.X - headEllipse.Width / 2);
                                Canvas.SetTop(headEllipse, point.Y - headEllipse.Height / 2);

                                if (this.faceTracker == null)
                                {
                                    try
                                    {
                                        this.faceTracker = new FaceTracker(frontSensor);
                                    }
                                    catch (InvalidOperationException)
                                    {
                                        // During some shutdown scenarios the FaceTrack
                                        // is unable to be instantiated.  Catch that exception
                                        // and don't track a face.
                                        this.faceTracker = null;
                                    }
                                }
                                if (this.faceTracker != null)
                                {
                                    FaceTrackFrame frame = this.faceTracker.Track(
                                        colorImageFormat, colorImage, depthImageFormat, depthImage, sd);

                                    if (frame.TrackSuccessful)
                                    {
                                        faceTriangles = frame.GetTriangles();
                                        this.facePoints = frame.GetProjected3DShape();

                                        var faceModelPts = new List<Point>();
                                        var faceModel = new List<FaceModelTriangle>();

                                        for (int i = 0; i < this.facePoints.Count; i++)
                                        {
                                            faceModelPts.Add(new Point(this.facePoints[i].X + 0.5f, this.facePoints[i].Y + 0.5f));
                                        }

                                        foreach (var t in faceTriangles)
                                        {
                                            var triangle = new FaceModelTriangle();
                                            triangle.P1 = faceModelPts[t.First];
                                            //triangle.P2 = faceModelPts[t.Second];
                                            //triangle.P3 = faceModelPts[t.Third];
                                            faceModel.Add(triangle);
                                        }

                                        Canvas.SetLeft(noseEllipse, faceModel[108].P1.X - noseEllipse.Width / 2);
                                        Canvas.SetTop(noseEllipse, faceModel[108].P1.Y - noseEllipse.Height / 2);
                                        nosePoint = new Point(faceModel[108].P1.X, faceModel[108].P1.Y);
                                    }
                                }
                            }
                        }
                    }
                }

                getAttentionAngle(nosePoint);
            }
        }
        private void ProcessMouseHit(System.Windows.Point mousePosition)
        {
            bool isVertexColorDataChanged;

            RayMeshGeometry3DHitTestResult hitTestResult;

            if (double.IsNaN(mousePosition.X)) // if mousePosition.X is NaN, then we consider this as mouse did not hit the model
            {
                hitTestResult = null;
            }
            else
            {
                hitTestResult = VisualTreeHelper.HitTest(MainViewport, mousePosition) as RayMeshGeometry3DHitTestResult;

                BeamLine1.X2         = mousePosition.X;
                BeamLine1.Y2         = mousePosition.Y;
                BeamLine1.Visibility = Visibility.Visible;

                BeamLine2.X2         = mousePosition.X;
                BeamLine2.Y2         = mousePosition.Y;
                BeamLine2.Visibility = Visibility.Visible;
            }

            if (hitTestResult != null)
            {
                var hitPoint3D = hitTestResult.PointHit;

                // Update the _positionColorsArray (array of colors for each vertex) so that each color is calculated as distance from the hitPoint3D.
                // Colors are set to the distances between 0 and 50; after 50 the lase color (light blue) is assigned.
                CalculatePositionColorsFromDistance(_objectGeometry3D.Positions, hitPoint3D, 50, _positionColorsArray);

                isVertexColorDataChanged = true;
                _isLastMousePositionHit  = true;

                BeamLine1.Stroke = Brushes.Red;
                BeamLine2.Stroke = Brushes.Red;
            }
            else
            {
                // Show Gray line for missed position

                BeamLine1.Stroke = Brushes.Gray;
                BeamLine2.Stroke = Brushes.Gray;

                if (_isLastMousePositionHit)
                {
                    // If before the mouse position hit the 3D mode, then the 3D model was colored
                    // But now the position do not hit the 3D mode any more - so we need to color the 3D mode with the last color - the one that is used for the biggest beam distance (light blue)
                    var lastColor = _gradientColor4Array[_gradientColor4Array.Length - 1];
                    FillPositionColorsArray(lastColor);

                    isVertexColorDataChanged = true;
                }
                else
                {
                    isVertexColorDataChanged = false;
                }

                _isLastMousePositionHit = false;
            }

            if (isVertexColorDataChanged)
            {
                //_vertexColorMaterial.PositionColors = _positionColorsArray; // PositionColors property was already set before

                // Update method on the VertexColorMaterial will update the underlying DirectX vertex buffer that
                // is created from PositionColors array and is sent to graphics card to render the 3D model.
                _vertexColorMaterial.Update();

                // Because we have manually updated the DXEngine material we need to notify the DXEngine's SceneNode that is using this material about the change.
                var sceneNode = MainDXViewportView.GetSceneNodeForWpfObject(_vertexColorGeometryModel3D);
                if (sceneNode != null)
                {
                    sceneNode.NotifySceneNodeChange(SceneNode.SceneNodeDirtyFlags.MaterialChanged);
                }
            }
        }
Exemplo n.º 10
0
        public GameWindow()
        {
            this.DoubleBuffered = true;

            // レイアウトロジックの停止
            this.SuspendLayout();
            //ピクチャーボックス配列を初期化
            this.StagePanel = new PictureBox();
            //全ステージパネル判定格納用配列
            HanteiPos  = new System.Windows.Point[(int)STAGE.StagePanel.Stage1panel][];
            HanteiNums = new int[(int)STAGE.StagePanel.Stage1panel][];


            // ピクチャーボックスを生成.
            this.StagePanel = new PictureBox();
            // ステージパネルのサイズを設定.
            StagePanel.Width  = STAGE.MapX * STAGE.MapChip * 6;
            StagePanel.Height = STAGE.MapY * STAGE.MapChip;
            // ステージパネルの座標を設定(左詰め).
            this.StagePanel.Left = 0; // i * STAGE.MapX * STAGE.MapChip;
            // スクロールポジション.
            StageScroll = 0;          //STAGE.MapX * 32 * i;
            // 画像のカプセル化用ビットマップとグラフィックを作成.
            Bitmap canvas  = new Bitmap(StagePanel.Width, StagePanel.Height);
            Bitmap canvass = new Bitmap(StagePanel.Width, StagePanel.Height);

            g = Graphics.FromImage(canvas);
            Graphics gg = Graphics.FromImage(canvass);

            for (int i = 0; i <= (int)STAGE.StagePanel.Stage1panel - 1; i++)
            {
                //ステージ番号を渡し、マップを生成
                STAGE.Stage1(i + 1);
                //mapはここだけSTAGE.GetMap(i)を参照.
                using (var map = STAGE.GetMap(i))
                {
                    // 原点に画像を設定.
                    g.DrawImage(map, i * 960, 0);
                    gg.DrawImage(map, i * 960, 0);
                }

                //判定マス整列用リスト
                List <System.Windows.Point> SetHanteiMass = new List <System.Windows.Point>();
                //スプライト番号整列用リスト
                List <int> SetHanteiNum = new List <int>();
                //判定マス整列用リスト判定変数
                //地形に判定をSTAGEから参照
                for (int Hanteii = 0; Hanteii < STAGE.HanteiMaps.Length; Hanteii++)
                {
                    if (STAGE.HanteiMaps[Hanteii] != new System.Windows.Point(0, 0))
                    {
                        //判定マスリストに判定座標を加算
                        SetHanteiMass.Add(STAGE.HanteiMaps[Hanteii]);
                        //判定マス番号リストに番号を加算
                        SetHanteiNum.Add(STAGE.HanteiNum[Hanteii]);
                    }
                }
                //判定マス配列の長さを整列用リストの数で初期化
                HanteiPos[i] = new System.Windows.Point[SetHanteiMass.Count];
                //同じように
                HanteiNums[i] = new int[SetHanteiNum.Count];
                //整列用リストの数だけ
                for (int HanteiMassnum = 0; HanteiMassnum < SetHanteiMass.Count; HanteiMassnum++)
                {
                    //判定マス配列に
                    HanteiPos[i][HanteiMassnum] = SetHanteiMass[HanteiMassnum];
                    //同じ用に
                    HanteiNums[i][HanteiMassnum] = SetHanteiNum[HanteiMassnum];
                }

                // GetMapのリソース開放.
                STAGE.GetMap(i).Dispose();
            }
            mapima = canvass;

            //背景を描写
            StagePanel.Image = canvas;
            // グラフィックのリソース開放.
            g.Dispose();
            gg.Dispose();

            this.StagePanel.Paint += new System.Windows.Forms.PaintEventHandler(this.Draw);
            // ユーザーフォームへ生成したコントロールを追加.
            this.Controls.Add(this.StagePanel);
            // デザイナーで作ったやつを描写.
            InitializeComponent();
            // レイアウトロジックの再開.
            this.ResumeLayout(false);

            //判定用ボタンを前面に
            button2.BringToFront();

            //プレイヤーの親設定と透過と描写
            //pictureBox1.BackColor = Color.Transparent;
            //pictureBox1.Parent = StagePanel;
            //Bitmap canvasmarion = new Bitmap(32, 32);
            //Graphics gi = Graphics.FromImage(canvasmarion);
            //gi.DrawImage(Marion.GetMarion(0), 0, 0, 32, 32);
            //pictureBox1.Image = canvasmarion;
            //ここまで

            /*
             * //ステータスバーの設定
             * status.Parent = StagePanel;
             * status.BackColor = Color.Transparent;
             * status.Location = new System.Drawing.Point(0, 0);
             * scoress= String.Format("{0:D8}", scores);
             * status.Text = scoress;
             * status.BringToFront();
             */
            _GameWindow = this;
        }
Exemplo n.º 11
0
        /// <summary>
        /// Draws a skeleton's bones and joints
        /// </summary>
        /// <param name="skeleton">skeleton to draw</param>
        /// <param name="drawingContext">drawing context to draw to</param>
        public void DrawBonesAndJoints(Skeleton skeleton, DrawingContext drawingContext)
        {
            // Render Torso
            //this.DrawBone(skeleton, drawingContext, JointType.Head, JointType.ShoulderCenter);
            DrawBone(skeleton, drawingContext, JointType.ShoulderCenter, JointType.ShoulderLeft);
            this.DrawBone(skeleton, drawingContext, JointType.ShoulderCenter, JointType.ShoulderRight);
            this.DrawBone(skeleton, drawingContext, JointType.ShoulderCenter, JointType.Spine);
            this.DrawBone(skeleton, drawingContext, JointType.Spine, JointType.HipCenter);
            this.DrawBone(skeleton, drawingContext, JointType.HipCenter, JointType.HipLeft);
            this.DrawBone(skeleton, drawingContext, JointType.HipCenter, JointType.HipRight);

            // Left Arm
            this.DrawBone(skeleton, drawingContext, JointType.ShoulderLeft, JointType.ElbowLeft);
            this.DrawBone(skeleton, drawingContext, JointType.ElbowLeft, JointType.WristLeft);
            this.DrawBone(skeleton, drawingContext, JointType.WristLeft, JointType.HandLeft);

            // Right Arm
            this.DrawBone(skeleton, drawingContext, JointType.ShoulderRight, JointType.ElbowRight);
            this.DrawBone(skeleton, drawingContext, JointType.ElbowRight, JointType.WristRight);
            this.DrawBone(skeleton, drawingContext, JointType.WristRight, JointType.HandRight);

            // Left Leg
            this.DrawBone(skeleton, drawingContext, JointType.HipLeft, JointType.KneeLeft);
            this.DrawBone(skeleton, drawingContext, JointType.KneeLeft, JointType.AnkleLeft);
            this.DrawBone(skeleton, drawingContext, JointType.AnkleLeft, JointType.FootLeft);

            // Right Leg
            this.DrawBone(skeleton, drawingContext, JointType.HipRight, JointType.KneeRight);
            this.DrawBone(skeleton, drawingContext, JointType.KneeRight, JointType.AnkleRight);
            this.DrawBone(skeleton, drawingContext, JointType.AnkleRight, JointType.FootRight);

            // Render Joints
            foreach (Joint joint in skeleton.Joints)
            {
                Brush drawBrush = null;

                if (joint.TrackingState == JointTrackingState.Tracked)
                {
                    drawBrush = this.trackedJointBrush;
                }
                else if (joint.TrackingState == JointTrackingState.Inferred)
                {
                    drawBrush = this.inferredJointBrush;
                }

                if (drawBrush != null)
                {
                    drawingContext.DrawEllipse(drawBrush, null, this.SkeletonPointToScreen(joint.Position), JointThickness, JointThickness);
                }
            }

            //render head
            Joint leftHand  = skeleton.Joints[JointType.HandLeft];
            Joint leftElbow = skeleton.Joints[JointType.ElbowLeft];

            Joint head           = skeleton.Joints[JointType.Head];
            Joint shoulderCenter = skeleton.Joints[JointType.ShoulderCenter];

            //assumes that head radius fits 4 times in the distance between hand and elbow

            /*float deltaX = leftHand.Position.X - leftElbow.Position.X;
             * float deltaY = leftHand.Position.Y - leftElbow.Position.Y;
             * float deltaZ = leftHand.Position.Z - leftElbow.Position.Z;
             * float distance = (float)Math.Sqrt(deltaX * deltaX + deltaY * deltaY + deltaZ * deltaZ);
             * float headRadius = (float)(distance * scale * 1.5);*/



            System.Windows.Media.Pen drawPen = this.inferredBonePen;
            if (head.TrackingState == JointTrackingState.Tracked && shoulderCenter.TrackingState == JointTrackingState.Tracked)
            {
                drawPen = this.trackedBonePen;
                Brush drawBrush = this.trackedJointBrush;

                if (drawBrush != null)
                {
                    System.Windows.Point headPointOnScreen     = SkeletonPointToScreen(head.Position);
                    System.Windows.Point shoulderPointOnScreen = SkeletonPointToScreen(shoulderCenter.Position);
                    double deltaX      = headPointOnScreen.X - shoulderPointOnScreen.X;
                    double deltaY      = headPointOnScreen.Y - shoulderPointOnScreen.Y;
                    float  distance    = (float)Math.Sqrt(deltaX * deltaX + deltaY * deltaY);
                    float  headRadius  = (float)(distance / 2);
                    Vector headVec     = new Vector(headPointOnScreen.X, headPointOnScreen.Y);
                    Vector shoulderVec = new Vector(shoulderPointOnScreen.X, shoulderPointOnScreen.Y);
                    Vector distVector  = shoulderVec - headVec;
                    distVector.Normalize();


                    Vector intersectingPoint = headVec + distVector * headRadius;

                    drawingContext.DrawEllipse(drawBrush, drawPen, this.SkeletonPointToScreen(head.Position), headRadius, headRadius);
                    drawingContext.DrawLine(drawPen, new Point(intersectingPoint.X, intersectingPoint.Y), shoulderPointOnScreen);
                }
            }
        }
Exemplo n.º 12
0
        void nui_AllFramesReady(object sender, AllFramesReadyEventArgs e)
        {
            ColorImageFrame cf = e.OpenColorImageFrame();
            DepthImageFrame df = e.OpenDepthImageFrame();
            SkeletonFrame   sf = e.OpenSkeletonFrame();

            //            Skeleton[] skeletonData = new Skeleton[sf.SkeletonArrayLength];

            if (cf == null || df == null || sf == null)
            {
                return;
            }


            byte[] ImageBits = new byte[cf.PixelDataLength];
            cf.CopyPixelDataTo(ImageBits);

            BitmapSource src = null;

            src = BitmapSource.Create(cf.Width, cf.Height,
                                      96, 96, PixelFormats.Bgr32, null,
                                      ImageBits,
                                      cf.Width * cf.BytesPerPixel);
            image2.Source = src;



            // Check for image format changes.  The FaceTracker doesn't
            // deal with that so we need to reset.
            if (this.depthImageFormat != df.Format)
            {
                this.ResetFaceTracking();
                this.depthImage       = null;
                this.depthImageFormat = df.Format;
            }

            if (this.colorImageFormat != cf.Format)
            {
                this.ResetFaceTracking();
                this.colorImage       = null;
                this.colorImageFormat = cf.Format;
            }

            // Create any buffers to store copies of the data we work with
            if (this.depthImage == null)
            {
                this.depthImage = new short[df.PixelDataLength];
            }

            if (this.colorImage == null)
            {
                this.colorImage = new byte[cf.PixelDataLength];
            }

            // Get the skeleton information
            if (this.skeletonData == null || this.skeletonData.Length != sf.SkeletonArrayLength)
            {
                this.skeletonData = new Skeleton[sf.SkeletonArrayLength];
            }

            cf.CopyPixelDataTo(this.colorImage);
            df.CopyPixelDataTo(this.depthImage);
            sf.CopySkeletonDataTo(this.skeletonData);

            foreach (Skeleton skeleton in this.skeletonData)
            {
                if (skeleton.TrackingState == SkeletonTrackingState.Tracked ||
                    skeleton.TrackingState == SkeletonTrackingState.PositionOnly)
                {
                    // We want keep a record of any skeleton, tracked or untracked.
                    if (!this.trackedSkeletons.ContainsKey(skeleton.TrackingId))
                    {
                        this.trackedSkeletons.Add(skeleton.TrackingId, new SkeletonFaceTracker());
                    }

                    // Give each tracker the upated frame.
                    SkeletonFaceTracker skeletonFaceTracker;
                    if (this.trackedSkeletons.TryGetValue(skeleton.TrackingId, out skeletonFaceTracker))
                    {
                        skeletonFaceTracker.OnFrameReady(nui2, colorImageFormat, colorImage, depthImageFormat, depthImage, skeleton);
                        skeletonFaceTracker.LastTrackedFrame = sf.FrameNumber;
                    }
                }
            }



            using (DepthImageFrame depthImageFrame = e.OpenDepthImageFrame())
            {
                if (depthImageFrame != null)
                {
                    foreach (Skeleton sd in skeletonData)
                    {
                        if (sd.TrackingState == SkeletonTrackingState.Tracked)
                        {
                            Joint joint = sd.Joints[JointType.Head];

                            DepthImagePoint depthPoint;

                            //                            CoordinateMapper coordinateMapper = new CoordinateMapper(nui);
                            //                            depthPoint = coordinateMapper.MapSkeletonPointToDepthPoint(joint.Position, DepthImageFormat.Resolution320x240Fps30);

                            depthPoint = depthImageFrame.MapFromSkeletonPoint(joint.Position);

                            System.Windows.Point point = new System.Windows.Point((int)(image2.ActualWidth * depthPoint.X
                                                                                        / depthImageFrame.Width),
                                                                                  (int)(image2.ActualHeight * depthPoint.Y
                                                                                        / depthImageFrame.Height));


                            Canvas.SetLeft(ellipse1, (point.X) - ellipse1.Width);
                            Canvas.SetTop(ellipse1, (point.Y) - ellipse1.Height);

                            App thisApp = App.Current as App;

                            Canvas.SetLeft(rect2, thisApp.m_dbX - rect2.Width);
                            Canvas.SetTop(rect2, thisApp.m_dbY - rect2.Height);

                            double GapX, GapY;
                            GapX = point.X - (thisApp.m_dbX - 2);
                            GapY = point.Y - (thisApp.m_dbY - 2);

                            int siteX = 999, siteY = 999;

                            if (GapX < 30 && GapX > -30)
                            {
                                siteX = 1;
                            }
                            else if (GapX >= 30)
                            {
                                siteX = 0;
                            }
                            else if (GapY <= -30)
                            {
                                siteX = 2;
                            }

                            if (GapY >= -40)
                            {
                                siteY = 0;
                            }
                            else if (GapY < -40 && GapY > -60)
                            {
                                siteY = 1;
                            }
                            else if (GapY <= -60)
                            {
                                siteY = 2;
                            }

                            int site;
                            site = siteX + (siteY * 3);
                            if (site == 0)
                            {
                                text2.Text = "좌상";
                            }
                            else if (site == 1)
                            {
                                text2.Text = "상";
                            }
                            else if (site == 2)
                            {
                                text2.Text = "우상";
                            }
                            else if (site == 3)
                            {
                                text2.Text = "좌";
                            }
                            else if (site == 4)
                            {
                                text2.Text = "정";
                            }
                            else if (site == 5)
                            {
                                text2.Text = "우";
                            }
                            else if (site == 6)
                            {
                                text2.Text = "좌하";
                            }
                            else if (site == 7)
                            {
                                text2.Text = "하";
                            }
                            else if (site == 8)
                            {
                                text2.Text = "우하";
                            }

                            thisApp.nowsite = site;

                            /*
                             *
                             * rect4.X = facePoints[i].X - 2;
                             * rect4.Y = facePoints[i].Y - 2;
                             * rect4.Width = 4;
                             * rect4.Height = 4;
                             */
                        }
                    }
                }
            }
        }
Exemplo n.º 13
0
        private void MoveWindow_MouseDown(object sender, MouseButtonEventArgs e)
        {
            if (e.LeftButton == MouseButtonState.Pressed)
            {
                _MoveWindowStartPos = e.GetPosition(this);
                Mouse.Capture(this);
                Mouse.OverrideCursor = Cursors.None;

                _IsMovingWindow = true;
            }
        }
Exemplo n.º 14
0
        public static BitmapSource DrawFaces(BitmapSource baseImage, IRound round, Dictionary <Guid, Microsoft.ProjectOxford.Face.Contract.Face> identities, ScoringSystem scoring, MainWindow.AppMode mode)
        {
            if (identities == null)
            {
                return(baseImage);
            }

            Action <DrawingContext, double> drawAction = (drawingContext, annotationScale) =>
            {
                foreach (var personId in identities.Keys)
                {
                    var face = identities[personId];

                    if (face.FaceRectangle == null)
                    {
                        continue;
                    }

                    Rect faceRect = new Rect(
                        face.FaceRectangle.Left, face.FaceRectangle.Top,
                        face.FaceRectangle.Width, face.FaceRectangle.Height);
                    string text = "";

                    SolidColorBrush brush;
                    if (!colorsForPlayers.TryGetValue(personId, out brush))
                    {
                        colorsForPlayers[personId] = GetLatestBrush();
                    }
                    brush = colorsForPlayers[personId];

                    if (face.FaceAttributes != null && mode == MainWindow.AppMode.Faces)
                    {
                        text += Aggregation.SummarizeFaceAttributes(face.FaceAttributes);
                    }

                    if (face.FaceAttributes.Emotion != null && mode == MainWindow.AppMode.Emotions)
                    {
                        text += Aggregation.SummarizeEmotion(face.FaceAttributes.Emotion);
                    }

                    if (scoring.CurrentRoundScore.ContainsKey(personId))
                    {
                        text += string.Format("  +{0}pts", scoring.CurrentRoundScore[personId]);
                    }

                    faceRect.Inflate(6 * annotationScale, 6 * annotationScale);

                    double lineThickness = 4 * annotationScale;

                    drawingContext.DrawRectangle(
                        Brushes.Transparent,
                        new Pen(brush, lineThickness),
                        faceRect);


                    //drawingContext.DrawImage(ImageProvider.Frame, faceRect);

                    if (text != "")
                    {
                        FormattedText ft = new FormattedText(text,
                                                             CultureInfo.CurrentCulture, FlowDirection.LeftToRight, s_typeface,
                                                             16 * annotationScale, Brushes.Black);

                        var pad = 3 * annotationScale;

                        var ypad   = pad;
                        var xpad   = pad + 4 * annotationScale;
                        var origin = new System.Windows.Point(
                            faceRect.Left + xpad - lineThickness / 2,
                            faceRect.Top - ft.Height - ypad + lineThickness / 2);
                        var rect = ft.BuildHighlightGeometry(origin).GetRenderBounds(null);
                        rect.Inflate(xpad, ypad);

                        drawingContext.DrawRectangle(brush, null, rect);
                        drawingContext.DrawText(ft, origin);
                    }
                }
            };

            return(DrawOverlay(baseImage, drawAction, true));
        }