TinyGPU
Loading...
Searching...
No Matches
Classes | Public Member Functions | Static Public Member Functions | Protected Types | Protected Member Functions | Static Protected Member Functions | Protected Attributes | List of all members
WireFrame3D< RGB_T > Class Template Reference

Lightweight 3D wireframe renderer for TinyGPU drawing targets. More...

#include <WireFrame3D.h>

Collaboration diagram for WireFrame3D< RGB_T >:
Collaboration graph
[legend]

Classes

struct  Camera
 Stores camera parameters for view transformation. More...
 
struct  Edge
 Represents an edge between two mesh vertices. More...
 
struct  Mat4
 Represents a 4x4 transformation matrix. More...
 
struct  Mesh
 Represents a wireframe mesh. More...
 
struct  ProjectedPoint
 Represents a projected vertex on screen. More...
 
struct  Vec3
 Represents a 3D point or vector. More...
 
struct  Vec4
 Represents a homogeneous 4D vector. More...
 

Public Member Functions

 WireFrame3D ()
 Creates an empty wireframe renderer.
 
 WireFrame3D (size_t viewportWidth, size_t viewportHeight)
 Creates a wireframe renderer with the specified viewport size.
 
 WireFrame3D (ISurface< RGB_T > &surface)
 Creates a wireframe renderer with the dimensions of the given surface.
 
void setViewport (size_t viewportWidth, size_t viewportHeight)
 Sets the viewport size used for projection and depth buffering.
 
bool begin ()
 
size_t viewportWidth () const
 Returns the current viewport width.
 
size_t viewportHeight () const
 Returns the current viewport height.
 
void setCamera (const Camera &camera)
 Sets the active camera.
 
const Cameracamera () const
 Returns the active camera.
 
void setPerspective (float fovYDegrees, float nearPlane=0.1f, float farPlane=100.0f)
 Sets a perspective projection using the current viewport aspect ratio.
 
void setOrthographic (float left, float right, float bottom, float top, float nearPlane=0.1f, float farPlane=100.0f)
 Sets an orthographic projection volume.
 
const Mat4viewMatrix () const
 Returns the current view matrix.
 
const Mat4projectionMatrix () const
 Returns the current projection matrix.
 
void clearDepthBuffer ()
 Clears the internal depth buffer.
 
bool projectPoint (const Vec3 &point, int16_t &screenX, int16_t &screenY, float &depth, const Mat4 &model=Mat4::identity()) const
 Projects a world-space point into screen space.
 
void renderWireframe (ISurface< RGB_T > &target, const Mesh &mesh, const Mat4 &model=Mat4::identity(), RGB_T color=RGB_T(255, 255, 255), bool clearDepth=true)
 Renders a wireframe mesh with minimal depth buffering.
 

Static Public Member Functions

static Vec3 transformPoint (const Mat4 &matrix, const Vec3 &point)
 Transforms a point by a matrix and divides by w when possible.
 
static Mat4 translation (float x, float y, float z)
 Creates a translation matrix.
 
static Mat4 scaling (float x, float y, float z)
 Creates a scale matrix.
 
static Mat4 rotationX (float radians)
 Creates a rotation matrix around the X axis.
 
static Mat4 rotationY (float radians)
 Creates a rotation matrix around the Y axis.
 
static Mat4 rotationZ (float radians)
 Creates a rotation matrix around the Z axis.
 
static Mesh cube (float size=1.0f)
 Creates a wireframe cube centered at the origin.
 
static Mesh axis (float length=1.0f)
 Creates RGB-style axis lines centered at the origin.
 
static Mesh grid (size_t subdivisions=10, float spacing=1.0f)
 Creates a wireframe grid on the XZ plane.
 
static Mesh sphere (float radius=1.0f, size_t latitudeSteps=8, size_t longitudeSteps=12)
 Creates a wireframe sphere centered at the origin.
 
static Mat4 lookAt (const Vec3 &eye, const Vec3 &target, const Vec3 &up)
 Creates a view matrix from camera parameters.
 

Protected Types

enum class  ProjectionMode { Perspective , Orthographic }
 

Protected Member Functions

void updateViewMatrix ()
 
void updateProjectionMatrix ()
 
float currentAspectRatio () const
 
bool resizeDepthBuffer ()
 
bool clipPointToCameraRange (const Vec3 &point) const
 
bool clipLineToCameraRange (Vec3 &start, Vec3 &end) const
 
bool projectViewPoint (const Vec3 &viewPoint, ProjectedPoint &projected) const
 
void drawDepthLine (ISurface< RGB_T > &target, const ProjectedPoint &start, const ProjectedPoint &end, RGB_T color)
 
void plotDepthPixel (ISurface< RGB_T > &target, int x, int y, float depth, RGB_T color)
 

Static Protected Member Functions

static float dot (const Vec3 &first, const Vec3 &second)
 
static Vec3 cross (const Vec3 &first, const Vec3 &second)
 
static float length (const Vec3 &vector)
 
static Vec3 normalize (const Vec3 &vector)
 
static Vec3 transformAffine (const Mat4 &matrix, const Vec3 &point)
 
static Mat4 createPerspectiveMatrix (float fovYDegrees, float aspect, float nearPlane, float farPlane)
 
static Mat4 createOrthographicMatrix (float left, float right, float bottom, float top, float nearPlane, float farPlane)
 
static bool clipLineToPlane (Vec3 &start, Vec3 &end, float planeZ, bool keepLessEqual)
 

Protected Attributes

size_t viewportWidth_ = 0
 
size_t viewportHeight_ = 0
 
Camera camera_
 
Mat4 viewMatrix_ = Mat4::identity()
 
Mat4 projectionMatrix_ = Mat4::identity()
 
ProjectionMode projectionMode_ = ProjectionMode::Perspective
 
float perspectiveFovYDegrees_ = 60.0f
 
float orthographicLeft_ = -1.0f
 
float orthographicRight_ = 1.0f
 
float orthographicBottom_ = -1.0f
 
float orthographicTop_ = 1.0f
 
Vector< float > depthBuffer_
 

Detailed Description

template<typename RGB_T = RGB565>
class tinygpu::WireFrame3D< RGB_T >

Lightweight 3D wireframe renderer for TinyGPU drawing targets.

WireFrame3D implements a compact CPU-side 3D pipeline intended for embedded and Arduino-style environments where a full 3D engine would be excessive. It stores no scene graph of its own; instead, it provides the math and rendering steps needed to transform user-supplied mesh data into 2D line output on any ISurface-compatible surface.

The class covers the main stages of a simple wireframe renderer:

Meshes are represented as vertices plus edge lists, which keeps memory usage predictable and makes the class suitable for simple geometry such as cubes, spheres, axes, grids, and custom debug or UI visualizations.

Member Enumeration Documentation

◆ ProjectionMode

enum class ProjectionMode
strongprotected
Enumerator
Perspective 
Orthographic 

Constructor & Destructor Documentation

◆ WireFrame3D() [1/3]

WireFrame3D ( )
inline

Creates an empty wireframe renderer.

◆ WireFrame3D() [2/3]

WireFrame3D ( size_t  viewportWidth,
size_t  viewportHeight 
)
inline

Creates a wireframe renderer with the specified viewport size.

◆ WireFrame3D() [3/3]

WireFrame3D ( ISurface< RGB_T > &  surface)
inline

Creates a wireframe renderer with the dimensions of the given surface.

Member Function Documentation

◆ axis()

static Mesh axis ( float  length = 1.0f)
inlinestatic

Creates RGB-style axis lines centered at the origin.

◆ begin()

bool begin ( )
inline

◆ camera()

const Camera & camera ( ) const
inline

Returns the active camera.

◆ clearDepthBuffer()

void clearDepthBuffer ( )
inline

Clears the internal depth buffer.

◆ clipLineToCameraRange()

bool clipLineToCameraRange ( Vec3 start,
Vec3 end 
) const
inlineprotected

◆ clipLineToPlane()

static bool clipLineToPlane ( Vec3 start,
Vec3 end,
float  planeZ,
bool  keepLessEqual 
)
inlinestaticprotected

◆ clipPointToCameraRange()

bool clipPointToCameraRange ( const Vec3 point) const
inlineprotected

◆ createOrthographicMatrix()

static Mat4 createOrthographicMatrix ( float  left,
float  right,
float  bottom,
float  top,
float  nearPlane,
float  farPlane 
)
inlinestaticprotected

◆ createPerspectiveMatrix()

static Mat4 createPerspectiveMatrix ( float  fovYDegrees,
float  aspect,
float  nearPlane,
float  farPlane 
)
inlinestaticprotected

◆ cross()

static Vec3 cross ( const Vec3 first,
const Vec3 second 
)
inlinestaticprotected

◆ cube()

static Mesh cube ( float  size = 1.0f)
inlinestatic

Creates a wireframe cube centered at the origin.

◆ currentAspectRatio()

float currentAspectRatio ( ) const
inlineprotected

◆ dot()

static float dot ( const Vec3 first,
const Vec3 second 
)
inlinestaticprotected

◆ drawDepthLine()

void drawDepthLine ( ISurface< RGB_T > &  target,
const ProjectedPoint start,
const ProjectedPoint end,
RGB_T  color 
)
inlineprotected

◆ grid()

static Mesh grid ( size_t  subdivisions = 10,
float  spacing = 1.0f 
)
inlinestatic

Creates a wireframe grid on the XZ plane.

◆ length()

static float length ( const Vec3 vector)
inlinestaticprotected

◆ lookAt()

static Mat4 lookAt ( const Vec3 eye,
const Vec3 target,
const Vec3 up 
)
inlinestatic

Creates a view matrix from camera parameters.

◆ normalize()

static Vec3 normalize ( const Vec3 vector)
inlinestaticprotected

◆ plotDepthPixel()

void plotDepthPixel ( ISurface< RGB_T > &  target,
int  x,
int  y,
float  depth,
RGB_T  color 
)
inlineprotected

◆ projectionMatrix()

const Mat4 & projectionMatrix ( ) const
inline

Returns the current projection matrix.

◆ projectPoint()

bool projectPoint ( const Vec3 point,
int16_t &  screenX,
int16_t &  screenY,
float &  depth,
const Mat4 model = Mat4::identity() 
) const
inline

Projects a world-space point into screen space.

◆ projectViewPoint()

bool projectViewPoint ( const Vec3 viewPoint,
ProjectedPoint projected 
) const
inlineprotected

◆ renderWireframe()

void renderWireframe ( ISurface< RGB_T > &  target,
const Mesh mesh,
const Mat4 model = Mat4::identity(),
RGB_T  color = RGB_T(255, 255, 255),
bool  clearDepth = true 
)
inline

Renders a wireframe mesh with minimal depth buffering.

◆ resizeDepthBuffer()

bool resizeDepthBuffer ( )
inlineprotected

◆ rotationX()

static Mat4 rotationX ( float  radians)
inlinestatic

Creates a rotation matrix around the X axis.

◆ rotationY()

static Mat4 rotationY ( float  radians)
inlinestatic

Creates a rotation matrix around the Y axis.

◆ rotationZ()

static Mat4 rotationZ ( float  radians)
inlinestatic

Creates a rotation matrix around the Z axis.

◆ scaling()

static Mat4 scaling ( float  x,
float  y,
float  z 
)
inlinestatic

Creates a scale matrix.

◆ setCamera()

void setCamera ( const Camera camera)
inline

Sets the active camera.

◆ setOrthographic()

void setOrthographic ( float  left,
float  right,
float  bottom,
float  top,
float  nearPlane = 0.1f,
float  farPlane = 100.0f 
)
inline

Sets an orthographic projection volume.

◆ setPerspective()

void setPerspective ( float  fovYDegrees,
float  nearPlane = 0.1f,
float  farPlane = 100.0f 
)
inline

Sets a perspective projection using the current viewport aspect ratio.

◆ setViewport()

void setViewport ( size_t  viewportWidth,
size_t  viewportHeight 
)
inline

Sets the viewport size used for projection and depth buffering.

◆ sphere()

static Mesh sphere ( float  radius = 1.0f,
size_t  latitudeSteps = 8,
size_t  longitudeSteps = 12 
)
inlinestatic

Creates a wireframe sphere centered at the origin.

◆ transformAffine()

static Vec3 transformAffine ( const Mat4 matrix,
const Vec3 point 
)
inlinestaticprotected

◆ transformPoint()

static Vec3 transformPoint ( const Mat4 matrix,
const Vec3 point 
)
inlinestatic

Transforms a point by a matrix and divides by w when possible.

◆ translation()

static Mat4 translation ( float  x,
float  y,
float  z 
)
inlinestatic

Creates a translation matrix.

◆ updateProjectionMatrix()

void updateProjectionMatrix ( )
inlineprotected

◆ updateViewMatrix()

void updateViewMatrix ( )
inlineprotected

◆ viewMatrix()

const Mat4 & viewMatrix ( ) const
inline

Returns the current view matrix.

◆ viewportHeight()

size_t viewportHeight ( ) const
inline

Returns the current viewport height.

◆ viewportWidth()

size_t viewportWidth ( ) const
inline

Returns the current viewport width.

Member Data Documentation

◆ camera_

Camera camera_
protected

◆ depthBuffer_

Vector<float> depthBuffer_
protected

◆ orthographicBottom_

float orthographicBottom_ = -1.0f
protected

◆ orthographicLeft_

float orthographicLeft_ = -1.0f
protected

◆ orthographicRight_

float orthographicRight_ = 1.0f
protected

◆ orthographicTop_

float orthographicTop_ = 1.0f
protected

◆ perspectiveFovYDegrees_

float perspectiveFovYDegrees_ = 60.0f
protected

◆ projectionMatrix_

Mat4 projectionMatrix_ = Mat4::identity()
protected

◆ projectionMode_

ProjectionMode projectionMode_ = ProjectionMode::Perspective
protected

◆ viewMatrix_

Mat4 viewMatrix_ = Mat4::identity()
protected

◆ viewportHeight_

size_t viewportHeight_ = 0
protected

◆ viewportWidth_

size_t viewportWidth_ = 0
protected

The documentation for this class was generated from the following file: