move 3d camera lower on the screen.

I’m just learning 3d. I can display and rotate a model. Currently the camera is at the center of the screen. Is there anyway to have the camera lower on the screen?

How are you creating the View Matrix for the camera? The view matrix is effectively the World matrix for the camera, so made up of position and rotation (scale not needed).

I’m not sure how to enter code in this forum but below is all my matrix. I can move the model around but the camera is always at the center.

world = Matrix.CreateTranslation(new Vector3(0, 0, 0)) ;
view = Matrix.CreateLookAt(new Vector3(0, 0, 2), new Vector3(0, 0, 0), Vector3.Up);
projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(45), w / h, 0.1f, 100f);

What do you mean exactly by your camera is always at the center ? The center of the screen is your camera’s view into the world and your camera’s world position is what you pass for the position to

CreateLookAt
( 
positionOfCameraInTheWorld, 
camerasTargetPositionInTheWorldWereItIsToLookAt, 
theCurrentUpVectorDirectionInTheWorldThatDefinesTheCamerasUp
);

I made a picture to illustrate it.

To show code paste your code here (leave a empty line above and below before doing so) then highlight over it with the mouse and then click on the little button labeled preformatted text. < / >

1 Like

I’m very new to 3d so I’m sorry that I’m not explaining my self well. I’m going to try to post some diagram later to explain better.

The image is side representation of what the engine will draw for the player to see.

  1. The red line is the PreferredBackBufferHeight. The blue box is just the model.
  2. If I make the PreferredBackBufferHeight bigger the model will still appear in the middle.
  3. This is what I want to happen if I make the PreferredBackBufferHeight bigger. Is this possible?

I hope this makes more sense what I’m trying to accomplish.

The back buffer is not related to the camera like that.

The “camera” is just a set of matrices that are used to then render data to the back buffer. You could render multiple scenes, using multiple cameras to the same back buffer.

If it helps, here is my camera class, though I am not sure it will help.

Feel free to have a look at my git repo, it’s mostly 3D.

Could you not find a tutorial on line for this?

I may do a set of 3D basics tutorials for MG now :smiley:

2 Likes

Thank you for the code. I will give a try.

Just adding to what the others said;
To get something like your example number 3, you’d probably need to back the camera up a bit and move the target (point the camera’s looking at) upward. Like if you added 2 to the z of the cam position (to back it up from the object) and maybe 2 or more to the y of the target to look more upward.
ie:

// ie: changed: camera_position, look-at-target
view = Matrix.CreateLookAt(new Vector3(0, 0, 4), new Vector3(0, 2, 0), Vector3.Up);

You may need to experiment with the values though since I don’t know the scale of your scene.

What you indicated in your illustration is something that I think can’t be achieved natively with Monogame’s matrix methods intended for cameras, but you can inject your own matrix to achieve this. I actually had to do this for my current project.
Here’s my suggested solution, again, in accordance with your illustration (if that’s accurately what you’re trying to achieve):

effect.View = Matrix.CreateLookAt(...) * new Matrix(1, 0, 0, 0, 0, 1, yToZSkewRatio, 0, 0, 0, 1, 0, 0, 0, 0, 1);

This will skew the further points up/down according to the yToZSkewRatio value you supply. (If you have a specific angle in mind, you can use (float)Math.Tan(-angle) for this.) This is what I inferred from your drawing. If this is not what you intended, perhaps the previous reply is your better bet, which rotates the view upwards rather than skewing it. That solution might look more like this:

effect.View = Matrix.CreateLookAt(...) * Matrix.CreateRotationX(-pitch);

Or you could build it into your CreateLookAt matrix, as the previous post suggests.

Thank you for the post. I have being driving myself crazy trying different things and I can’t move the camera lower. You have saved me alot of time. I will try the custom matrix. I haven’t done linear algebra since university and I forgot 99.9% of it. I’m starting to think maybe Unity is the answer because 3d is alot more complicated than I anticipated. But I will still give custom matrix a try. Thank you again.

It’s actually not that complicated at least to use the Matrices. The matrix with the custom skew is a nice solution, but I am not sure that is what you meant? If you just want to have your camera lower, you can do that by changing the first parameter of the CreateLookAt method (and there the second parameter which is y or the up down component, in case you define up to be that direction in the very last parameter (you can use Vector3.Up which is just a shortcut for a unit length vector pointing in the y direction).

Also make sure that you apply all matrices when you draw the models. And keep in mind that the order of multiplication is important.

My guess is that this is what he actually wants but his question was so badly worded its hard to say.

In this case he wants a perspective feild of view projection matrix and to either rotate his world on the X axis or Use CreateLookAt to place his camera slightly down and looking up without rotating the world.