示例#1
0
        public void Draw(ArcBallCamera camera, BasicEffect effect)
        {
            foreach (EffectPass pass in effect.CurrentTechnique.Passes)
            {
                //make origin point of a sphere-like frez at the bottom instead of middle
                Vector3 pos = Position;
                if (Type == FileHelper.FrezType.K)
                {
                    pos.Y += diameter / 2.0f;
                }

                pass.Apply();
                primitive.Draw(Matrix.CreateTranslation(pos), camera.View, camera.Projection, Color.Gray);
            }
        }
        protected override void Initialize()
        {
            this.IsMouseVisible = true;
            screenCenter.X      = this.Window.ClientBounds.Width / 2;
            screenCenter.Y      = this.Window.ClientBounds.Height / 2;
            previousMouse       = Mouse.GetState();
            Mouse.SetPosition(screenCenter.X, screenCenter.Y);

            Effect           = new BasicEffect(graphics.GraphicsDevice);
            CameraArc        = new ArcBallCamera(new Vector3(0f, 0f, 0f), MathHelper.ToRadians(-200), 0f, 32f, 300f, 128f, GraphicsDevice.Viewport.AspectRatio, 0.1f, 512f); //rad -30 192
            FileHelper       = new FileHelper(graphics.GraphicsDevice);
            Brick            = new MaterialBrick(graphics.GraphicsDevice);
            Brick.CritError += new MaterialBrick.CritErrorHandler(StopMilling);
            Cutter1          = new Cutter(graphics.GraphicsDevice, 10);
            MillingLimit     = new SquarePrimitive(graphics.GraphicsDevice, 10, 140);
            base.Initialize();
        }
        public void Draw(ArcBallCamera camera, BasicEffect effect)
        {
            effect.EnableDefaultLighting();
            effect.VertexColorEnabled = true;
            effect.World      = Matrix.Identity;
            effect.View       = camera.View;
            effect.Projection = camera.Projection;
            //effect.DirectionalLight0.Enabled = true;
            effect.DirectionalLight0.DiffuseColor  = Color.White.ToVector3(); // a red light
            effect.DirectionalLight0.Direction     = new Vector3(0, 1, 0);    // coming along the x-axis/pnpphj
            effect.DirectionalLight0.SpecularColor = Color.White.ToVector3(); //new Vector3(0, 1, 0); // with green highlights
            //effect.PreferPerPixelLighting = true;

            //RasterizerState originalState = GraphicsDevice.RasterizerState;
            RasterizerState rasterizerState = new RasterizerState();

            rasterizerState.CullMode = CullMode.None;
            if (IsWireframeOn)
            {
                rasterizerState.FillMode = FillMode.WireFrame;
            }
            else
            {
                rasterizerState.FillMode = FillMode.Solid;
            }

            device.RasterizerState = rasterizerState;
            device.SetVertexBuffer(vertexBuffer);
            device.Indices = indexBuffer; //CHECK: send only once?

            foreach (EffectPass pass in effect.CurrentTechnique.Passes)
            {
                pass.Apply();
                //vertexBuffer.SetData<VertexPositionColorNormal>(Vertices);
                device.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, (Length + 1) * (Width + 1), 0, 2 * Length * Width);
            }
        }