Class Camera
Namespace: ValveResourceFormat.Renderer
Assembly: Renderer.dll
Perspective camera with view and projection matrix management.
public class CameraInheritance
Constructors
Camera(RendererContext)
Initializes a new camera with a default position and 16:9 viewport.
public Camera(RendererContext rendererContext)Parameters
rendererContext RendererContext
Renderer context used to read field-of-view settings.
Properties
AspectRatio
Viewport width divided by height.
public float AspectRatio { get; }Property Value
CameraViewMatrix
World-to-view transform matrix.
public Matrix4x4 CameraViewMatrix { get; }Property Value
Forward
Unit vector pointing in the camera's look direction.
public Vector3 Forward { get; }Property Value
Location
World-space position of the camera.
public Vector3 Location { get; set; }Property Value
Pitch
Vertical rotation angle in radians.
public float Pitch { get; set; }Property Value
ProjectionMatrix
Perspective projection matrix (reverse-Z, infinite far plane).
public Matrix4x4 ProjectionMatrix { get; }Property Value
Right
Unit vector pointing to the camera's right.
public Vector3 Right { get; }Property Value
Up
Unit vector pointing upward from the camera's perspective.
public Vector3 Up { get; }Property Value
ViewFrustum
Frustum derived from the current view-projection matrix, used for culling.
public Frustum ViewFrustum { get; }Property Value
ViewProjectionMatrix
Combined world-to-clip transform matrix.
public Matrix4x4 ViewProjectionMatrix { get; }Property Value
WindowSize
Current viewport dimensions in pixels.
public Vector2 WindowSize { get; }Property Value
Yaw
Horizontal rotation angle in radians.
public float Yaw { get; set; }Property Value
Methods
ClampRotation()
Clamps to prevent the camera from flipping upside-down.
public void ClampRotation()CopyFrom(Camera)
Copies all transform state from another camera into this one.
public void CopyFrom(Camera fromOther)Parameters
fromOther Camera
The camera to copy from.
CreateProjectionMatrix()
Rebuilds from the current field of view and aspect ratio.
public void CreateProjectionMatrix()FrameObject(Vector3, float, float, float)
Positions the camera so the specified bounding box fills the view.
public void FrameObject(Vector3 objectPosition, float width, float height, float depth)Parameters
objectPosition Vector3
Center of the object to frame.
width float
Width of the object's bounding box.
height float
Height of the object's bounding box.
depth float
Depth of the object's bounding box.
FrameObjectFromAngle(Vector3, float, float, float, float, float)
Positions the camera at the given yaw/pitch angle so the bounding box fills the view.
public void FrameObjectFromAngle(Vector3 objectPosition, float width, float height, float depth, float yaw, float pitch)Parameters
objectPosition Vector3
Center of the object to frame.
width float
Width of the object's bounding box.
height float
Height of the object's bounding box.
depth float
Depth of the object's bounding box.
yaw float
Horizontal angle in radians.
pitch float
Vertical angle in radians.
GetFOV()
Returns the field of view in radians, as read from the renderer context settings.
public float GetFOV()Returns
LookAt(Vector3)
Orients the camera to face the given world-space target.
public void LookAt(Vector3 target)Parameters
target Vector3
RecalculateDirectionVectors()
Recomputes , , and vectors from the current pitch and yaw.
public void RecalculateDirectionVectors()RecalculateMatrices()
Recomputes view, projection, and view-projection matrices from the current location, pitch, and yaw.
public void RecalculateMatrices()SetFromTransformMatrix(Matrix4x4)
Sets the camera position and orientation from a transform matrix.
public void SetFromTransformMatrix(Matrix4x4 matrix)Parameters
matrix Matrix4x4
Transform matrix whose translation and first row determine position and direction.
SetLocation(Vector3)
Sets without recalculating matrices.
public void SetLocation(Vector3 location)Parameters
location Vector3
SetLocationPitchYaw(Vector3, float, float)
Sets , , and without recalculating matrices.
public void SetLocationPitchYaw(Vector3 location, float pitch, float yaw)Parameters
location Vector3
pitch float
yaw float
SetViewConstants(ViewConstants)
Writes camera matrices and direction vectors into the provided view constants struct.
public void SetViewConstants(ViewConstants viewConstants)Parameters
viewConstants ViewConstants
View constants struct to populate.
SetViewportSize(int, int)
Updates the viewport dimensions and rebuilds the projection matrix.
public void SetViewportSize(int viewportWidth, int viewportHeight)Parameters
viewportWidth int
viewportHeight int

