Terminology

Camera Elements

CamCoords:

An array holding 3 decimal numbers. These are the coordinates of the center of the camera within the 3D space (X, Y and Z coordinates).

CamRO:

This is the horizontal rotation orientation of the camera. It tracks how much the camera has rotated horizontally away from its identity position. Measured in radians.

A rightwards turn increments it and a leftwards turn decrements it.

CamROVert:

This is the vertical rotation orientation of the camera. To do with pitch ups and pitch downs. An upwards turn increments it and a downwards turn decrements it.

CamScreenDV:

The Camera Screen Displacement Vector. This is a two dimensional vector that exists within the realm of the camera screen. It's important to think of the camera sceen as being a virtual graph of its own that exists within the 3D environment. That way when things in the 3D environment move, you can track where their positions will be on the graph and how camera movements will affect these projections.

For instance: If the camera is facing an object, and then the camera turns rightwards. There will be a rotation transformation applied to all the points in the 3D space in the inverse direction (leftwards). However the more prominent change here would be that from the camera's point of view, the objects will appear to shift to the left of the screen. This is a displacement. When all the points/vectors in the 3D environment are rendered from the camera's point of view, you will have to take into account this displacement. How much the points have displaced and in what direction. This will affect the starting position and ending position of all vectors.

The CamScreenDV has a X value (which is affected by horizontal camera rotations) and a Y value (which is affected by vertical camera rotations)

CamWidth:

The width of the camera. Represent by an integer. The unit values are universal in my program. 1 Unit value is 1 square on the grid in all views. A width of 4 means that the camera's width is 4 squares long on the X axis and the center of the camera screen would be after the first 2 squares

CamHeight:

The height of the camera. Represented by an integer. A height of 4 means that the camera is 4 squares long on the Y axis and the center is is after first 2 squares.

CamHats:

These are the camera's local unit vectors. CamI^, CamJ^ and CamK^. These unit vectors change as the camera moves and rotates. Which is what drives the transformation of all vectors from the camera's point of view as they get oriented with the camera's local unit vectors.

CamXPlane

This is the plane that exists in 3D space if the cam had a CamRO of 0 in its current position. Important to note that this plane is dynamic. It moves with the camera and is not fixed in one point. It's just its angle that never changes.

CamXPlaneToOriginAngle:

This is an angle that gets created between the camera's center and the origin point of the world (0, 0, 0). The angle exists on the XZ plane. To consider the angle, we have to consider the camera (in its current position) to have a CamRO of 0. Then on the top view (XZ plane) draw a line from the camera's center to the origin (0, 0, 0). The angle that this line makes with the camera screen (which is now parallel with the X axis since the CamRO is 0) is what this variable is. This comes in handy when calculating various values like the CamScreenDV.

World Elements

WorldHats:

The I^, K^ and K^ unit vectors of the world space. These are constant in the world and do not change with camera transformations.

Points within the 3D space are oriented to these unit vectors and are projected onto the CamHats.

TrianglesArr:

A three dimensional array. Going deep into the array from the outset:
Level 2: Each sub array is a triangle.
Level 1: Each triangle is an array of 3 points.
Level 0: Each point is an array of 3 decimal numbers that represnt its X, Y and Z coordinate.

Ultimately these are the points which are visualized in the 3D space. The points are organized into triangles since that is the simplest shape that can be drawn on a flat plane. A collection of triangles can be organized to form a 3D shape.

Functions

CalculateCamScreenDV()

Purpose: To update the camScreenDV (Cam Screen Displacement Vector). It calculates this using the current camRO (Camera Rotation Orientation) and the camCoords (The camera’s X, Y and Z coordinates).

It's ultimate goal is to find the length of the line segment below highlighted with a red squiggly line.

There exists a point on the camera where the normals vector from the origin [0,0,0] hits the camera screen. This vector is always perpendicular to the camera screen (hence its called the normals) The red squiggly line represents the distance between the center of the camera screen and the point where this normals vector lands.

In diagram 1.1 below, we can get the length of the red squiggly line (the CamScreenDV) by finding Angle B and DistToOrigin (Distance from the camera to the origin[0,0,0]).
Cos(Angle B) = CamScreenDV / DistToOrigin.
Therefore CamScreenDV = Cos(Angle B) * DistToOrigin

Finding DistToOrigin is easy but finding Angle B is slightly more complicated

Process:

Step 1: Calculate Distance from Camera To Origin[0,0,0]

Use the Pythagorean theorem to find the distance from the camera to the origin[0,0,0]. The camera's coordinates will tell you how much the camera has displaced from the origin on each axis. Eg: If the camCoords are [-4, 0, -2], this means it has displaced -4 on the X-axis and -2 on the Z-axis. So the vector that both of these individual displacements have created is the distance from the camera to the origin. And we get that by calculating: ((X-Displacement)2 + (Y-Displacement)2)

Note: Remember to keep in mind that since you're looking at things from the top view, the local Y-axis of the top view corresponds to the Z-axis of the actual 3D space.

Step 2: Calculate Angle Between CamXPlane and the DistToOrigin Vector

We now have the DistToOrigin vector. In order to eventually get Angle B, we can use the following approach. Notice the angle drawn in dark blue. This is the angle between CamXPlane and the current position of the camera (rotation orientation wise). This angle is clearly CamRO. It would be non existant if the CamRO was 0 since the cam would be parallel with the CamXPlane. It's directly proportional to the CamRO.

Now look at the angle drawn in light blue (Which we'll call Angle T). This is the angle between the CamXPlane and the DistToOrigin vector. If we can find this angle, then we simply have to substract CamRO from it and then we get Angle B.

Angle T forms a non-right angled triangle. So we can't use SOH CAH TOA. We'll have to get creative.

Let's revisit the displacement of the camera from the origin[0,0,0]. Dissect the displacement for each axis. Pretend you're holding a pen which is on the origin[0,0,0]. Now slide the pen left or right to track the X-Axis displacement of the cam. Then slide the pen up or down to track the Z-Axis displacement. Once you're done, STOP. The pen is now on the camera. If you draw a line straight to the origin, you'll get the DistToOrigin vector. But notice how we now have a right angled triangle? (The X-axis displacement, Z-axis displacement and the DistToOrigin vector). Within that triangle we now have an Angle X. We can easily find that out with Tan inverse. Tan(Angle X) = (X-Axis Displacement) / (Z-Axis Displacement).

Now notice how the angle between CamXPlane and the start of Angle X is 90 degrees? The start of Angle X represents the Z-Axis line. Which means if we add 90 degrees (which is PI/2 in radians) to Angle X, we can finally get Angle T.

Step 3: Get Angle B

Now to get Angle B, we just have to subtract CamRO from Angle T. And then we get the DV with the equation we discussed in the beginning. CamScreenDV = Cos(Angle B) * DistToOrigin;

High Level Overview Diagram Of Program