MXVK Vulkan Framework 0.24.0
C++20 Vulkan rendering framework for practical 2D and 3D application development with SDL3.
Loading...
Searching...
No Matches
mxvk_math.h File Reference

Math, geometry, rasterization, and simple software 3D pipeline helpers for MXVK examples. More...

#include "mxvk_math_obj.hpp"
#include "mxvk_sprite.hpp"
#include <SDL3/SDL.h>
#include <algorithm>
#include <array>
#include <cmath>
#include <cstdint>
#include <cstdlib>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <span>
#include <sstream>
#include <stdexcept>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>

Go to the source code of this file.

Classes

class  mxvk::Camera
 Camera and projection data for the simple software 3D pipeline. More...
struct  mxvk::CyType
 Cylindrical coordinate. More...
class  mxvk::Mat1D
 Two-element column-vector storage used by 2x2 linear solves. More...
class  mxvk::Mat1x3D
 Three-element column-vector storage used by 3x3 linear solves. More...
class  mxvk::Mat1x4D
 Four-element column-vector storage. More...
class  mxvk::Mat2D
 Two-by-two matrix with arithmetic, determinant, inverse, and solve helpers. More...
class  mxvk::Mat3D
 Three-by-three matrix with multiplication, vector transform, inverse, and solve helpers. More...
class  mxvk::Mat4D
 Four-by-four homogeneous transform matrix. More...
class  mxvk::Mat4x3D
 Four-by-three matrix storage. More...
class  mxvk::mxObject
 Simple mesh object loaded from PLG-style indexed triangle data. More...
struct  mxvk::paramLine2D
 Parametric 2D line segment represented by a start point, end point, and direction. More...
struct  mxvk::paramLine3D
 Parametric 3D line segment represented by a start point, end point, and direction. More...
class  mxvk::PipeLine
 Clipped software rasterization pipeline for lines and filled triangles. More...
struct  mxvk::Plane3D
 Plane represented by a point and a normal vector. More...
struct  mxvk::Polar
 2D polar coordinate. More...
class  mxvk::QuatType
 Quaternion used for 3D rotations. More...
class  mxvk::RenderList
 Flat list of triangles prepared for transformation and rasterization. More...
struct  mxvk::SDLRendererPixelPlotter
 Pixel plotter adapter that writes packed MXVK colors to an SDL renderer. More...
struct  mxvk::SpType
 Spherical coordinate. More...
struct  mxvk::Triangle
 Triangle primitive used by the simple software rendering pipeline. More...
class  mxvk::vec2D
 Two-dimensional float vector with common arithmetic helpers. More...
class  mxvk::vec3D
 Three-dimensional float vector with arithmetic, dot, and cross-product helpers. More...
class  mxvk::vec4D
 Four-dimensional float vector used for homogeneous 3D coordinates. More...
struct  mxvk::VKSpritePixelPlotter
 Pixel plotter adapter that draws square pixels into a VK_Sprite. More...

Namespaces

namespace  mxvk
 Utilities for loading and saving PNG images.

Typedefs

using mxvk::MXCOLOR = std::uint32_t
 Packed 32-bit color in ARGB byte order.

Enumerations

enum  { mxvk::MX_ACTIVE = 0x1 , mxvk::MX_VISIBLE = 0x2 , mxvk::MX_BACKFACE = 0x4 , mxvk::MX_CULLED = 0x8 }
 Object and polygon state bit flags. More...

Functions

std::array< float, 361 > mxvk::build_cos_table ()
std::array< float, 361 > mxvk::build_sin_table ()
void mxvk::BuildTables ()
 Rebuild the sine and cosine lookup tables.
constexpr std::uint8_t mxvk::color_a (MXCOLOR color)
 Extract the alpha component from a packed ARGB color.
constexpr std::uint8_t mxvk::color_b (MXCOLOR color)
 Extract the blue component from a packed ARGB color.
constexpr std::uint8_t mxvk::color_g (MXCOLOR color)
 Extract the green component from a packed ARGB color.
constexpr std::uint8_t mxvk::color_r (MXCOLOR color)
 Extract the red component from a packed ARGB color.
float mxvk::deg2rad (float ang)
 Convert degrees to radians.
template<typename PlotPixel>
void mxvk::draw_filled_triangle (const vec2D &p0, const vec2D &p1, const vec2D &p2, MXCOLOR color, PlotPixel &&plot_pixel)
 Rasterize a filled triangle by testing pixels against edge functions.
void mxvk::draw_filled_triangle (SDL_Renderer *renderer, const vec2D &p0, const vec2D &p1, const vec2D &p2, MXCOLOR color)
 Draw a filled triangle directly to an SDL renderer.
void mxvk::draw_filled_triangle (VK_Sprite &sprite, const vec2D &p0, const vec2D &p1, const vec2D &p2, MXCOLOR color, int pixel_size=1)
 Draw a filled triangle directly to a VK_Sprite with optional square pixel size.
template<typename DrawSpan>
void mxvk::draw_filled_triangle_spans (vec2D p0, vec2D p1, vec2D p2, MXCOLOR color, DrawSpan &&draw_span)
template<typename DrawSpan>
void mxvk::draw_filled_triangle_spans_clipped (vec2D p0, vec2D p1, vec2D p2, int clip_min_y, int clip_max_y, MXCOLOR color, DrawSpan &&draw_span)
 Rasterize a filled triangle as horizontal spans.
template<typename PlotPixel>
void mxvk::draw_line (int x0, int y0, int x1, int y1, MXCOLOR color, PlotPixel &&plot_pixel)
 Draw a line with Bresenham-style integer stepping.
void mxvk::draw_line (SDL_Renderer *renderer, int x0, int y0, int x1, int y1, MXCOLOR color)
 Draw a line directly to an SDL renderer.
void mxvk::draw_line (VK_Sprite &sprite, int x0, int y0, int x1, int y1, MXCOLOR color, int pixel_size=1)
 Draw a line directly to a VK_Sprite with optional square pixel size.
float mxvk::edge_function (const vec2D &a, const vec2D &b, const vec2D &p)
 Compute the signed edge function value for point p relative to edge a-b.
float mxvk::fast_cosf (float theta_degrees)
 Approximate cosine using the degree lookup table with linear interpolation.
float mxvk::fast_sinf (float theta_degrees)
 Approximate sine using the degree lookup table with linear interpolation.
constexpr MXCOLOR mxvk::MXVK_RGB (int r, int g, int b)
 Build an opaque ARGB color from red, green, and blue components.
std::ostream & mxvk::operator<< (std::ostream &out, const vec2D &v)
 Write a 2D vector to a stream using vec2D::Print().
std::ostream & mxvk::operator<< (std::ostream &out, const vec3D &v)
 Write a 3D vector to a stream using vec3D::Print().
std::ostream & mxvk::operator<< (std::ostream &out, const vec4D &v)
 Write a 4D vector to a stream using vec4D::Print().
std::istream & mxvk::operator>> (std::istream &in, vec2D &v)
 Read a 2D vector from a stream as two scalar coordinates.
std::istream & mxvk::operator>> (std::istream &in, vec3D &v)
 Read a 3D vector from a stream as three scalar coordinates.
std::istream & mxvk::operator>> (std::istream &in, vec4D &v)
 Read a 4D vector from a stream as four scalar coordinates.
float mxvk::rad2deg (float rad)
 Convert radians to degrees.
int mxvk::rrand (int x, int y)
 Return a pseudo-random integer in the inclusive range between two bounds.
MXCOLOR mxvk::shade_color (MXCOLOR color, float intensity)
 Scale the RGB channels of a color while preserving alpha.

Variables

std::array< float, 361 > mxvk::cos_look = build_cos_table()
 Cosine lookup table with one entry per degree from 0 through 360.
constexpr float mxvk::EPSILON = 1.0e-5f
 Default tolerance used for floating-point singularity and zero-length checks.
constexpr float mxvk::PI = 3.14159265358979323846f
 Mathematical constant pi as a single-precision value.
std::array< float, 361 > mxvk::sin_look = build_sin_table()
 Sine lookup table with one entry per degree from 0 through 360.

Detailed Description

Math, geometry, rasterization, and simple software 3D pipeline helpers for MXVK examples.

Definition in file mxvk_math.h.