150 const Vec3 ¢er,
const Vec3 &dir,
151 float fov_radians,
float *out_dist =
nullptr) {
153 Vec3(bmin.x, bmin.y, bmin.z),
Vec3(bmax.x, bmin.y, bmin.z),
154 Vec3(bmin.x, bmax.y, bmin.z),
Vec3(bmax.x, bmax.y, bmin.z),
155 Vec3(bmin.x, bmin.y, bmax.z),
Vec3(bmax.x, bmin.y, bmax.z),
156 Vec3(bmin.x, bmax.y, bmax.z),
Vec3(bmax.x, bmax.y, bmax.z),
158 float max_dist = 0.0f;
159 float half_tan = std::tan(fov_radians * 0.5f);
160 if (half_tan < 1e-6f) half_tan = 1e-6f;
162 for (
int i = 0; i < 8; i++) {
163 Vec3 delta = corners[i] - center;
164 float along = glm::dot(delta, dir);
165 float perp_sq = glm::dot(delta, delta) - along * along;
166 float perp = std::sqrt(perp_sq);
171 float d = perp / half_tan + along;
172 if (d > max_dist) max_dist = d;
174 if (max_dist < 1e-6f) max_dist = 1.0f;
176 if (out_dist) *out_dist = max_dist;
178 float sin_half = std::sin(fov_radians * 0.5f);
179 if (sin_half < 1e-6f) sin_half = 1e-6f;
180 return max_dist * sin_half;
197 const Vec3 ¢er,
const Vec3 &dir) {
199 Vec3(bmin.x, bmin.y, bmin.z),
Vec3(bmax.x, bmin.y, bmin.z),
200 Vec3(bmin.x, bmax.y, bmin.z),
Vec3(bmax.x, bmax.y, bmin.z),
201 Vec3(bmin.x, bmin.y, bmax.z),
Vec3(bmax.x, bmin.y, bmax.z),
202 Vec3(bmin.x, bmax.y, bmax.z),
Vec3(bmax.x, bmax.y, bmax.z),
204 float max_perp = 0.0f;
205 for (
int i = 0; i < 8; i++) {
206 Vec3 delta = corners[i] - center;
207 float along = glm::dot(delta, dir);
208 float perp = std::sqrt(std::max(0.0f, glm::dot(delta, delta) - along * along));
209 if (perp > max_perp) max_perp = perp;
211 if (max_perp < 1e-6f) max_perp = 1.0f;
239 const Vec3 &direction,
const Vec3 &up,
240 float fov_degrees,
float margin = 1.1f,
267 const Vec3 &up,
float fov_degrees,
float margin = 1.1f,
291 const Vec3 &up,
float fov_degrees,
float margin = 1.1f,
312Camera
camera_orbit(
const Camera &camera,
const Vec3 &axis,
float angle_degrees);
Camera camera_look_at(const Vec3 ¢er, float radius, const Vec3 &direction, const Vec3 &up, float fov_degrees, float margin, ProjectionType projection)
Create a camera that looks at a point from a given distance and direction.
glm::mat4 Mat4
4×4 floating-point matrix.
glm::vec3 Vec3
3-component floating-point vector (xyz).
Camera camera_fit_scene(const Scene &scene, const Vec3 &direction, const Vec3 &up, float fov_degrees, float margin, ProjectionType projection)
Create a camera that automatically frames an entire Scene.
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.
ProjectionType
The type of 3D→2D projection used by the camera.
@ ORTHOGRAPHIC
Orthographic projection: parallel lines stay parallel.
@ PERSPECTIVE
Perspective projection: objects farther away appear smaller.
float perp_extent_radius(const Vec3 &bmin, const Vec3 &bmax, const Vec3 ¢er, const Vec3 &dir, float fov_radians, float *out_dist=nullptr)
Compute the "perpendicular extent radius" of an axis-aligned bounding box relative to a view directio...
float max_ortho_extent(const Vec3 &bmin, const Vec3 &bmax, const Vec3 ¢er, const Vec3 &dir)
Compute the maximum perpendicular extent of an AABB from a view ray (for orthographic projection fram...
Camera camera_orbit(const Camera &camera, const Vec3 &axis, float angle_degrees)
Orbit the camera around its look-at point.
The Scene — a collection of meshes rendered together.
A virtual camera that defines the viewpoint for rendering.
Mat4 get_view_matrix() const
Compute the view matrix (world → camera space).
ProjectionType projection
Which projection type to use.
Vec3 center
The point the camera looks at.
Vec3 up
The camera's "up" direction.
Vec3 eye
Camera position in world space.
float fov_degrees
Vertical field of view in degrees (perspective only).
Mat4 get_projection_matrix(float aspect_ratio, float near_plane, float far_plane) const
Compute the projection matrix (camera → clip space).
Fundamental types used throughout the scimesh rendering engine.