Help on viewMatrix

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

Recommended Posts

I can't seem to get my head around Matrix.CreateLookAt.

Currently my vehicle is always displayed in the center of the screen, however I would like to have it drawn in the bottom part of the screen. I am using world matrix and think I need to modify the way the camera is looking at the screen.

Every time I move, my currentposx and currentposy values are modified, they represent my current vehicle x,y pos (z is constant).

Take a look at the code below, how do I move my center point away from the center of the screen??????\
THANKS!
Johannes

public void MoveCamera(float blength, float Heading,float speed)
{

balloonstringlength = balloonstringlength - blength;

float lookingdownangle = 64;

double ar = ((lookingdownangle / 180f) * Math.PI);
//Use heading to set Z rotation.
double piangle = ((Heading) / 180) * Math.PI;
camxdiff = (float)(Math.Sin(piangle) * camerabackdist);
camydiff = (float)(Math.Cos(piangle) * camerabackdist);
LastSpeed = speed;

}

private void SetUpCamera()
{

viewMatrix = Matrix.CreateLookAt(new Vector3(currentposx - camxdiff , currentposy - camydiff , cameraheight), new Vector3(currentposx , currentposy , currentposz), new Vector3(0.0f, 0.0f, -1.0f));

projectionMatrix = Matrix.CreatePerspectiveFieldOfView(MathHelper.PiOver4 , GraphicsDevice.Viewport.AspectRatio, (float)Draw2D.gridmeter, (float)(Draw2D.gridmeter * 50));

}
}

draw()
{

translationMatrix = Matrix.CreateTranslation(0, 0, 0.0f);

SetUpCamera();
effect.View = viewMatrix;
effect.Projection = projectionMatrix;
effect.World = translationMatrix;

//Rotate vehicle in position 0, then move to current pos, angle is heading of vehicle
translationMatrix = Matrix.CreateTranslation(currentposx , currentposy , 0.0f);
rotationMatrix = Matrix.CreateRotationZ((float)(angle * Math.PI / 180));
effect.View = viewMatrix;
effect.Projection = projectionMatrix;
effect.World = worldMatrix * rotationMatrix * translationMatrix;

}

• Game Developer Survey

We are looking for qualified game developers to participate in a 10-minute online survey. Qualified participants will be offered a \$15 incentive for your time and insights. Click here to start!

• 15
• 21
• 21
• 11
• 9