this is an example of what Im after:
http://gamesareevil....starraiders.jpg
I tried raising both the camera and where the camera is looking at on the up axis which when you first start the game the ship is positioned correctly on the screen but as soon as you move the camera does not follow it properly and the ship ends up somewhere else on the screen. Which was the advise I found at this post http://forums.create...689/181122.aspx which means either I did something wrong or it doesnt work right.
Here is my update camera code:
public void UpdateCamera(Ship target, GraphicsDevice device)
{
cameraRotation = Quaternion.Lerp(cameraRotation, target.ShipRotation, 0.1f);
Vector3 campos = new Vector3(0, 0.1f, 0.6f);
campos = Vector3.Transform(campos, Matrix.CreateFromQuaternion(cameraRotation));
campos += target.ShipPosition;
Vector3 camup = new Vector3(0, 1, 0);
camup = Vector3.Transform(camup, Matrix.CreateFromQuaternion(cameraRotation));
viewMatrix = Matrix.CreateLookAt(campos, target.ShipPosition, camup);
projectionMatrix = Matrix.CreatePerspectiveFieldOfView(MathHelper.PiOver4,
device.Viewport.AspectRatio, 0.000001f, 100000000.0f);
cameraPosition = campos;
cameraUpDirection = camup;
}
here is the input and draw methods which are slightly related I guess, incase something in there helps
public void HandleInput(GamePadState gamePadState, GameTime gameTime)
{
float leftRightRot = 0;
float upDownRot = 0;
float rollRotation = 0;
float turningSpeed = (float)
gameTime.ElapsedGameTime.TotalMilliseconds / 1000.0f;
leftRightRot += gamePadState.ThumbSticks.Left.X * 0.03f;
upDownRot -= gamePadState.ThumbSticks.Left.Y * 0.03f;
if (gamePadState.IsButtonDown(Buttons.LeftShoulder))
rollRotation += turningSpeed;
if (gamePadState.IsButtonDown(Buttons.RightShoulder))
rollRotation -= turningSpeed;
Quaternion additionalRot = Quaternion.CreateFromAxisAngle(new
Vector3(0, -1, 0), leftRightRot) * Quaternion.CreateFromAxisAngle(new
Vector3(1, 0, 0), upDownRot) * Quaternion.CreateFromAxisAngle(new
Vector3(0, 0, -1), rollRotation);
shipRotation *= additionalRot;
shipThrust(ref shipPosition, shipRotation);
}
public void Draw(Effect effect, Camera camera)
{
Matrix worldMatrix = Matrix.CreateScale(0.0005f, 0.0005f, 0.0005f) *
Matrix.CreateRotationY(MathHelper.Pi) * Matrix.CreateFromQuaternion(shipRotation) *
Matrix.CreateTranslation(shipPosition);
Matrix[] shipTransforms = new Matrix[shipModel.Bones.Count];
shipModel.CopyAbsoluteBoneTransformsTo(shipTransforms);
foreach (ModelMesh mesh in shipModel.Meshes)
{
foreach (Effect currentEffect in mesh.Effects)
{
currentEffect.CurrentTechnique = currentEffect.Techniques["Colored"];
currentEffect.Parameters["xWorld"].SetValue(
shipTransforms[mesh.ParentBone.Index] * worldMatrix);
currentEffect.Parameters["xView"].SetValue(camera.ViewMatrix);
currentEffect.Parameters["xProjection"].SetValue(camera.ProjectionMatrix);
currentEffect.Parameters["xEnableLighting"].SetValue(true);
currentEffect.Parameters["xLightDirection"].SetValue(camera.LightDirection);
currentEffect.Parameters["xAmbient"].SetValue(0.5f);
}
mesh.Draw();
}
}
I'm using code from Riemer's flightsim tutorials so far http://www.riemers.net/eng/Tutorials/XNA/Csharp/Series2/Quaternions.php, but it positions the ship in the middle of the screen. How would I change the code to make the ship position at the bottom center instead? I'm rather new to XNA and 3D programming so if you can help please explain with some example for me to see
thanks.