Back to main page

Camera

Vertical field of view is defined as an angle between top and bottom of a planar projection with perspective.

Horizontal field of view is an angle between left and right side.

Orthogonal camera projection is using half width and half height to define a rectangle in distance units.

int Camera_Create(void);

The new ID to the camera.

Creates a new camera with the following default values.

Position = (0,0,0) Where the camera is placed

Target = (1,0,0) A point that the camera will be facing

Up vector = (0,1,0) A vector that helps the camera to know where up is when looking at the target

Orthogonal = false

Vertical field of view = true

Field of view = 45 degrees

Cutting plane = None

Refractive multiplier = 1

OrthogonalHalfWidth = 1

OrthogonalHalfHeight = 1

void Camera_Delete(int Camera);

Camera is a valid camera ID.

Camera is deleted.

void Camera_RenderScene(int InputCamera, int OutputSurface, int ShaderChannel);

InputCamera is a valid camera ID, OutputSurface is a valid draw surface ID refering to a draw surface with a depth buffer, if OutputSurface is used for texture overriding then OutputSurface need an extra color buffer, 0 <= ShaderChannel <= 15 and each visible instance's model have shaders assigned to the channel ShaderChannel.

Render the scene seen from InputCamera to the draw surface refered to by OutputSurface with the set of shaders refered to by ShaderChannel.

void Camera_RenderInstance(int InputCamera, int OutputSurface, int Instance, int MaterialShaderOverride, int FilterIndex, int RenderingMethod, bool UseDepthBuffer, float InstanceColor_Red, float InstanceColor_Green, float InstanceColor_Blue, float InstanceColor_Alpha, int Part);

FilterIndex:

Solid = 0

Alpha filter = 1

RenderingMethod:

Triangles = 0

Wire frame = 1

Double sided triangles = 2

If Part = -1 then render all visible parts.

If Part > -1 then render the part of index Part if it is visible

The instance's visibility is replaced by true but the detail level is still used to hide parts.

Light sources are replaced by (1,1,1) since malfunctioning light would make it look worse and take more performance.

This method was made for the model editor but can also be used for advanced drawing with geometry shaders and the depth buffer.

InputCamera is a valid camera ID, OutputSurface is a valid draw surface ID refering to a draw surface with a depth buffer or UseDepthBuffer is false, OutputSurface may not be used for texture overriding in models, Instance is a valid ID to a visual Instance, MaterialShaderOverride is 0 or the ID of a valid material shader, FilterIndex is the index of a valid filter, RenderingMethod is the index of a valid rendering method, Part is -1 or the index of a part in Instance's model.

Render Instance to OutputSurface seen from InputCamera.

void Camera_SetHorizontalFOV_InRadians(int Camera, float FOV);

Camera is a valid camera ID.

Camera has it's field of view set to FOV in radians and the camera remember that the field of view is defined horizontally.

void Camera_SetVerticalFOV_InRadians(int Camera, float FOV);

Camera is a valid camera ID.

Camera has it's field of view set to FOV in radians and the camera remember that the field of view is defined vertically.

void Camera_SetHorizontalFOV_InDegrees(int Camera, float FOV);

Camera is a valid camera ID.

Camera has it's field of view set to FOV in degrees and the camera remember that the field of view is defined horizontally.

void Camera_SetVerticalFOV_InDegrees(int Camera, float FOV);

Camera is a valid camera ID.

Camera has it's field of view set to FOV in degrees and the camera remember that the field of view is defined vertically.

void Camera_Place(int Camera, float Position_X, float Position_Y, float Position_Z, float Target_X, float Target_Y, float Target_Z, float Up_X, float Up_Y, float Up_Z);

Camera is a valid camera ID.

Camera's position, target and up vector is set by the arguments.

void Camera_GetPosition_OutV3(int Camera);

Camera is a valid camera ID.

Camera's position is written to (X1,Y1,Z1)

void Camera_GetDirection_OutV3(int Camera);

Camera is a valid camera ID.

Camera's direction is written to (X1,Y1,Z1)

void Camera_GetTarget_OutV3(int Camera);

Camera is a valid camera ID.

Camera's target position is written to (X1,Y1,Z1)

void Camera_GetUp_OutV3(int Camera);

Camera is a valid camera ID.

Camera's up vector is written to (X1,Y1,Z1)

float Camera_GetFieldOfViewInRadians(int Camera);

Camera is a valid camera ID.

Returns Camera's angular field of view in radians.

float Camera_GetFieldOfViewInDegrees(int Camera);

Camera is a valid camera ID.

Returns Camera's angular field of view in degrees.

int Camera_IsFieldOfViewVertical(int Camera);

Camera is a valid camera ID.

Returns 1 if the field of view is vertical and 0 if the field of view is horizontal.

void Camera_Get4x4System_OutM4(int Camera);

This axis system is used to convert from orthogonal camera space to world space just like the 4x4 system for instances. Instead of calculating the inverse of the matrix, just transpose using the orthogonal property since this matrix does not include the camera's perspective.

Camera is a valid camera ID.

Writes Camera's X axis to (X1,Y1,Z1), Y axis to (X2,Y2,Z2), Z axis to (X3,Y3,Z3) and position to (X4,Y4,Z4). W1 = 0, W2 = 0, W3 = 0 and W4 = 1 so that the 4x4 matrix can be used for multiplication and other things.

void Camera_GiveCuttingPlane(int Camera, float NX, float NY, float NZ, float D, float RefractiveMultiplier);

This is only used for advanced reflections and refractions.

The cutting plane is defined as (x * NX) + (y * NY) + (z * NZ) = D in world space for arbitrary x,y,z.

It's positive side (visible) is defined as (x * NX) + (y * NY) + (z * NZ) > D.

It's negative side (invisible) is defined as (x * NX) + (y * NY) + (z * NZ) < D.

RefractiveMultiplier is a value that can be used to modify Camera's orthogonal WorldToCamera matrix so that the world seems to be scaled along the cutting plane without affecting the pixel shader's world position. It is done by multiplying the shortest distance to the plane with RefractiveMultiplier. Use 1 as a default value when you don't want refraction.

Camera is a valid camera ID, |(NX,NY,NZ)| = 1 and RefractiveMultiplier > 0.

(NX,NY,NZ) is normalized before used in case of something breaking the precondition.

To place the plane in relation to a position in world space, add the dot product of the position and (NX,NY,NZ) to D.

Assign a cutting plane to the camera and replace any previous so that every pixel not satisfying (x * NX) + (y * NY) + (z * NZ) > D in world space is invisible when the UseCuttingPlane macro is used with the pixel's world space position as it's only argument. The refractive multiplier is stored in the camera as a part of the cutting plane.

void Camera_RemoveCuttingPlane(int Camera);

This is only used for advanced reflections and refractions.

Camera is a valid camera ID.

Any cutting plane in the camera is removed.

int Camera_HasCuttingPlane(int Camera);

This is only used for advanced reflections and refractions.

Camera is a valid camera ID.

Returns 1 if Camera has a cutting plane and 0 otherwise.

void Camera_GetCuttingPlane_OutV4(int Camera);

This is only used for advanced reflections and refractions.

Camera is a valid camera ID.

The camera's last assigned cutting plane (NX,NY,NZ,D) is stored in (X1,Y1,Z1,W1).

float Camera_GetRefractiveMultiplier(int Camera);

This is only used for advanced reflections and refractions.

Camera is a valid camera ID.

Returns Camera's last assigned refractive multiplier.

void Camera_SetOrthogonal(int Camera, bool Orthogonal);

Camera is a valid camera ID.

If Orthogonal is true then the camera will be otrhogonal and use HalfWidth and HalfHeight. If Orthogonal is false then the camera will have perspective and use vertical or horizontal field of view.

int Camera_IsOrthogonal(int Camera);

Camera is a valid camera ID.

Returns 1 if the the projection is orthogonal and 0 if the projection has perspective.

void Camera_SetHalfWidth(int Camera, float HalfWidth);

Camera is a valid camera ID and HalfWidth > 0.

Sets the camera's HalfWidth to HalfWidth.

float Camera_GetHalfWidth(int Camera);

Camera is a valid camera ID.

Returns the camera's HalfWidth.

void Camera_SetHalfHeight(int Camera, float HalfHeight);

Camera is a valid camera ID and HalfHeight > 0.

Sets the camera's HalfHeight to HalfHeight.

float Camera_GetHalfHeight(int Camera);

Camera is a valid camera ID.

Returns the camera's HalfHeight.

void Camera_SetDebugViewVisibility(int Camera, int DebugViewIndex, bool Visible);

This method is used to enable and disable different types of debug drawing for all images rendered with the camera.

Debug views are different things to render on top of the world so that you know what is going on in the engine.

Debug view enumeration:

World center = 0

Used to know where the world center is and where each axis is pointing.

The X axis is red, the Y axis is green and the Z axis is blue.

Rigid bodies = 1

Used to check that rigid bodies and their collision shapes are overlapping with their visual representation.

The X axis is red, the Y axis is green and the Z axis is blue.

Activation state color codes:

Bodies with disabled deactivation are yellow.

Active bodies are green.

Bodies that want to be deactivated are cyan.

Sleeping bodies are blue. This include static bodies.

Bodies with disabled simulation are red.

Showing everything in this debug view might take 10 seconds per frame to render because heightfields can have millions of triangles.

Use Physics_SetDebugDrawRadius to choose how far from the camera you want to debug draw rigid bodies.

Constraints = 2

Used to see physical constraints.

Collisions = 3

Used to see physical collisions as lines.

Instances = 4

Used to check that instances are inside their bounding shapes.

The X axis is red, the Y axis is green and the Z axis is blue.

Camera is a valid camera ID and DebugViewIndex is a valid debug view enumeration.

If Visible is true then enable debug drawing for Index in Camera. If Visible is false then disable debug drawing for Index in Camera.

int Camera_GetDebugViewVisibility(int Camera, int DebugViewIndex);

Camera is a valid camera ID and DebugViewIndex is a valid debug view enumeration (See Camera_SetDebugViewVisibility).

Returns the debug view visibility of DebugViewIndex in Camera.