Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using Microsoft.Xna.Framework;
- using Microsoft.Xna.Framework.Content;
- using Microsoft.Xna.Framework.Graphics;
- using Microsoft.Xna.Framework.Input;
- namespace Games_Game_1
- {
- class player
- {
- private Model myModel;
- public Matrix[] Transforms;
- //Position of the model in world space
- public Vector3 Position = Vector3.Zero;
- //Velocity of the model, applied each frame to the model's position
- public Vector3 Velocity = Vector3.Zero;
- public Matrix RotationMatrix = Matrix.Identity;
- private float rotation;
- public float Rotation
- {
- get { return rotation; }
- set
- {
- float newVal = value;
- while (newVal >= MathHelper.TwoPi)
- {
- newVal -= MathHelper.TwoPi;
- }
- while (newVal < 0)
- {
- newVal += MathHelper.TwoPi;
- }
- if (rotation != newVal)
- {
- rotation = newVal;
- RotationMatrix = Matrix.CreateRotationY(rotation);
- }
- }
- }
- public void Update(GamePadState controllerState)
- {
- // Rotate the model using the left thumbstick, and scale it down.
- Rotation -= controllerState.ThumbSticks.Left.X * 0.10f;
- // Finally, add this vector to our velocity.
- Velocity += RotationMatrix.Forward * 1.0f *
- controllerState.Triggers.Right;
- }
- Vector3 modelPosition = Vector3.Zero;
- float modelRotation = 0.0f;
- Vector3 cameraPosition = new Vector3(0.0f, 50.0f, 5000.0f);
- public void Draw(GameTime gameTime)
- {
- // TODO: Add your drawing code here
- Matrix[] transforms = new Matrix[myModel.Bones.Count];
- myModel.CopyAbsoluteBoneTransformsTo(transforms);
- foreach (ModelMesh mesh in myModel.Meshes)
- {
- foreach (BasicEffect effect in mesh.Effects)
- {
- effect.EnableDefaultLighting();
- effect.World = transforms[mesh.ParentBone.Index] *
- Matrix.CreateRotationY(modelRotation)
- * Matrix.CreateTranslation(modelPosition);
- effect.View = Matrix.CreateLookAt(cameraPosition,
- Vector3.Zero, Vector3.Up);
- effect.Projection = Matrix.CreatePerspectiveFieldOfView(
- MathHelper.ToRadians(45.0f), aspectRatio,
- 1.0f, 10000.0f);
- }
- mesh.Draw();
- }
- base.Draw(gameTime);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement