Creating predefinied camera views - How do I move the camera to make sense while using Controller?
Posted
by
Deukalion
on Game Development
See other posts from Game Development
or by Deukalion
Published on 2012-06-27T14:02:58Z
Indexed on
2012/06/27
15:27 UTC
Read the original article
Hit count: 376
I'm trying to understand 3D but the one thing I can't seem to understand is the Camera.
Right now I'm rendering four 3D Cubes with textures and I set the Project Matrix:
public BasicCamera3D(float fieldOfView, float aspectRatio, float clipStart, float clipEnd, Vector3 cameraPosition, Vector3 cameraLookAt)
{
projection_fieldOfView = MathHelper.ToRadians(fieldOfView);
projection_aspectRatio = aspectRatio;
projection_clipstart = clipStart;
projection_clipend = clipEnd;
matrix_projection = Matrix.CreatePerspectiveFieldOfView(projection_fieldOfView, aspectRatio, clipStart, clipEnd);
view_cameraposition = cameraPosition;
view_cameralookat = cameraLookAt;
matrix_view = Matrix.CreateLookAt(cameraPosition, cameraLookAt, Vector3.Up);
}
BasicCamera3D gameCamera = new BasicCamera3D(45f, GraphicsDevice.Viewport.AspectRatio, 1.0f, 1000f, new Vector3(0, 0, 8), new Vector3(0, 0, 0));
This creates a sort of "Top-Down" camera, with 8 (still don't get the unit type here - it's not pixels I guess?)
But, if I try to position the camera at the side to make "Side-View" or "Reverse Side View" camera, the camera is rotating to much until it's turned around it a couple of times.
I render the boxes at:
new Vector3(-1, 0, 0)
new Vector3(0, 0, 0)
new Vector3(1, 0, 0)
new Vector3(1, 0, 1)
and with the Top-Down camera it shows good, but I don't get how I can make the camera show the side or 45 degrees from top (Like 3rd person action games) because the logic doesn't make sense.
Also, since every object you render needs a new BasicEffect with a new projection/view/world - can you still use the "same" camera always so you don't have to create a new View/Matrix and such for each object. It's seems weird.
If someone could help me get the camera to navigate around my objects "naturally" so I can be able to set a few predtermined views to choose from it would be really helpful.
Are there some sort of algorithm to calculate the view for this and perhaps not simply one value?
Examples:
Top-Down-View: I have an object at 0, 0, 0 when I turn the right stick on the Xbox 360 Controller it should rotate around that object kind of, not flip and turn upside down, disappear and then magically appear as a tiny dot somewhere I have no clue where it is like it feels like it does now.
Side-View: I have an object at 0, 0, 0 when I rotate to sides or up and down, the camera should be able to show a little more of the periphery to each side (depending on which you look at), and the same while moving up or down.
© Game Development or respective owner