Пример #1
0
 private void DrawPrimitveStartSword(GeometricPrimitive primitive, Matrix view, Matrix projection, BTCHelper.Hand hand, Color color)
 {
     try
     {
         if (activeSkeleton != null)
         {
             if (activeSkeleton.TrackingState == SkeletonTrackingState.Tracked)
             {
                 Joint joint;
                 if (hand == BTCHelper.Hand.Right)
                 {
                     joint = activeSkeleton.Joints[JointType.HandRight];
                 }
                 else
                 {
                     joint = activeSkeleton.Joints[JointType.HandLeft];
                 }
                 var    position = GameWorldTransformation(joint.Position);
                 Matrix world    = new Matrix();
                 world = Matrix.CreateTranslation((float)position.X, (float)position.Y, (float)position.Z) * Matrix.CreateTranslation(0.0f, -1.0f, 0.0f);
                 primitive.Draw(world, view, projection * Matrix.CreateScale(1.0f), color);
             }
         }
     }
     catch
     {
     }
 }
Пример #2
0
        private void DrawPrimitveSword(GeometricPrimitive primitive, Matrix view, Matrix projection, BTCHelper.Hand hand)
        {
            try
            {
                if (activeSkeleton != null)
                {
                    if (activeSkeleton.TrackingState == SkeletonTrackingState.Tracked)
                    {
                        Joint joint;
                        Color color = Color.Red;;
                        if (hand == BTCHelper.Hand.Right)
                        {
                            joint = activeSkeleton.Joints[JointType.HandRight];
                        }
                        else
                        {
                            joint = activeSkeleton.Joints[JointType.HandLeft];
                        }
                        var       position    = GameWorldTransformation(joint.Position);
                        BTCVector mydirection = BTCHelper.GetHandDirection(hand, activeSkeleton, new BTCVector(-1.0f, 1.0f, 1.0f));
                        Vector3   direction   = new Vector3(mydirection.X, mydirection.Y, mydirection.Z);
                        Matrix    world       = new Matrix();
                        for (int i = 1; i < 10; i++)
                        {
                            if (ii % 10 == 0)
                            {
                                Color temp = start;
                                start = nect;
                                nect  = temp;
                                ii++;
                            }


                            if (i % 2 != 0)
                            {
                                color = start;
                            }
                            else
                            {
                                color = nect;
                            }
                            position = position + direction * float.Parse(i.ToString()) * 0.5f / 3.0f;
                            world    = Matrix.CreateTranslation((float)position.X, (float)position.Y, (float)position.Z);
                            primitive.Draw(world, view, projection * Matrix.CreateScale(1f, 1f, 1f), color);
                        }
                        ii++;
                    }
                }
            }
            catch
            {
            }
        }
Пример #3
0
        private void DrawPrimitveSkeleton(GeometricPrimitive primitive, Matrix view, Matrix projection, Color color)
        {
            try
            {
                if (activeSkeleton != null)
                {
                    if (activeSkeleton.TrackingState == SkeletonTrackingState.Tracked)
                    {
                        float maxDepth  = -1;
                        float maxHeight = 1;
                        float maxWidth  = 1;

                        foreach (Joint joint in activeSkeleton.Joints)
                        {
                            Vector3 position = GameWorldTransformation(joint.Position);
                            if (maxDepth < position.Z)
                            {
                                maxDepth = position.Z;
                            }
                            if (maxHeight < position.Y)
                            {
                                maxHeight = position.Y;
                            }
                            if (maxWidth < position.X)
                            {
                                maxWidth = position.X;
                            }

                            Matrix world = new Matrix();
                            world = Matrix.CreateTranslation((float)position.X, (float)position.Y, (float)position.Z);
                            primitive.Draw(world, view, projection * Matrix.CreateScale(1.0f), color);
                        }
                        animationDepth  = (int)maxDepth;
                        animationHeight = (int)maxHeight;
                        animationWidth  = (int)maxWidth;
                    }
                }
            }
            catch
            {
            }
        }
Пример #4
0
        /// <summary>
        /// This is called when the game should draw itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.CornflowerBlue);

            projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.PiOver4,
                                                             GraphicsDevice.Viewport.AspectRatio,
                                                             1.0f,
                                                             100);

            spriteBatch.Begin();

            if (kinectVideoTexture != null)
            {
                spriteBatch.Draw(kinectVideoTexture, fullScreenRectangle, Color.White);
            }

            //if (gameMaskTexture != null)
            //    spriteBatch.Draw(gameMaskTexture, fullScreenRectangle, Color.White);

            //if (activeSkeleton != null)
            //{
            //    drawSkeleton(activeSkeleton, Color.White);
            //}

            //spriteBatch.Draw(pinTexture, pinRectangle, pinColor);

            if (errorMessage.Length > 0)
            {
                spriteBatch.DrawString(messageFont, errorMessage, Vector2.Zero, Color.White);
            }

            spriteBatch.End();

            foreach (ISprite sprite in gameSprites)
            {
                sprite.Draw(this);
            }

            //Matrix world = Matrix.CreateTranslation(PinVector) * Matrix.CreateTranslation(0.0f, -1.0f, 0.0f);
            //DrawModel(pinModel, world , view, projection);

            // Draw the current primitive.
            GeometricPrimitive currentPrimitive = primitives[currentPrimitiveIndex];
            Color color = Color.SpringGreen;

            DrawPrimitveSkeleton(currentPrimitive, view, projection, color);
            if (startcastingRight)
            {
                DrawPrimitveStartSword(primitives[1], view, projection, BTCHelper.Hand.Right, Color.WhiteSmoke);
            }
            if (startcastingLeft)
            {
                DrawPrimitveStartSword(primitives[1], view, projection, BTCHelper.Hand.Left, Color.WhiteSmoke);
            }
            if (swortLeft)
            {
                DrawPrimitveSword(primitives[0], view, projection, BTCHelper.Hand.Left);
            }
            if (swortRight)
            {
                DrawPinSword(pinModel, view, projection, BTCHelper.Hand.Right);
            }

            // Reset the fill mode renderstate.
            GraphicsDevice.RasterizerState = RasterizerState.CullCounterClockwise;

            base.Draw(gameTime);
        }
Пример #5
0
        private void DrawPrimitveStartSword(GeometricPrimitive primitive, Matrix view, Matrix projection, BTCHelper.Hand hand, Color color)
        {
            try
            {
                if (activeSkeleton != null)
                {
                    if (activeSkeleton.TrackingState == SkeletonTrackingState.Tracked)
                    {
                        Joint joint;
                        if (hand == BTCHelper.Hand.Right)
                            joint = activeSkeleton.Joints[JointType.HandRight];
                        else joint = activeSkeleton.Joints[JointType.HandLeft];
                        var position = GameWorldTransformation(joint.Position);
                        Matrix world = new Matrix();
                        world = Matrix.CreateTranslation((float)position.X, (float)position.Y, (float)position.Z) * Matrix.CreateTranslation(0.0f, -1.0f, 0.0f);
                        primitive.Draw(world, view, projection * Matrix.CreateScale(1.0f), color);

                    }
                }
            }
            catch
            {

            }
        }
Пример #6
0
        private void DrawPrimitveSword(GeometricPrimitive primitive, Matrix view, Matrix projection, BTCHelper.Hand hand)
        {
            try
            {
                if (activeSkeleton != null)
                {
                    if (activeSkeleton.TrackingState == SkeletonTrackingState.Tracked)
                    {
                        Joint joint;
                        Color color = Color.Red; ;
                        if (hand == BTCHelper.Hand.Right) joint = activeSkeleton.Joints[JointType.HandRight];
                        else joint = activeSkeleton.Joints[JointType.HandLeft];
                        var position = GameWorldTransformation(joint.Position);
                        BTCVector mydirection = BTCHelper.GetHandDirection(hand, activeSkeleton, new BTCVector(-1.0f, 1.0f, 1.0f));
                        Vector3 direction = new Vector3(mydirection.X, mydirection.Y, mydirection.Z);
                        Matrix world = new Matrix();
                        for (int i = 1; i < 10; i++)
                        {

                            if (ii % 10 == 0)
                            {
                                Color temp = start;
                                start = nect;
                                nect = temp;
                                ii++;
                            }


                            if (i % 2 != 0) color = start;
                            else color = nect;
                            position = position + direction * float.Parse(i.ToString()) * 0.5f / 3.0f;
                            world = Matrix.CreateTranslation((float)position.X, (float)position.Y, (float)position.Z);
                            primitive.Draw(world, view, projection * Matrix.CreateScale(1f, 1f, 1f), color);
                            

                        }
                        ii++;

                    }
                }
            }
            catch
            {

            }
        }
Пример #7
0
        private void DrawPrimitveSkeleton(GeometricPrimitive primitive, Matrix view, Matrix projection, Color color)
        {
            try
            {
                if (activeSkeleton != null)
                {
                    
                    if (activeSkeleton.TrackingState == SkeletonTrackingState.Tracked)
                    {
                        float maxDepth = -1;
                        float maxHeight = 1;
                        float maxWidth = 1;

                        foreach (Joint joint in activeSkeleton.Joints)
                        {
                            Vector3 position = GameWorldTransformation(joint.Position);
                            if (maxDepth < position.Z)
                                maxDepth = position.Z;
                            if (maxHeight < position.Y)
                                maxHeight = position.Y;
                            if (maxWidth < position.X)
                                maxWidth = position.X;

                            Matrix world = new Matrix();
                            world = Matrix.CreateTranslation((float)position.X, (float)position.Y, (float)position.Z);
                            primitive.Draw(world, view, projection * Matrix.CreateScale(1.0f), color);
                        }
                        animationDepth = (int)maxDepth;
                        animationHeight = (int)maxHeight;
                        animationWidth = (int)maxWidth;
                    }
                }
            }
            catch
            {

            }
        }