scimesh 0.3.2
Headless CPU-only 3D software renderer for scientific mesh visualization
Loading...
Searching...
No Matches
scimesh::Camera Struct Reference

A virtual camera that defines the viewpoint for rendering. More...

#include <camera.h>

Public Member Functions

Mat4 get_view_matrix () const
 Compute the view matrix (world → camera space).
 
Mat4 get_projection_matrix (float aspect_ratio, float near_plane, float far_plane) const
 Compute the projection matrix (camera → clip space).
 

Public Attributes

Vec3 eye = Vec3(0.0f, 0.0f, 10.0f)
 Camera position in world space.
 
Vec3 center = Vec3(0.0f, 0.0f, 0.0f)
 The point the camera looks at.
 
Vec3 up = Vec3(0.0f, 1.0f, 0.0f)
 The camera's "up" direction.
 
ProjectionType projection = ProjectionType::PERSPECTIVE
 Which projection type to use.
 
float fov_degrees = 45.0f
 Vertical field of view in degrees (perspective only).
 

Detailed Description

A virtual camera that defines the viewpoint for rendering.

How a camera works

A camera is defined by three things:

  • Position (eye): where the camera sits in 3D space.
  • Look-at point (center): what the camera is pointing at.
  • Up direction (up): which way is "up" on screen (usually +Y).

Together these define a view matrix that transforms world coordinates into camera coordinates.

The projection matrix (orthographic or perspective) then maps camera coordinates to clip space, which the rasterizer converts to screen pixels.

Construction

You rarely need to set all fields manually. Use one of the convenience functions:

// Fit a single mesh in view automatically
Camera cam = camera_fit_mesh(mesh, {0, 0, 1}, {0, 1, 0}, 45.0f);
// Manual setup
Camera cam;
cam.eye = {5, 3, 10}; // camera position
cam.center = {0, 0, 0}; // look at origin
cam.up = {0, 1, 0}; // Y is up
cam.fov_degrees = 45.0f; // 45° field of view
cam.projection = ProjectionType::PERSPECTIVE;
Camera camera_fit_mesh(const Mesh &mesh, const Vec3 &direction, const Vec3 &up, float fov_degrees, float margin, ProjectionType projection)
Create a camera that automatically frames a single Mesh.
Definition camera.cpp:75
@ PERSPECTIVE
Perspective projection: objects farther away appear smaller.
A virtual camera that defines the viewpoint for rendering.
Definition camera.h:77
Vec3 eye
Camera position in world space.
Definition camera.h:82
See also
camera_look_at(), camera_fit_mesh(), camera_fit_scene()
camera_orbit(), ProjectionType

Definition at line 77 of file camera.h.

Member Function Documentation

◆ get_projection_matrix()

Mat4 scimesh::Camera::get_projection_matrix ( float  aspect_ratio,
float  near_plane,
float  far_plane 
) const

Compute the projection matrix (camera → clip space).

Parameters
aspect_ratioImage width / height (e.g., 800/600 = 1.333).
near_planeDistance to the near clipping plane.
far_planeDistance to the far clipping plane.
Returns
A 4×4 projection matrix.

Definition at line 13 of file camera.cpp.

◆ get_view_matrix()

Mat4 scimesh::Camera::get_view_matrix ( ) const

Compute the view matrix (world → camera space).

This is a standard look-at matrix. You typically don't need to call this yourself — the renderer does it internally.

Returns
A 4×4 view matrix.

Definition at line 9 of file camera.cpp.

Member Data Documentation

◆ center

Vec3 scimesh::Camera::center = Vec3(0.0f, 0.0f, 0.0f)

The point the camera looks at.

Together with eye, this defines the view direction as center - eye. Default: the origin (0, 0, 0).

Definition at line 88 of file camera.h.

◆ eye

Vec3 scimesh::Camera::eye = Vec3(0.0f, 0.0f, 10.0f)

Camera position in world space.

Where the "eye" sits. Default: (0, 0, 10), looking toward the origin from 10 units away on the +Z axis.

Definition at line 82 of file camera.h.

◆ fov_degrees

float scimesh::Camera::fov_degrees = 45.0f

Vertical field of view in degrees (perspective only).

Controls how wide the lens is. Typical values:

  • 30° — telephoto (narrow, zoomed in)
  • 45° — normal (default)
  • 60°–90° — wide angle

Ignored when projection == ORTHOGRAPHIC.

Definition at line 109 of file camera.h.

◆ projection

ProjectionType scimesh::Camera::projection = ProjectionType::PERSPECTIVE

Which projection type to use.

See also
ProjectionType

Definition at line 99 of file camera.h.

◆ up

Vec3 scimesh::Camera::up = Vec3(0.0f, 1.0f, 0.0f)

The camera's "up" direction.

Usually (0, 1, 0) for Y-up scenes. Must not be parallel to the view direction (center - eye).

Definition at line 94 of file camera.h.


The documentation for this struct was generated from the following files: