> For the complete documentation index, see [llms.txt](https://docs.flatredball.com/flatredball/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.flatredball.com/flatredball/tutorials/code-tutorials/flatredballxna-tutorials-3d-camera-setup.md).

# 3D Camera Setup

### Introduction

The default FlatRedBall camera presents a 3D view - the further an object is from the camera the smaller it appears. However, the camera looks down the Z axis and its default settings assume that this is the view for performance reasons. The camera can be modified so that it doesn't have to view down the Z axis.

### Looking down a different axis

The following code creates sets the camera to look down the Y axis rather than Z axis. It is common in 3D applications using FlatRedBall to have the ground lie on the XY axis and Z be height. Add the following in Initialize after initializing FlatRedBall:

```csharp
// Make the camera look down the Y axis so that Z is up:
Camera.Main.RotationX = (float)System.Math.PI / 2.0f;

// Since we're not looking down the Z axis turn off culling
Camera.Main.CameraCullMode = CameraCullMode.None;

// If the XY plane is the ground then Z is up.
// Give the camera an altitude of 1 units.  
Camera.Main.Z = 1;

// This keeps the camera oriented so that the up vector is positive Z:
Camera.Main.UpVector = new Vector3(0, 0, 1);

// Place a bunch of Sprites in the world on the XY plane
for (int i = 0; i < 200; i++)
{
    Sprite sprite = SpriteManager.AddSprite("redball.png");
    sprite.X = -50 + 100 * (float)FlatRedBallServices.Random.NextDouble();
    sprite.Y = 100 * (float)FlatRedBallServices.Random.NextDouble();
    
    // Make the Sprite "sit" on the ground
    sprite.Z = sprite.ScaleY;
    
    // Spin the Sprites so that they sit on the XZ plane (facing the camera)
    sprite.RotationX = (float)System.Math.PI / 2.0f;
}

// Set the sort type to distance along forward vector or else Sprites won't
// sort properly.
SpriteManager.OrderedSortType = SortType.DistanceAlongForwardVector;
```

![3DCamera.png](https://951240982-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M_fye9Ufg3vzJxwX5Hk%2Fuploads%2Fgit-blob-5ab60cbee258bdcf36724cc09dff34418e30d95b%2Fmigrated_media-3DCamera.png?alt=media)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.flatredball.com/flatredball/tutorials/code-tutorials/flatredballxna-tutorials-3d-camera-setup.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
