Jump to content
  • Advertisement
Sign in to follow this  

Controls not responding

This topic is 3175 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Ok, well i got a fps camera, which works and basically plots a single model on vector3.zero, so i changed it to allot me to change the spots of this models in way like new vector3(0.0f, 50.0f, 20.0f,) but when i change it to allow that the contotrls dont work, only escape does. Below is my code, it must be simple what im doing wrong :S using System; using System.Collections.Generic; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Audio; using Microsoft.Xna.Framework.Content; using Microsoft.Xna.Framework.GamerServices; using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Input; using Microsoft.Xna.Framework.Net; using Microsoft.Xna.Framework.Storage; namespace CameraDemo { /// <summary> /// This is the main type for your game /// </summary> public class Game1 : Microsoft.Xna.Framework.Game { GraphicsDeviceManager graphics; SpriteBatch spriteBatch; Vector3 cameraPosition; Vector3 cameraTarget; Vector3 cameraReference; float aspectRatio; float nearPlane; float farPlane; float fieldOfView; Matrix Projection; float cameraYaw; float cameraPitch; MouseState mStateCashe; Vector3 modelPosition; //TEST CODE START GameObject crate = new GameObject(); //TEST CODE END public Game1() { graphics = new GraphicsDeviceManager(this); Content.RootDirectory = "Content"; } /// <summary> /// Allows the game to perform any initialization it needs to before starting to run. /// This is where it can query for any required services and load any non-graphic /// related content. Calling base.Initialize will enumerate through any components /// and initialize them as well. /// </summary> protected override void Initialize() { // TODO: Add your initialization logic here nearPlane = 1.0f; farPlane = 1000.0f; fieldOfView = 45.0f; cameraPosition = new Vector3(0.0f, 0.0f, 0.0f); cameraReference = new Vector3(0.0f, 0.0f, 1.0f); cameraTarget = cameraReference + cameraPosition; cameraYaw = 0.0f; cameraPitch = 0.0f; aspectRatio = (float)graphics.GraphicsDevice.Viewport.Width / (float)graphics.GraphicsDevice.Viewport.Height; modelPosition = new Vector3(0.0f, -0.5f, 5.0f); Projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(fieldOfView), aspectRatio, nearPlane, farPlane); Mouse.SetPosition(graphics.GraphicsDevice.Viewport.Width / 2, graphics.GraphicsDevice.Viewport.Height / 2); mStateCashe = Mouse.GetState(); base.Initialize(); } /// <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); // TODO: use this.Content to load your game content here crate.model = Content.Load<Model>("Models\\crate"); } /// <summary> /// UnloadContent will be called once per game and is the place to unload /// all content. /// </summary> protected override void UnloadContent() { // TODO: Unload any non ContentManager content here } /// <summary> /// Allows the game to run logic such as updating the world, /// checking for collisions, gathering input, and playing audio. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> protected override void Update(GameTime gameTime) { // Allows the game to exit if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed) this.Exit(); // TODO: Add your update logic here KeyboardState kState = Keyboard.GetState(); MouseState mState = Mouse.GetState(); float deltaTime = (float)gameTime.ElapsedGameTime.TotalSeconds; Vector3 moveVector = Vector3.Zero; if (kState.IsKeyDown(Keys.W)) { moveVector.Z += 3.0f * deltaTime; } if (kState.IsKeyDown(Keys.S)) { moveVector.Z -= 3.0f * deltaTime; } if (kState.IsKeyDown(Keys.A)) { moveVector.X += 3.0f * deltaTime; } if (kState.IsKeyDown(Keys.D)) { moveVector.X -= 3.0f * deltaTime; } if (kState.IsKeyDown(Keys.Escape)) { this.Exit(); } float mouseX = mState.X - mStateCashe.X; float mouseY = mState.Y - mStateCashe.Y; cameraPitch += (mouseY * 0.4f) * deltaTime; cameraYaw -= (mouseX * 0.4f) * deltaTime; cameraPitch = MathHelper.Clamp(cameraPitch, MathHelper.ToRadians(-89.9f), MathHelper.ToRadians(89.9f)); Mouse.SetPosition(graphics.GraphicsDevice.Viewport.Width / 2, graphics.GraphicsDevice.Viewport.Height / 2); Matrix cameraViewRotationMatrix = Matrix.CreateRotationX(cameraPitch) * Matrix.CreateRotationY(cameraYaw); Matrix cameraMoveRotationMatrix = Matrix.CreateRotationY(cameraYaw); Vector3 transformedCameraReference = Vector3.Transform(cameraReference, cameraViewRotationMatrix); cameraPosition += Vector3.Transform(moveVector, cameraMoveRotationMatrix); cameraTarget = transformedCameraReference + cameraPosition; base.Update(gameTime); } /// <summary> /// This is called when the game should draw itself. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> protected override void Draw(GameTime gameTime) { graphics.GraphicsDevice.Clear(Color.CornflowerBlue); //START NEW CODE DrawGameObject(crate); // TODO: Add your drawing code here base.Draw(gameTime); } void DrawGameObject(GameObject gameobject) { foreach (ModelMesh mesh in gameobject.model.Meshes) { foreach (BasicEffect effect in mesh.Effects) { effect.EnableDefaultLighting(); effect.PreferPerPixelLighting = true; effect.World = Matrix.CreateFromYawPitchRoll( gameobject.rotation.Y, gameobject.rotation.X, gameobject.rotation.Z) * Matrix.CreateScale(gameobject.scale) * Matrix.CreateTranslation(gameobject.position); } mesh.Draw(); } } } }

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!