mousetrap v0.2.0
Loading...
Searching...
No Matches
mousetrap::Shape Class Reference

opengl shape primitive, variable number of vertices More...

#include <shape.hpp>

Inheritance diagram for mousetrap::Shape:
mousetrap::SignalEmitter

Public Member Functions

 Shape ()
 ctor, allocates vertex buffer gpu-side
 
 ~Shape ()
 dtor, deallocated vertex buffer gpu-side
 
 Shape (detail::ShapeInternal *)
 construct from internal, \for_internal_use_only
 
NativeObject get_internal () const override
 expose internal
 
 Shape (const Shape &)
 copy ctor, allocates new vertex array with identical vertex data
 
Shapeoperator= (const Shape &)
 copy assignment, allocates new vertex array with identical vertex data
 
 Shape (Shape &&) noexcept
 move ctor
 
Shapeoperator= (Shape &&) noexcept
 move assignment
 
GLNativeHandle get_native_handle () const
 access OpenGL vertex buffer id
 
void as_point (Vector2f position)
 construct as 2d point that point is always rendered as exactly 1 fragment
 
void as_points (const std::vector< Vector2f > &points)
 construct as set of points, each point is always rendered as exactly 1 fragment
 
void as_triangle (Vector2f a, Vector2f b, Vector2f c)
 construct as filled triangle
 
void as_rectangle (Vector2f top_left, Vector2f size)
 construct as filled rectangle from top left and size
 
void as_circle (Vector2f center, float radius, uint64_t n_outer_vertices)
 construct as filled circle
 
void as_ellipse (Vector2f center, float x_radius, float y_radius, uint64_t n_outer_vertices)
 construct as ellipse
 
void as_line (Vector2f a, Vector2f b)
 construct as line, has a width of 1 fragment exactly
 
void as_lines (const std::vector< std::pair< Vector2f, Vector2f > > &points)
 construct as set of lines, each has a width of exactly 1 fragment
 
void as_line_strip (const std::vector< Vector2f > &points)
 construct as set of connected lines
 
void as_polygon (const std::vector< Vector2f > &points)
 construct as convex polygon
 
void as_rectangular_frame (Vector2f top_left, Vector2f outer_size, float x_width, float y_width)
 construct as rectanglular frame of given thickness
 
void as_circular_ring (Vector2f center, float outer_radius, float thickness, uint64_t n_outer_vertices)
 construct as circular ring, a "2d donut"
 
void as_elliptical_ring (Vector2f center, float x_radius, float y_radius, float x_thickness, float y_thickness, uint64_t n_outer_vertices)
 construct as elliptic ring, a "2d elliptic donut"
 
void as_wireframe (const std::vector< Vector2f > &points)
 construct as a closed loop linesegment
 
void as_outline (const Shape &shape, RGBA color=RGBA(0, 0, 0, 1))
 construct a wireframe from a shapes outer vertices. Useful for generating frames or outlines
 
void render (const Shader &shader, GLTransform transform) const
 render the shape to the currently bound framebuffer
 
RGBA get_vertex_color (uint64_t index) const
 get color of n-th vertex, returns RGBA(0, 0, 0, 0) and prints a warning if vertex index out of bounds
 
void set_vertex_color (uint64_t index, RGBA new_color)
 set color of n-th vertex, does nothing if vertex index out of bounds
 
void set_vertex_texture_coordinate (uint64_t index, Vector2f coordinate)
 set texture coordinate of vertex, does nothing if vertex index out of bounds
 
Vector2f get_vertex_texture_coordinate (uint64_t index) const
 get vertex texture coordinate, returns Vector2f() if index out of bounds
 
void set_vertex_position (uint64_t index, Vector3f position)
 set vertex position in 3d space, does nothing if index out of bounds
 
Vector3f get_vertex_position (uint64_t index) const
 get vertex position in 3d space, return Vector3f() if out of bounds
 
uint64_t get_n_vertices () const
 get number of vertices, the number depends on the shape and may be larger than intuitive
 
void set_color (RGBA rgba)
 set color of all vertices at once
 
void set_is_visible (bool b)
 set whether shape should render when instructed
 
bool get_is_visible () const
 get whether shape should render when instructed
 
struct Rectangle get_bounding_box () const
 get axis aligned bounding box of all vertices
 
Vector2f get_size () const
 get size of axis aligned bounding box
 
void set_centroid (Vector2f new_position)
 align all vertices such that the centroid, the center of the axis aligned bounding box, is set to the given position
 
Vector2f get_centroid () const
 get centroid, center of the axis aligned bounding box
 
void set_top_left (Vector2f position)
 align top left of axis aligned bounding box with position
 
Vector2f get_top_left () const
 get top left of axis aligned bounding box
 
void rotate (Angle angle, Vector2f origin)
 rotate all vertices around origin
 
void set_texture (const TextureObject *texture)
 set texture of shape, has to be queried in the fragment shader using the int _texture_set and Sampler2D _texture uniforms, the default fragment shader does this automatically
 
const TextureObjectget_texture () const
 get texture object
 
 operator NativeObject () const override
 expose as GObject
 
- Public Member Functions inherited from mousetrap::SignalEmitter
void set_signal_blocked (const std::string &signal_id, bool b)
 block a signal by id \for_internal_use_only
 
bool get_signal_blocked (const std::string &signal_id) const
 get whether a signal is currently blocked
 
std::vector< std::string > get_all_signal_names ()
 get list of possible signal ids \for_internal_use_only
 
template<typename Function_t >
void connect_signal (const std::string &signal_id, Function_t *function, void *data=nullptr)
 connect static function to signal, does not work with lambdas \for_internal_use_only
 
void disconnect_signal (const std::string &signal_id)
 disconnect signal, it may not be invoked until reconnected, if signal is not registered, does nothing. For internal use only
 
virtual operator NativeObject () const =0
 expose as NativeObject, this is the GLib instance that signals are emitted on \for_internal_use_only
 
virtual NativeObject get_internal () const
 expose internally managed object, \for_internal_use_only
 

Static Public Member Functions

static Shape Point (Vector2f position)
 construct as 2d point that point is always rendered as exactly 1 fragment
 
static Shape Points (const std::vector< Vector2f > &points)
 construct as set of points, each point is always rendered as exactly 1 fragment
 
static Shape Triangle (Vector2f a, Vector2f b, Vector2f c)
 construct as filled triangle
 
static Shape Rectangle (Vector2f top_left, Vector2f size)
 construct as filled rectangle from top left and size
 
static Shape Circle (Vector2f center, float radius, uint64_t n_outer_vertices)
 construct as filled circle
 
static Shape Ellipse (Vector2f center, float x_radius, float y_radius, uint64_t n_outer_vertices)
 construct as ellipse
 
static Shape Line (Vector2f a, Vector2f b)
 construct as line, has a width of 1 fragment exactly
 
static Shape Lines (const std::vector< std::pair< Vector2f, Vector2f > > &points)
 construct as set of lines, each has a width of exactly 1 fragment
 
static Shape LineStrip (const std::vector< Vector2f > &points)
 construct as set of connected lines
 
static Shape Polygon (const std::vector< Vector2f > &points)
 construct as convex polygon
 
static Shape RectangularFrame (Vector2f top_left, Vector2f outer_size, float x_width, float y_width)
 
static Shape CircularRing (Vector2f center, float outer_radius, float thickness, uint64_t n_outer_vertices)
 construct as circular ring, a "2d donut"
 
static Shape EllipticalRing (Vector2f center, float x_radius, float y_radius, float x_thickness, float y_thickness, uint64_t n_outer_vertices)
 
static Shape Wireframe (const std::vector< Vector2f > &points)
 construct as a closed loop linesegment
 
static Shape Outline (const Shape &shape)
 construct a wireframe from a shapes outer vertices. Useful for generating frames or outlines
 

Additional Inherited Members

- Protected Member Functions inherited from mousetrap::SignalEmitter
 SignalEmitter ()
 ctor
 
 ~SignalEmitter ()
 destructor
 

Detailed Description

opengl shape primitive, variable number of vertices

Constructor & Destructor Documentation

◆ Shape() [1/3]

mousetrap::Shape::Shape ( detail::ShapeInternal *  internal)

construct from internal, \for_internal_use_only

Parameters
internal

◆ Shape() [2/3]

mousetrap::Shape::Shape ( const Shape other)

copy ctor, allocates new vertex array with identical vertex data

Parameters
other

◆ Shape() [3/3]

mousetrap::Shape::Shape ( Shape &&  other)
noexcept

move ctor

Parameters
other

Member Function Documentation

◆ as_circle()

void mousetrap::Shape::as_circle ( Vector2f  center,
float  radius,
uint64_t  n_outer_vertices 
)

construct as filled circle

Parameters
centerpoint in gl coordinates
radiusdistance in gl coordinates
n_outer_verticesnumber of equally spaced vertices on the perimeter of the circle

References as_ellipse(), and mousetrap::log::critical().

◆ as_circular_ring()

void mousetrap::Shape::as_circular_ring ( Vector2f  center,
float  outer_radius,
float  thickness,
uint64_t  n_outer_vertices 
)

construct as circular ring, a "2d donut"

Parameters
centercenter in 2d space
outer_radiusradius from the center to the outer perimeter of the ring
thicknesswidth of the rings inner bounds along all axis
n_outer_verticesnumber of vertices on the outer perimeter of the ring

References as_elliptical_ring().

◆ as_ellipse()

void mousetrap::Shape::as_ellipse ( Vector2f  center,
float  x_radius,
float  y_radius,
uint64_t  n_outer_vertices 
)

construct as ellipse

Parameters
centerpoint in gl coordinates
x_radiusradius along the x-axis, normalized distance in 2d space
y_radiusradius along the y-axis, normalized distance in 2d space
n_outer_verticesnumber of equally spaced vertices on the perimeter of the circle

References mousetrap::log::critical().

Referenced by as_circle().

◆ as_elliptical_ring()

void mousetrap::Shape::as_elliptical_ring ( Vector2f  center,
float  x_radius,
float  y_radius,
float  x_thickness,
float  y_thickness,
uint64_t  n_outer_vertices 
)

construct as elliptic ring, a "2d elliptic donut"

Parameters
centercenter in 2d space
x_radiushorizontal radius of the outer perimeter of the ellipse
y_radiusvertical radius of the outer perimeter of the ellipse
x_thicknesswidth of the inner bound of the ellipse along the x-axis
y_thicknessheight of the inner bounds of the ellipse along the y-axis
n_outer_verticesnumber of vertices on the outer perimeter of the ellipse

Referenced by as_circular_ring().

◆ as_line()

void mousetrap::Shape::as_line ( Vector2f  a,
Vector2f  b 
)

construct as line, has a width of 1 fragment exactly

Parameters
apoint in gl coordinates
bpoint in gl coordinates

◆ as_line_strip()

void mousetrap::Shape::as_line_strip ( const std::vector< Vector2f > &  points)

construct as set of connected lines

Parameters
points{a1, a2, ..., an} will result in line segments {a1, a2}, {a2, a3}, ..., {an-1, an}

◆ as_lines()

void mousetrap::Shape::as_lines ( const std::vector< std::pair< Vector2f, Vector2f > > &  points)

construct as set of lines, each has a width of exactly 1 fragment

Parameters
pointsvector of pairs of 2 points, both in gl coordinates

◆ as_outline()

void mousetrap::Shape::as_outline ( const Shape shape,
RGBA  color = RGBA(0, 0, 0, 1) 
)

construct a wireframe from a shapes outer vertices. Useful for generating frames or outlines

Parameters
shapeanother shape, will generate minimum bounding polygon and construct a wireframe from that polygon

References mousetrap::log::critical(), get_bounding_box(), get_n_vertices(), get_vertex_position(), and mousetrap::Rectangle::top_left.

◆ as_point()

void mousetrap::Shape::as_point ( Vector2f  position)

construct as 2d point that point is always rendered as exactly 1 fragment

Parameters
positionposition gl coordinates

◆ as_points()

void mousetrap::Shape::as_points ( const std::vector< Vector2f > &  points)

construct as set of points, each point is always rendered as exactly 1 fragment

Parameters
pointsvector of points

◆ as_polygon()

void mousetrap::Shape::as_polygon ( const std::vector< Vector2f > &  points)

construct as convex polygon

Parameters
pointspoints in gl coordinates, minimum bounding polygon is calculated on these, so some of the vertices ay be discarded

◆ as_rectangle()

void mousetrap::Shape::as_rectangle ( Vector2f  top_left,
Vector2f  size 
)

construct as filled rectangle from top left and size

Parameters
top_leftpoint in gl coordinates
sizelength in gl coordinates

◆ as_rectangular_frame()

void mousetrap::Shape::as_rectangular_frame ( Vector2f  top_left,
Vector2f  outer_size,
float  x_width,
float  y_width 
)

construct as rectanglular frame of given thickness

Parameters
top_lefttop left anchor of the outer perimeter of the frame, in gl coordinates
outer_sizewidth and height of the oute perimeter of the frame, in gl coordinates
x_widthhorizontal width of the frames inner bounds, in gl coordinates
y_widthvertical height of the frames inner bounds, in gl coordinates

◆ as_triangle()

void mousetrap::Shape::as_triangle ( Vector2f  a,
Vector2f  b,
Vector2f  c 
)

construct as filled triangle

Parameters
apoint in gl coordinates
bpoint in gl coordinates
cpoint in gl coordinates

◆ as_wireframe()

void mousetrap::Shape::as_wireframe ( const std::vector< Vector2f > &  points)

construct as a closed loop linesegment

Parameters
points{a1, a2, ..., an} will result in line segments {a1, a2}, {a2, a3}, ..., {an-1, an}, {an, a1}

◆ Circle()

Shape mousetrap::Shape::Circle ( Vector2f  center,
float  radius,
uint64_t  n_outer_vertices 
)
static

construct as filled circle

Parameters
centerpoint in gl coordinates
radiusdistance in gl coordinates
n_outer_verticesnumber of equally spaced vertices on the perimeter of the circle

References Shape().

◆ CircularRing()

Shape mousetrap::Shape::CircularRing ( Vector2f  center,
float  outer_radius,
float  thickness,
uint64_t  n_outer_vertices 
)
static

construct as circular ring, a "2d donut"

Parameters
centercenter in 2d space
outer_radiusradius from the center to the outer perimeter of the ring
thicknesswidth of the rings inner bounds along all axis
n_outer_verticesnumber of vertices on the outer perimeter of the ring

References Shape().

◆ Ellipse()

Shape mousetrap::Shape::Ellipse ( Vector2f  center,
float  x_radius,
float  y_radius,
uint64_t  n_outer_vertices 
)
static

construct as ellipse

Parameters
centerpoint in gl coordinates
x_radiusradius along the x-axis, normalized distance in 2d space
y_radiusradius along the y-axis, normalized distance in 2d space
n_outer_verticesnumber of equally spaced vertices on the perimeter of the circle

References Shape().

◆ EllipticalRing()

Shape mousetrap::Shape::EllipticalRing ( Vector2f  center,
float  x_radius,
float  y_radius,
float  x_thickness,
float  y_thickness,
uint64_t  n_outer_vertices 
)
static

References Shape().

◆ get_bounding_box()

Rectangle mousetrap::Shape::get_bounding_box ( ) const

get axis aligned bounding box of all vertices

Returns
rectangle

Referenced by as_outline(), get_size(), get_top_left(), and set_top_left().

◆ get_centroid()

Vector2f mousetrap::Shape::get_centroid ( ) const

get centroid, center of the axis aligned bounding box

Returns
position

Referenced by set_centroid().

◆ get_internal()

NativeObject mousetrap::Shape::get_internal ( ) const
overridevirtual

expose internal

Reimplemented from mousetrap::SignalEmitter.

◆ get_is_visible()

bool mousetrap::Shape::get_is_visible ( ) const

get whether shape should render when instructed

Returns
true if false, mousetrap::Shape::render will do nothing, true otherwise

◆ get_n_vertices()

uint64_t mousetrap::Shape::get_n_vertices ( ) const

get number of vertices, the number depends on the shape and may be larger than intuitive

Returns
number of vertices

Referenced by as_outline().

◆ get_native_handle()

GLNativeHandle mousetrap::Shape::get_native_handle ( ) const

access OpenGL vertex buffer id

Returns
id

◆ get_size()

Vector2f mousetrap::Shape::get_size ( ) const

get size of axis aligned bounding box

Returns
width, height

References get_bounding_box(), and mousetrap::Rectangle::size.

◆ get_texture()

const TextureObject * mousetrap::Shape::get_texture ( ) const

get texture object

Returns
pointer to texture object, or nullptr if no texture is registered

◆ get_top_left()

Vector2f mousetrap::Shape::get_top_left ( ) const

get top left of axis aligned bounding box

Returns
position

References get_bounding_box(), and mousetrap::Rectangle::top_left.

◆ get_vertex_color()

RGBA mousetrap::Shape::get_vertex_color ( uint64_t  index) const

get color of n-th vertex, returns RGBA(0, 0, 0, 0) and prints a warning if vertex index out of bounds

Parameters
indexvertex index
Returns
color as RGBA

References mousetrap::log::critical().

◆ get_vertex_position()

Vector3f mousetrap::Shape::get_vertex_position ( uint64_t  index) const

get vertex position in 3d space, return Vector3f() if out of bounds

Parameters
indexvertex index
Returns
position in 3d space

References mousetrap::log::critical().

Referenced by as_outline().

◆ get_vertex_texture_coordinate()

Vector2f mousetrap::Shape::get_vertex_texture_coordinate ( uint64_t  index) const

get vertex texture coordinate, returns Vector2f() if index out of bounds

Parameters
indexvertex index
Returns
texture coordinate, {0, 0} for top left, {1, 1} for bottom right of texture

◆ Line()

Shape mousetrap::Shape::Line ( Vector2f  a,
Vector2f  b 
)
static

construct as line, has a width of 1 fragment exactly

Parameters
apoint in gl coordinates
bpoint in gl coordinates

References Shape().

◆ Lines()

Shape mousetrap::Shape::Lines ( const std::vector< std::pair< Vector2f, Vector2f > > &  points)
static

construct as set of lines, each has a width of exactly 1 fragment

Parameters
pointsvector of pairs of 2 points, both in gl coordinates

References Shape().

◆ LineStrip()

Shape mousetrap::Shape::LineStrip ( const std::vector< Vector2f > &  points)
static

construct as set of connected lines

Parameters
points{a1, a2, ..., an} will result in line segments {a1, a2}, {a2, a3}, ..., {an-1, an}

References Shape().

◆ operator NativeObject()

mousetrap::Shape::operator NativeObject ( ) const
overridevirtual

expose as GObject

Implements mousetrap::SignalEmitter.

◆ operator=() [1/2]

Shape & mousetrap::Shape::operator= ( const Shape other)

copy assignment, allocates new vertex array with identical vertex data

Parameters
other
Returns
reference to self after assignment

◆ operator=() [2/2]

Shape & mousetrap::Shape::operator= ( Shape &&  other)
noexcept

move assignment

Parameters
other
Returns
reference to self after assignment

◆ Outline()

Shape mousetrap::Shape::Outline ( const Shape shape)
static

construct a wireframe from a shapes outer vertices. Useful for generating frames or outlines

Parameters
shapeanother shape, will generate minimum bounding polygon and construct a wireframe from that polygon

References Shape().

◆ Point()

Shape mousetrap::Shape::Point ( Vector2f  position)
static

construct as 2d point that point is always rendered as exactly 1 fragment

Parameters
positionposition gl coordinates

References Shape().

◆ Points()

Shape mousetrap::Shape::Points ( const std::vector< Vector2f > &  points)
static

construct as set of points, each point is always rendered as exactly 1 fragment

Parameters
pointsvector of points

References Shape().

◆ Polygon()

Shape mousetrap::Shape::Polygon ( const std::vector< Vector2f > &  points)
static

construct as convex polygon

Parameters
pointspoints in gl coordinates, minimum bounding polygon is calculated on these, so some of the vertices ay be discarded

References Shape().

◆ Rectangle()

Shape mousetrap::Shape::Rectangle ( Vector2f  top_left,
Vector2f  size 
)
static

construct as filled rectangle from top left and size

Parameters
top_leftpoint in gl coordinates
sizelength in gl coordinates

References Shape().

◆ RectangularFrame()

Shape mousetrap::Shape::RectangularFrame ( Vector2f  top_left,
Vector2f  outer_size,
float  x_width,
float  y_width 
)
static

References Shape().

◆ render()

void mousetrap::Shape::render ( const Shader shader,
GLTransform  transform 
) const

render the shape to the currently bound framebuffer

Parameters
shadershader program to use
transformtransform to hand to the vertex shader

References mousetrap::Shader::get_program_id(), mousetrap::Shader::get_uniform_location(), and mousetrap::GLTransform::transform.

◆ rotate()

void mousetrap::Shape::rotate ( Angle  angle,
Vector2f  origin 
)

rotate all vertices around origin

Parameters
angle
originpoint in 2d space

◆ set_centroid()

void mousetrap::Shape::set_centroid ( Vector2f  new_position)

align all vertices such that the centroid, the center of the axis aligned bounding box, is set to the given position

Parameters
new_position

References get_centroid().

◆ set_color()

void mousetrap::Shape::set_color ( RGBA  rgba)

set color of all vertices at once

Parameters
rgbacolor in RGBA

◆ set_is_visible()

void mousetrap::Shape::set_is_visible ( bool  b)

set whether shape should render when instructed

Parameters
bif false, mousetrap::Shape::render will do nothing, true otherwise

◆ set_texture()

void mousetrap::Shape::set_texture ( const TextureObject texture)

set texture of shape, has to be queried in the fragment shader using the int _texture_set and Sampler2D _texture uniforms, the default fragment shader does this automatically

Parameters
texturetexture object, such as mousetrap::Texture, mousetrap::RenderTexture or mousetrap::MultisampledRenderTexture. The user is responsible for making sure the texture stays in memory. May be nullptr

◆ set_top_left()

void mousetrap::Shape::set_top_left ( Vector2f  position)

align top left of axis aligned bounding box with position

Parameters
position

References get_bounding_box(), and mousetrap::Rectangle::top_left.

◆ set_vertex_color()

void mousetrap::Shape::set_vertex_color ( uint64_t  index,
RGBA  new_color 
)

set color of n-th vertex, does nothing if vertex index out of bounds

Parameters
indexvertex index
new_color

References mousetrap::log::critical().

◆ set_vertex_position()

void mousetrap::Shape::set_vertex_position ( uint64_t  index,
Vector3f  position 
)

set vertex position in 3d space, does nothing if index out of bounds

Parameters
indexvertex index
positionposition in 3d space
Note
if multiple vertex positions change at the same time, use mousetrap::Vertex::as_rectangle (or other appropriate shape) to update all of them at once in a more performant manned

References mousetrap::log::critical().

◆ set_vertex_texture_coordinate()

void mousetrap::Shape::set_vertex_texture_coordinate ( uint64_t  index,
Vector2f  coordinate 
)

set texture coordinate of vertex, does nothing if vertex index out of bounds

Parameters
indexvertex index
coordinatenew texture coordinate, {0, 0} for top left, {1, 1} for bottom right of texture

References mousetrap::log::critical().

◆ Triangle()

Shape mousetrap::Shape::Triangle ( Vector2f  a,
Vector2f  b,
Vector2f  c 
)
static

construct as filled triangle

Parameters
apoint in gl coordinates
bpoint in gl coordinates
cpoint in gl coordinates

References Shape().

◆ Wireframe()

Shape mousetrap::Shape::Wireframe ( const std::vector< Vector2f > &  points)
static

construct as a closed loop linesegment

Parameters
points{a1, a2, ..., an} will result in line segments {a1, a2}, {a2, a3}, ..., {an-1, an}, {an, a1}

References Shape().


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