Ejemplo n.º 1
0
        /// <summary>
        /// This is called when the game should draw itself.
        /// </summary>
        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.CornflowerBlue);

            if (isWireframe)
            {
                GraphicsDevice.RasterizerState = wireFrameState;
            }
            else
            {
                GraphicsDevice.RasterizerState = RasterizerState.CullClockwise;
            }

            // Create camera matrices, making the object spin.
            float time = (float)gameTime.TotalGameTime.TotalSeconds;

            float yaw   = time * 0.4f;
            float pitch = time * 0.7f;
            float roll  = time * 1.1f;

            Vector3 cameraPosition = new Vector3(0, 0, 2.5f);

            float aspect = GraphicsDevice.Viewport.AspectRatio;

            Matrix world      = Matrix.CreateFromYawPitchRoll(yaw, pitch, roll);
            Matrix view       = Matrix.CreateLookAt(cameraPosition, Vector3.Zero, Vector3.Up);
            Matrix projection = Matrix.CreatePerspectiveFieldOfView(1, aspect, 1, 50);

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

            currentPrimitive.Draw(world, view, projection, color);

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

            // Draw overlay text.
            string text = "A or tap top of screen = Change primitive\n" +
                          "B or tap bottom left of screen = Change color\n" +
                          "Y or tap bottom right of screen = Toggle wireframe";

            //spriteBatch.Begin();
            //spriteBatch.DrawString(spriteFont, text, new Vector2(30, 30), Color.White);
            //spriteBatch.DrawString(null, text, new Vector2(30, 30), Color.White);
            //spriteBatch.End();

            base.Draw(gameTime);
        }
Ejemplo n.º 2
0
        private void OnDraw(object sender, DrawEventArgs e)
        {
            GraphicsDevice graphicsDevice = GraphicsDeviceManager.Current.GraphicsDevice;

            Color cornflowerBlue = new Color(0x64, 0x95, 0xED, 0xFF);

            graphicsDevice.Clear(cornflowerBlue);

            if (isWireframe)
            {
                graphicsDevice.RasterizerState = wireFrameState;
            }
            else
            {
                graphicsDevice.RasterizerState = RasterizerState.CullCounterClockwise;
            }

            // Create camera matrices, making the object spin.
            float time = (float)e.TotalTime.TotalSeconds;

            float yaw   = time * 0.4f;
            float pitch = time * 0.7f;
            float roll  = time * 1.1f;

            Vector3 cameraPosition = new Vector3(0, 0, 2.5f);

            float aspect = graphicsDevice.Viewport.AspectRatio;

            Matrix world      = Matrix.CreateFromYawPitchRoll(yaw, pitch, roll);
            Matrix view       = Matrix.CreateLookAt(cameraPosition, Vector3.Zero, Vector3.Up);
            Matrix projection = Matrix.CreatePerspectiveFieldOfView(1, aspect, 1, 10);

            // Draw the current primitive.
            GeometricPrimitive currentPrimitive = primitives[currentPrimitiveIndex];
            Color currentColor = colors[currentColorIndex];

            currentPrimitive.Draw(world, view, projection, currentColor);

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

            // Force a redraw so this control will continuously animate.
            e.InvalidateSurface();
        }
        private void DrawPrimitveSkeleton(GeometricPrimitive primitive, Matrix view, Matrix projection, Color color)
        {
            try
            {
                if (skeleton != null)
                {
                    if (skeleton.TrackingState == SkeletonTrackingState.Tracked)
                    {
                        foreach (Joint joint in skeleton.Joints)
                        {
                            var position = ConvertRealWorldPoint(joint.Position);
                            //position.X = -position.X;
                            Matrix world = new Matrix();
                            world = Matrix.CreateTranslation(position);
                            primitive.Draw(world, view, projection, color);
                        }
                        var leftHand = skeleton.Joints[JointID.HandLeft];
                        leftHandPosition = ConvertRealWorldPoint(leftHand.Position);
                    }
                }
            }
            catch
            {

            }
        }