Beispiel #1
0
        public override void LoadContent()
        {
            base.LoadContent();

            // Setup vertex declaration
            _vDeclaration = new VertexDeclaration(VertexPositionColor.VertexDeclaration.GetVertexElements());
            _simpleEffect = new BasicEffect(GraphicsDevice);
            _simpleEffect.VertexColorEnabled = true;

            // Setup our Cone Pointer
            TranslationPointer = Game.Content.Load <Model>("Cone");

            _coneBoneTransforms         = new Matrix[TranslationPointer.Bones.Count];
            _coneOriginalBoneTransforms = new Matrix[TranslationPointer.Bones.Count];

            TranslationPointer.CopyAbsoluteBoneTransformsTo(_coneBoneTransforms);
            TranslationPointer.CopyBoneTransformsTo(_coneOriginalBoneTransforms);

            // Setup our Cube Pointer
            ScalePointer                = Game.Content.Load <Model>("Cube");
            _cubeBoneTransforms         = new Matrix[ScalePointer.Bones.Count];
            _cubeOriginalBoneTransforms = new Matrix[ScalePointer.Bones.Count];
            ScalePointer.CopyAbsoluteBoneTransformsTo(_cubeBoneTransforms);
            ScalePointer.CopyBoneTransformsTo(_cubeOriginalBoneTransforms);
        }
Beispiel #2
0
        public override void Draw(GameTime gameTime)
        {
            // Setup our vertices incase line length has changed
            SetupVertices();

            if (Camera != null)
            {
                _simpleEffect.World      = Matrix.CreateTranslation(Position.X, Position.Y, Position.Z);
                _simpleEffect.View       = Camera.View;
                _simpleEffect.Projection = Camera.Projection;
            }

            #region X Axis Drawing

            if (SelectedAxis == SelectedAxis.X)
            {
                // Draw our X Axis Line
                _simpleEffect.AmbientLightColor = Color.Yellow.ToVector3();
                _simpleEffect.DiffuseColor      = Color.Yellow.ToVector3();
            }
            else
            {
                // Draw our X Axis Line
                _simpleEffect.AmbientLightColor = _xColor.ToVector3();
                _simpleEffect.DiffuseColor      = _xColor.ToVector3();
            }

            // Begin this effect pass
            _simpleEffect.CurrentTechnique.Passes[0].Apply();

            GraphicsDevice.DrawUserPrimitives(PrimitiveType.LineList, _vertX, 0, 1);

            #endregion

            #region Y Axis Drawing


            if (SelectedAxis == SelectedAxis.Y)
            {
                // Draw our X Axis Line
                _simpleEffect.AmbientLightColor = Color.Yellow.ToVector3();
                _simpleEffect.DiffuseColor      = Color.Yellow.ToVector3();
            }
            else
            {
                _simpleEffect.AmbientLightColor = _yColor.ToVector3();
                _simpleEffect.DiffuseColor      = _yColor.ToVector3();
            }

            // Begin this effect pass
            _simpleEffect.CurrentTechnique.Passes[0].Apply();

            GraphicsDevice.DrawUserPrimitives(PrimitiveType.LineList, _vertY, 0, 1);

            #endregion

            #region Z Axis Drawing

            if (SelectedAxis == SelectedAxis.Z)
            {
                // Draw our X Axis Line
                _simpleEffect.AmbientLightColor = Color.Yellow.ToVector3();
                _simpleEffect.DiffuseColor      = Color.Yellow.ToVector3();
            }
            else
            {
                _simpleEffect.AmbientLightColor = _zColor.ToVector3();
                _simpleEffect.DiffuseColor      = _zColor.ToVector3();
            }

            // Begin this effect pass
            _simpleEffect.CurrentTechnique.Passes[0].Apply();

            GraphicsDevice.DrawUserPrimitives(PrimitiveType.LineList, _vertZ, 0, 1);

            #endregion

            #region Translation Pointer

            if (SelectMode == SelectedDisplayMode.Translation)
            {
                #region Draw Cone Pointer for X Axis

                foreach (ModelMesh mesh in TranslationPointer.Meshes)
                {
                    foreach (BasicEffect effect in mesh.Effects)
                    {
                        _coneXWorld = _cubeBoneTransforms[mesh.ParentBone.Index] *
                                      Matrix.CreateScale(Scale) *
                                      Matrix.CreateRotationZ(MathHelper.ToRadians(-90)) *
                                      Matrix.CreateTranslation(new Vector3(Position.X + LineLength, Position.Y, Position.Z));

                        if (Camera != null)
                        {
                            effect.World      = _coneXWorld;
                            effect.View       = Camera.View;
                            effect.Projection = Camera.Projection;
                        }

                        effect.EnableDefaultLighting();
                        effect.PreferPerPixelLighting = true;

                        if (SelectedAxis == SelectedAxis.X)
                        {
                            effect.DiffuseColor      = Color.Yellow.ToVector3();
                            effect.AmbientLightColor = Color.Yellow.ToVector3();
                        }
                        else
                        {
                            effect.DiffuseColor      = _xColor.ToVector3();
                            effect.AmbientLightColor = _xColor.ToVector3();
                        }
                    }
                    mesh.Draw();
                }

                TranslationPointer.CopyBoneTransformsFrom(_coneOriginalBoneTransforms);

                #endregion

                #region Draw Cone Pointer for Y Axis

                foreach (ModelMesh mesh in TranslationPointer.Meshes)
                {
                    foreach (BasicEffect effect in mesh.Effects)
                    {
                        _coneYWorld = _cubeBoneTransforms[mesh.ParentBone.Index] *
                                      Matrix.CreateScale(Scale) *
                                      Matrix.CreateTranslation(new Vector3(Position.X, Position.Y + LineLength, Position.Z));

                        if (Camera != null)
                        {
                            effect.World      = _coneYWorld;
                            effect.View       = Camera.View;
                            effect.Projection = Camera.Projection;
                        }

                        effect.EnableDefaultLighting();
                        effect.PreferPerPixelLighting = true;

                        if (SelectedAxis == SelectedAxis.Y)
                        {
                            effect.DiffuseColor      = Color.Yellow.ToVector3();
                            effect.AmbientLightColor = Color.Yellow.ToVector3();
                        }
                        else
                        {
                            effect.DiffuseColor      = _yColor.ToVector3();
                            effect.AmbientLightColor = _yColor.ToVector3();
                        }
                    }
                    mesh.Draw();
                }

                TranslationPointer.CopyBoneTransformsFrom(_coneOriginalBoneTransforms);

                #endregion

                #region Draw Cone Pointer for Z Axis

                foreach (ModelMesh mesh in TranslationPointer.Meshes)
                {
                    foreach (BasicEffect effect in mesh.Effects)
                    {
                        _coneZWorld = _cubeBoneTransforms[mesh.ParentBone.Index] *
                                      Matrix.CreateScale(Scale) *
                                      Matrix.CreateRotationX(MathHelper.ToRadians(90)) *
                                      Matrix.CreateTranslation(new Vector3(Position.X, Position.Y, Position.Z + LineLength));

                        if (Camera != null)
                        {
                            effect.World      = _coneZWorld;
                            effect.View       = Camera.View;
                            effect.Projection = Camera.Projection;
                        }

                        effect.EnableDefaultLighting();
                        effect.PreferPerPixelLighting = true;

                        if (SelectedAxis == SelectedAxis.Z)
                        {
                            effect.DiffuseColor      = Color.Yellow.ToVector3();
                            effect.AmbientLightColor = Color.Yellow.ToVector3();
                        }
                        else
                        {
                            effect.DiffuseColor      = _zColor.ToVector3();
                            effect.AmbientLightColor = _zColor.ToVector3();
                        }
                    }
                    mesh.Draw();
                }

                TranslationPointer.CopyBoneTransformsFrom(_coneOriginalBoneTransforms);

                #endregion
            }

            #endregion

            #region Scale Pointer

            if (SelectMode == SelectedDisplayMode.Scale)
            {
                #region Draw Cube Pointer for X Axis

                foreach (ModelMesh mesh in ScalePointer.Meshes)
                {
                    foreach (BasicEffect effect in mesh.Effects)
                    {
                        _cubeXWorld = _cubeBoneTransforms[mesh.ParentBone.Index] *
                                      Matrix.CreateScale(Scale) *
                                      Matrix.CreateTranslation(new Vector3(Position.X + LineLength, Position.Y, Position.Z));


                        if (Camera != null)
                        {
                            effect.World      = _cubeXWorld;
                            effect.View       = Camera.View;
                            effect.Projection = Camera.Projection;
                        }

                        effect.EnableDefaultLighting();
                        effect.PreferPerPixelLighting = true;

                        effect.AmbientLightColor = _xColor.ToVector3();
                        effect.DiffuseColor      = _xColor.ToVector3();
                    }
                    mesh.Draw();
                }

                // Copy our bone transforms from our original
                ScalePointer.CopyBoneTransformsFrom(_cubeOriginalBoneTransforms);

                #endregion

                #region Draw Cube Pointer for Y Axis

                foreach (ModelMesh mesh in ScalePointer.Meshes)
                {
                    foreach (BasicEffect effect in mesh.Effects)
                    {
                        _cubeYWorld = _cubeBoneTransforms[mesh.ParentBone.Index] *
                                      Matrix.CreateScale(Scale) *
                                      Matrix.CreateTranslation(new Vector3(Position.X, Position.Y + LineLength, Position.Z));

                        if (Camera != null)
                        {
                            effect.World      = _cubeYWorld;
                            effect.View       = Camera.View;
                            effect.Projection = Camera.Projection;
                        }

                        effect.EnableDefaultLighting();
                        effect.PreferPerPixelLighting = true;

                        effect.DiffuseColor      = _yColor.ToVector3();
                        effect.AmbientLightColor = _yColor.ToVector3();
                    }
                    mesh.Draw();
                }

                // Copy our bone transforms from our original
                ScalePointer.CopyBoneTransformsFrom(_cubeOriginalBoneTransforms);

                #endregion

                #region Draw Cube Pointer for Z Axis

                foreach (ModelMesh mesh in ScalePointer.Meshes)
                {
                    foreach (BasicEffect effect in mesh.Effects)
                    {
                        _cubeZWorld = _cubeBoneTransforms[mesh.ParentBone.Index] *
                                      Matrix.CreateScale(Scale) *
                                      Matrix.CreateTranslation(new Vector3(Position.X, Position.Y, Position.Z + LineLength));

                        if (Camera != null)
                        {
                            effect.World      = _cubeZWorld;
                            effect.View       = Camera.View;
                            effect.Projection = Camera.Projection;
                        }

                        effect.EnableDefaultLighting();
                        effect.PreferPerPixelLighting = true;

                        effect.DiffuseColor      = _zColor.ToVector3();
                        effect.AmbientLightColor = _zColor.ToVector3();
                    }
                    mesh.Draw();
                }

                // Copy our bone transforms from our original
                ScalePointer.CopyBoneTransformsFrom(_cubeOriginalBoneTransforms);

                #endregion
            }

            #endregion

            base.Draw(gameTime);
        }