Jump to content
  • Advertisement
Sign in to follow this  

Help on viewMatrix

This topic is 2413 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

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??????\

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

balloonstringlength = balloonstringlength - blength;

float lookingdownangle = 64;

if (Heading == -1) Heading = LastHeading;
else Heading = Heading +90; // -180;

double ar = ((lookingdownangle / 180f) * Math.PI);
lookingdownradians = (float)ar;
cameraheight = (float)(Math.Cos(lookingdownradians) * balloonstringlength)*-1;
camerabackdist = (float)(Math.Sin(lookingdownradians) * balloonstringlength);
//Use heading to set Z rotation.
double piangle = ((Heading) / 180) * Math.PI;
camxdiff = (float)(Math.Sin(piangle) * camerabackdist);
camydiff = (float)(Math.Cos(piangle) * camerabackdist);
LastHeading = Heading;
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));



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

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;


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!