hi this is a simple first person camera algortihm I get the main code from an online website and I add modifications to it so please I want know whether this algorithms is efficient or not
using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
namespace NeuronGame
{
public class Camera
{
public Vector3 cameraPosition;
public Vector3 cameraTarget;
public Vector3 cameraReference;
public void intialize(GraphicsDevice graphics)
{
// TODO: Add your initialization logic here
cameraPosition = new Vector3(0.0f, 0.0f, 0.0f);
cameraReference = new Vector3(0.0f, 0.0f, 1.0f);
cameraTarget = cameraReference + cameraPosition;
//Projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(fieldOfView), aspectRatio, nearPlane, farPlane);
}
public void update(GameTime gameTime,GraphicsDevice graphics)
{
KeyboardState kState = Keyboard.GetState();
MouseState mState = Mouse.GetState();
float deltaTime = (float)gameTime.ElapsedGameTime.TotalSeconds;
Vector3 moveVector = Vector3.Zero;
if (kState.IsKeyDown(Keys.W))
{
moveVector.Y += 20.0f ;
}
if (kState.IsKeyDown(Keys.S))
{
moveVector.Y -= 20.0f ;
}
if (kState.IsKeyDown(Keys.Left))
{
moveVector.X += 20.0f ;
}
if (kState.IsKeyDown(Keys.Right))
{
moveVector.X -= 20.0f ;
}
if (kState.IsKeyDown(Keys.Up))
{
moveVector.Z += 20.0f ;
}
if (kState.IsKeyDown(Keys.Down))
{
moveVector.Z -= 20.0f ;
}
Matrix cameraViewRotationMatrix = Matrix.CreateRotationX(MathHelper.ToRadians(45));
Vector3 transformedCameraReference = Vector3.Transform(cameraReference, cameraViewRotationMatrix);
cameraPosition += Vector3.Transform(moveVector, Matrix.Identity);
cameraTarget = transformedCameraReference + cameraPosition;
}
}
}