コード例 #1
0
ファイル: InputManager.cs プロジェクト: Woodje/3DGame
        public void updateCamera(Camera camera, CModel model)
        {
            if (Keyboard.GetState().IsKeyDown(Keys.W) || Mouse.GetState().RightButton == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.S) || Keyboard.GetState().IsKeyDown(Keys.A) || Keyboard.GetState().IsKeyDown(Keys.D))
            {
                // Move the camera to the new model's position and orientation
                ((ChaseCamera)camera).Move(model.Position, model.Rotation, cameraUpDownLook);
                cameraFreeRotation = model.Rotation;
            }

            if (Mouse.GetState().LeftButton == ButtonState.Pressed && Mouse.GetState().RightButton == ButtonState.Released)
                ((ChaseCamera)camera).Move(model.Position, cameraFreeRotation, cameraUpDownLook);

            // Update the camera
            camera.Update();
        }
コード例 #2
0
ファイル: BoneModel.cs プロジェクト: Woodje/3DGame
        public void Draw(Camera camera)
        {
            model.CopyAbsoluteBoneTransformsTo(_boneTransforms);

            // Draw the model.
            foreach (ModelMesh mesh in model.Meshes)
            {
                foreach (BasicEffect effect in mesh.Effects)
                {
                    effect.World = _boneTransforms[mesh.ParentBone.Index] * Matrix.CreateScale(15f) * Matrix.CreateTranslation(-50,50,-50);
                    effect.View = camera.View;
                    effect.Projection = camera.Projection;
                    effect.EnableDefaultLighting();
                }
                mesh.Draw();
            }
        }
コード例 #3
0
ファイル: Wall.cs プロジェクト: Woodje/3DGame
        public void Draw(GraphicsDeviceManager graphicsDeviceManager, Camera camera)
        {
            graphicsDeviceManager.GraphicsDevice.SetVertexBuffer(vertexBuffer);

            //Set object and camera info
            effect.World = world;
            effect.View = camera.View;
            effect.Projection = camera.Projection;
            effect.Texture = texture;
            effect.TextureEnabled = true;

            // Begin effect and draw for each pass
            foreach (EffectPass pass in effect.CurrentTechnique.Passes)
            {
                pass.Apply();
                graphicsDeviceManager.GraphicsDevice.DrawUserPrimitives<VertexPositionTexture>
                (PrimitiveType.TriangleStrip, wall, 0, 11);
            }
        }
コード例 #4
0
ファイル: InputManager.cs プロジェクト: Woodje/3DGame
        public void updateModel(GameTime gameTime, Camera camera, CModel model, GraphicsDeviceManager graphics)
        {
            prevPosition = model.Position;

            Vector3 rotChange = new Vector3(0, 0, 0);
            Vector3 freeRotation = new Vector3(0, 0, 0);
            Vector3 upDownLook = new Vector3(0, 0, 0);

            // Determine how much the camera should turn
            float deltaX = (float)lastMouseState.X - (float)Mouse.GetState().X;
            float deltaY = (float)lastMouseState.Y - (float)Mouse.GetState().Y;

            // Calculate scroll wheel movement
            scrollDelta = (float)lastMouseState.ScrollWheelValue - (float)Mouse.GetState().ScrollWheelValue;
            ((ChaseCamera)camera).UpdateScroolDelta(scrollDelta);

            // Move model with mouse
            if (Mouse.GetState().RightButton == ButtonState.Pressed)
            {
                rotChange = new Vector3(0, deltaX * 0.1f, 0);
                upDownLook = new Vector3(deltaY * 0.1f, 0, 0);
            }
            if (Mouse.GetState().LeftButton == ButtonState.Pressed)
            {
                freeRotation = new Vector3(deltaY * 0.1f, deltaX * 0.1f, 0);
            }

            // Rotate model with keyboard
            if (Keyboard.GetState().IsKeyDown(Keys.A) && Mouse.GetState().RightButton == ButtonState.Released)
                rotChange = new Vector3(0, 1, 0);
            if (Keyboard.GetState().IsKeyDown(Keys.D) && Mouse.GetState().RightButton == ButtonState.Released)
                rotChange = new Vector3(0, -1, 0);

            // Set speed of model and camera
            model.Rotation += rotChange * .025f;
            cameraFreeRotation += freeRotation * .025f;
            cameraUpDownLook += upDownLook * .025f;

            // Determine what direction to move in
            Matrix rotation = Matrix.CreateFromYawPitchRoll(model.Rotation.Y, 0, model.Rotation.Z);

            // Move in the direction dictated by our rotation matrix
            if (Keyboard.GetState().IsKeyDown(Keys.W) || Mouse.GetState().RightButton == ButtonState.Pressed && Mouse.GetState().LeftButton == ButtonState.Pressed)
            {
                model.Model.Root.Transform = Matrix.CreateRotationY(0);
                model.Model.Bones[1].Transform *= Matrix.CreateRotationX(-0.2f);
                model.Model.Bones[2].Transform *= Matrix.CreateRotationX(-0.2f);
                model.Model.Bones[3].Transform = Matrix.CreateTranslation(new Vector3(0, 5.235f, -5.235f)) * Matrix.CreateRotationY(MathHelper.ToRadians(90));
                model.Position += Vector3.Transform(Vector3.Forward, rotation) * (float)gameTime.ElapsedGameTime.TotalMilliseconds * 0.2f;
                if (collision.UpdateCollision(model))
                    model.Position = prevPosition;
            }

            if (Keyboard.GetState().IsKeyDown(Keys.S))
            {
                model.Model.Root.Transform = Matrix.CreateRotationY(0);
                model.Model.Bones[1].Transform *= Matrix.CreateRotationX(0.2f);
                model.Model.Bones[2].Transform *= Matrix.CreateRotationX(0.2f);
                model.Model.Bones[3].Transform = Matrix.CreateTranslation(new Vector3(0, 5.235f, -5.235f)) * Matrix.CreateRotationY(MathHelper.ToRadians(90));
                model.Position += Vector3.Transform(Vector3.Backward, rotation) * (float)gameTime.ElapsedGameTime.TotalMilliseconds * 0.2f;
                if (collision.UpdateCollision(model))
                    model.Position = prevPosition;
            }

            // Move model left and right
            if (Keyboard.GetState().IsKeyDown(Keys.D) && Mouse.GetState().RightButton == ButtonState.Pressed)
            {
                if (Keyboard.GetState().IsKeyDown(Keys.W) || Mouse.GetState().RightButton == ButtonState.Pressed && Mouse.GetState().LeftButton == ButtonState.Pressed)
                {
                    model.Model.Root.Transform = Matrix.CreateRotationY(-0.5f);
                    model.Model.Bones[3].Transform = Matrix.CreateTranslation(new Vector3(0, 5.235f, -5.235f)) * Matrix.CreateRotationY(MathHelper.ToRadians(135));
                }
                else if (Keyboard.GetState().IsKeyDown(Keys.S))
                {
                    model.Model.Root.Transform = Matrix.CreateRotationY(0.5f);
                    model.Model.Bones[3].Transform = Matrix.CreateTranslation(new Vector3(0, 5.235f, -5.235f)) * Matrix.CreateRotationY(MathHelper.ToRadians(90));
                }
                else
                {
                    model.Model.Root.Transform = Matrix.CreateRotationY(MathHelper.ToRadians(-90));
                    model.Model.Bones[1].Transform *= Matrix.CreateRotationX(-0.2f);
                    model.Model.Bones[2].Transform *= Matrix.CreateRotationX(-0.2f);
                    model.Model.Bones[3].Transform = Matrix.CreateTranslation(new Vector3(0, 5.235f, -5.235f)) * Matrix.CreateRotationY(MathHelper.ToRadians(90));
                }

                model.Position += Vector3.Transform(Vector3.Right, rotation) * (float)gameTime.ElapsedGameTime.TotalMilliseconds * 0.2f;
                if (collision.UpdateCollision(model))
                    model.Position -= Vector3.Transform(Vector3.Right, rotation) * (float)gameTime.ElapsedGameTime.TotalMilliseconds * 0.2f;
            }
            if (Keyboard.GetState().IsKeyDown(Keys.A) && Mouse.GetState().RightButton == ButtonState.Pressed)
            {
                if (Keyboard.GetState().IsKeyDown(Keys.W) || Mouse.GetState().RightButton == ButtonState.Pressed && Mouse.GetState().LeftButton == ButtonState.Pressed)
                {
                    model.Model.Root.Transform = Matrix.CreateRotationY(0.5f);
                    model.Model.Bones[3].Transform = Matrix.CreateTranslation(new Vector3(0, 5.235f, -5.235f)) * Matrix.CreateRotationY(MathHelper.ToRadians(45));
                }
                else if (Keyboard.GetState().IsKeyDown(Keys.S))
                {
                    model.Model.Root.Transform = Matrix.CreateRotationY(-0.5f);
                    model.Model.Bones[3].Transform = Matrix.CreateTranslation(new Vector3(0, 5.235f, -5.235f)) * Matrix.CreateRotationY(MathHelper.ToRadians(90));
                }
                else
                {
                    model.Model.Root.Transform = Matrix.CreateRotationY(MathHelper.ToRadians(90));
                    model.Model.Bones[1].Transform *= Matrix.CreateRotationX(-0.2f);
                    model.Model.Bones[2].Transform *= Matrix.CreateRotationX(-0.2f);
                    model.Model.Bones[3].Transform = Matrix.CreateTranslation(new Vector3(0, 5.235f, -5.235f)) * Matrix.CreateRotationY(MathHelper.ToRadians(90));
                }

                model.Position += Vector3.Transform(Vector3.Left, rotation) * (float)gameTime.ElapsedGameTime.TotalMilliseconds * 0.2f;
                if (collision.UpdateCollision(model))
                    model.Position -= Vector3.Transform(Vector3.Left, rotation) * (float)gameTime.ElapsedGameTime.TotalMilliseconds * 0.2f;
            }

            // Set mouse position and do initial get state
            Mouse.SetPosition(graphics.GraphicsDevice.Viewport.Width / 2, graphics.GraphicsDevice.Viewport.Height / 2);

            // Update the mousestate
            lastMouseState = Mouse.GetState();
        }
コード例 #5
0
ファイル: MapManager.cs プロジェクト: Woodje/3DGame
 public void Draw(GraphicsDeviceManager graphicsDeviceManager, Camera camera)
 {
     foreach (Tile tile in tiles)
         tile.Draw(graphicsDeviceManager, camera);
 }
コード例 #6
0
ファイル: Game1.cs プロジェクト: Woodje/3DGame
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            models.Add(new CModel(Content.Load<Model>("freak"), new Vector3(40, 50, 50), Vector3.Zero, false, new Vector3(10), GraphicsDevice));

            models.Add(new CModel(Content.Load<Model>("new1"), Vector3.Zero, Vector3.Zero, false, new Vector3(200f), GraphicsDevice));

            camera = new ChaseCamera(new Vector3(0, 50, 300), new Vector3(0, 50, 0), Vector3.Zero, GraphicsDevice);
            ((ChaseCamera)camera).Move(models[0].Position, models[0].Rotation, new Vector3(0, 0, 0));

            map.LoadContent(graphics, Content);

            boner = new BoneModel(Content.Load<Model>("freak3"));

            bB.Min = new Vector3(0, 0, 100);
            bB.Max = new Vector3(100, 100, 200);

            tile = new Tile(Content.Load<Texture2D>("CylinderSkin"), graphics, new Vector3(0, 0, 100), new Vector3(100, 100, 100));
        }