Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Player
- {
- Model playerModel;
- public Matrix playerWorld;
- Matrix[] playerTransforms;
- float speed = 200f;
- float rotationRate = 0.3f;
- public Player()
- {
- playerWorld = Matrix.CreateScale(0.1f);
- }
- public void LoadContent(ContentManager content)
- {
- playerModel = content.Load<Model>("playerModel");
- playerTransforms = new Matrix[playerModel.Bones.Count];
- playerModel.CopyAbsoluteBoneTransformsTo(playerTransforms);
- }
- public void Update(float dt)
- {
- KeyboardState kbs = Keyboard.GetState();
- if (kbs.IsKeyDown(Keys.W))
- playerWorld *= Matrix.CreateTranslation(playerWorld.Forward * speed * dt);
- if(kbs.IsKeyDown(Keys.S))
- playerWorld *= Matrix.CreateTranslation(playerWorld.Backward * speed * dt);
- if (kbs.IsKeyDown(Keys.A))
- {
- Vector3 temp = playerWorld.Translation;
- playerWorld.Translation = Vector3.Zero;
- playerWorld *= Matrix.CreateRotationY(rotationRate * dt);
- playerWorld.Translation = temp;
- }
- if (kbs.IsKeyDown(Keys.D))
- {
- Vector3 temp = playerWorld.Translation;
- playerWorld.Translation = Vector3.Zero;
- playerWorld *= Matrix.CreateRotationY(-rotationRate * dt);
- playerWorld.Translation = temp;
- }
- }
- public void Draw(Camera3rdPerson cam)
- {
- foreach (ModelMesh mm in playerModel.Meshes)
- {
- foreach (BasicEffect bfx in mm.Effects)
- {
- bfx.View = cam.view;
- bfx.Projection = cam.proj;
- bfx.World = playerTransforms[mm.ParentBone.Index] * playerWorld;
- }
- mm.Draw();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement