Quin's Profile
Reputation: 18
Tradesman
- Group:
- Contributors
- Active Posts:
- 359 (0.21 per day)
- Joined:
- 16-October 08
- Profile Views:
- 9,446
- Last Active:
Mar 07 2013 11:53 AM- Currently:
- Offline
Previous Fields
- Country:
- GB
- OS Preference:
- Windows
- Favorite Browser:
- Chrome
- Favorite Processor:
- Intel
- Favorite Gaming Platform:
- XBox
- Your Car:
- BMW
- Dream Kudos:
- 50
Latest Visitors
-
brep 
29 Mar 2012 - 16:19 -
macosxnerd101 
11 Oct 2011 - 09:46 -
Dogstopper 
10 Oct 2011 - 03:10
Posts I've Made
-
In Topic: Moving a First Person Camera - Land Based
Posted 4 Mar 2013
Sorry, I just assumed that people would just get it straight away.
The controls are WASD, just for the debugging (I'm going to have those changeable at some point); so that's forwards, side to side, and backwards. Mouse movement is 'look'.
Here's the entire code
using System; using System.Collections.Generic; using System.Linq; 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.Media; namespace _3D_Game { public class Camera : Microsoft.Xna.Framework.GameComponent { // Camera matricies public Matrix view { get; protected set; } public Matrix projection { get; protected set; } // Camera vectors public Vector3 cameraPosition { get; protected set; } Vector3 cameraDirection; Vector3 cameraUp; MouseState prevMouseState; float speed = 3; // Max yaw/pitch variable float totalYaw = MathHelper.PiOver4 / 2; float currentYaw = 0; float totalPitch = MathHelper.PiOver4 / 2; float currentPitch = 0; public Camera(Game game, Vector3 pos, Vector3 target, Vector3 up) : base(game) { // view = Matrix.CreateLookAt(pos, target, up); // Build camera view matrix cameraPosition = pos; cameraDirection = target - pos; cameraDirection.Normalize(); cameraUp = up; CreateLookAt(); projection = Matrix.CreatePerspectiveFieldOfView( MathHelper.PiOver4, (float)Game.window.ClientBounds.Width / (float)Game.window.ClientBounds.Height, 1, 3000); } public override void Initialize() { // Set mouse position and do intial get state Mouse.SetPosition(Game.window.ClientBounds.Width / 2, Game.window.ClientBounds.Height / 2); prevMouseState = Mouse.GetState(); base.Initialize(); } public override void Update(GameTime gameTime) { // Move forward/backward if (Keyboard.GetState().IsKeyDown(Keys.W)) { // cameraDirection.Y = 0; cameraPosition += cameraDirection * speed; } if (Keyboard.GetState().IsKeyDown(Keys.S)) { // cameraDirection.Y = 0; cameraPosition -= cameraDirection * speed; } // Move side to side if (Keyboard.GetState().IsKeyDown(Keys.A)) cameraPosition += Vector3.Cross(cameraUp, cameraDirection) * speed; if (Keyboard.GetState().IsKeyDown(Keys.D)) cameraPosition -= Vector3.Cross(cameraUp, cameraDirection) * speed; // Yaw rotation float yawAngle = (-MathHelper.PiOver4 / 150) * (Mouse.GetState().X - prevMouseState.X); if (Math.Abs(currentYaw + yawAngle) < totalYaw) { cameraDirection = Vector3.Transform(cameraDirection, Matrix.CreateFromAxisAngle(cameraUp, yawAngle)); currentYaw += yawAngle; } // Pitch rotation float pitchAngle = (MathHelper.PiOver4 / 150) * (Mouse.GetState().Y - prevMouseState.Y); if (Math.Abs(currentPitch + pitchAngle) < totalPitch) { cameraDirection = Vector3.Transform(cameraDirection, Matrix.CreateFromAxisAngle( Vector3.Cross(cameraUp, cameraDirection), pitchAngle)); currentPitch += pitchAngle; } // Reset prevMouseState prevMouseState = Mouse.GetState(); // Recreate the camera view matrix CreateLookAt(); base.Update(gameTime); } private void CreateLookAt() { view = Matrix.CreateLookAt(cameraPosition, cameraPosition + cameraDirection, cameraUp); } } }
Edit: Very easy to do actually. I was on the right lines, but I needed to call another method with the Y axis set at 0, and then use that for movement rather than the camera :-D -
In Topic: Revealing Content in Floating Divs
Posted 11 Oct 2011
Hmm, no, I just used class="wrapper" for both, with <div class="clearer"></div> before the end (as can be seen in the original coding.
Would that work? (I don't feel like testing it right now :-D) -
In Topic: Remove Reputation
Posted 10 Oct 2011
-
In Topic: Remove Reputation
Posted 10 Oct 2011
Well I don't know what has happened to this member, since they have -12 and are Disgraced. I have been abused :-(
Thanks for the reply... like I said, it doesn't overly bother me. -
In Topic: Dream.in.Code 10th Birthday/500k Members Contest!
Posted 10 Oct 2011
I'm tempted... who wouldn't be?
Question is, what should I tutor on?
My Information
- Member Title:
- D.I.C Regular
- Age:
- 24 years old
- Birthday:
- November 3, 1988
- Gender:
-
- Location:
- West Yorkshire, England
- Full Name:
- Niall Deakin
- Years Programming:
- 9
- Programming Languages:
- HTML, CSS, VB6, Java, Javascript, PHP, MySQL, ActionScript, VBScript, C#
Contact Information
- E-mail:
- Private
- Website URL:
-
http://www.classicniall.co.uk
- Skype:
-
Quin452
- Facebook:
- http://facebook.com/ClassicNiall
- Twitter:
- Quin452
Friends
|
|


Find Topics
Find Posts
View Reputation Given


|
Comments
Quin has no profile comments yet. Why not say hello?