|
mousetrap v0.2.0
|
opengl shape primitive, variable number of vertices More...
#include <shape.hpp>
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 | |
| Shape & | operator= (const Shape &) |
| copy assignment, allocates new vertex array with identical vertex data | |
| Shape (Shape &&) noexcept | |
| move ctor | |
| Shape & | operator= (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 TextureObject * | get_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 | |
opengl shape primitive, variable number of vertices
| mousetrap::Shape::Shape | ( | detail::ShapeInternal * | internal | ) |
construct from internal, \for_internal_use_only
| internal |
| mousetrap::Shape::Shape | ( | const Shape & | other | ) |
copy ctor, allocates new vertex array with identical vertex data
| other |
|
noexcept |
move ctor
| other |
| void mousetrap::Shape::as_circle | ( | Vector2f | center, |
| float | radius, | ||
| uint64_t | n_outer_vertices | ||
| ) |
construct as filled circle
| center | point in gl coordinates |
| radius | distance in gl coordinates |
| n_outer_vertices | number of equally spaced vertices on the perimeter of the circle |
References as_ellipse(), and mousetrap::log::critical().
| 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"
| center | center in 2d space |
| outer_radius | radius from the center to the outer perimeter of the ring |
| thickness | width of the rings inner bounds along all axis |
| n_outer_vertices | number of vertices on the outer perimeter of the ring |
References as_elliptical_ring().
| void mousetrap::Shape::as_ellipse | ( | Vector2f | center, |
| float | x_radius, | ||
| float | y_radius, | ||
| uint64_t | n_outer_vertices | ||
| ) |
construct as ellipse
| center | point in gl coordinates |
| x_radius | radius along the x-axis, normalized distance in 2d space |
| y_radius | radius along the y-axis, normalized distance in 2d space |
| n_outer_vertices | number of equally spaced vertices on the perimeter of the circle |
References mousetrap::log::critical().
Referenced by as_circle().
| 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"
| center | center in 2d space |
| x_radius | horizontal radius of the outer perimeter of the ellipse |
| y_radius | vertical radius of the outer perimeter of the ellipse |
| x_thickness | width of the inner bound of the ellipse along the x-axis |
| y_thickness | height of the inner bounds of the ellipse along the y-axis |
| n_outer_vertices | number of vertices on the outer perimeter of the ellipse |
Referenced by as_circular_ring().
| void mousetrap::Shape::as_line | ( | Vector2f | a, |
| Vector2f | b | ||
| ) |
construct as line, has a width of 1 fragment exactly
| a | point in gl coordinates |
| b | point in gl coordinates |
| void mousetrap::Shape::as_line_strip | ( | const std::vector< Vector2f > & | points | ) |
construct as set of connected lines
| points | {a1, a2, ..., an} will result in line segments {a1, a2}, {a2, a3}, ..., {an-1, an} |
| 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
| points | vector of pairs of 2 points, both in gl coordinates |
construct a wireframe from a shapes outer vertices. Useful for generating frames or outlines
| shape | another 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.
| void mousetrap::Shape::as_point | ( | Vector2f | position | ) |
construct as 2d point that point is always rendered as exactly 1 fragment
| position | position gl coordinates |
| void mousetrap::Shape::as_points | ( | const std::vector< Vector2f > & | points | ) |
construct as set of points, each point is always rendered as exactly 1 fragment
| points | vector of points |
| void mousetrap::Shape::as_polygon | ( | const std::vector< Vector2f > & | points | ) |
construct as convex polygon
| points | points in gl coordinates, minimum bounding polygon is calculated on these, so some of the vertices ay be discarded |
| void mousetrap::Shape::as_rectangle | ( | Vector2f | top_left, |
| Vector2f | size | ||
| ) |
construct as filled rectangle from top left and size
| top_left | point in gl coordinates |
| size | length in gl coordinates |
| 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
| top_left | top left anchor of the outer perimeter of the frame, in gl coordinates |
| outer_size | width and height of the oute perimeter of the frame, in gl coordinates |
| x_width | horizontal width of the frames inner bounds, in gl coordinates |
| y_width | vertical height of the frames inner bounds, in gl coordinates |
| void mousetrap::Shape::as_triangle | ( | Vector2f | a, |
| Vector2f | b, | ||
| Vector2f | c | ||
| ) |
construct as filled triangle
| a | point in gl coordinates |
| b | point in gl coordinates |
| c | point in gl coordinates |
| void mousetrap::Shape::as_wireframe | ( | const std::vector< Vector2f > & | points | ) |
construct as a closed loop linesegment
| points | {a1, a2, ..., an} will result in line segments {a1, a2}, {a2, a3}, ..., {an-1, an}, {an, a1} |
|
static |
construct as filled circle
| center | point in gl coordinates |
| radius | distance in gl coordinates |
| n_outer_vertices | number of equally spaced vertices on the perimeter of the circle |
References Shape().
|
static |
construct as circular ring, a "2d donut"
| center | center in 2d space |
| outer_radius | radius from the center to the outer perimeter of the ring |
| thickness | width of the rings inner bounds along all axis |
| n_outer_vertices | number of vertices on the outer perimeter of the ring |
References Shape().
|
static |
construct as ellipse
| center | point in gl coordinates |
| x_radius | radius along the x-axis, normalized distance in 2d space |
| y_radius | radius along the y-axis, normalized distance in 2d space |
| n_outer_vertices | number of equally spaced vertices on the perimeter of the circle |
References Shape().
|
static |
References Shape().
| Rectangle mousetrap::Shape::get_bounding_box | ( | ) | const |
get axis aligned bounding box of all vertices
Referenced by as_outline(), get_size(), get_top_left(), and set_top_left().
| Vector2f mousetrap::Shape::get_centroid | ( | ) | const |
|
overridevirtual |
expose internal
Reimplemented from mousetrap::SignalEmitter.
| bool mousetrap::Shape::get_is_visible | ( | ) | const |
get whether shape should render when instructed
| uint64_t mousetrap::Shape::get_n_vertices | ( | ) | const |
get number of vertices, the number depends on the shape and may be larger than intuitive
Referenced by as_outline().
| GLNativeHandle mousetrap::Shape::get_native_handle | ( | ) | const |
access OpenGL vertex buffer id
| Vector2f mousetrap::Shape::get_size | ( | ) | const |
get size of axis aligned bounding box
References get_bounding_box(), and mousetrap::Rectangle::size.
| const TextureObject * mousetrap::Shape::get_texture | ( | ) | const |
get texture object
| Vector2f mousetrap::Shape::get_top_left | ( | ) | const |
get top left of axis aligned bounding box
References get_bounding_box(), and mousetrap::Rectangle::top_left.
| 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
| index | vertex index |
References mousetrap::log::critical().
| Vector3f mousetrap::Shape::get_vertex_position | ( | uint64_t | index | ) | const |
get vertex position in 3d space, return Vector3f() if out of bounds
| index | vertex index |
References mousetrap::log::critical().
Referenced by as_outline().
| Vector2f mousetrap::Shape::get_vertex_texture_coordinate | ( | uint64_t | index | ) | const |
get vertex texture coordinate, returns Vector2f() if index out of bounds
| index | vertex index |
|
static |
construct as line, has a width of 1 fragment exactly
| a | point in gl coordinates |
| b | point in gl coordinates |
References Shape().
|
static |
construct as set of lines, each has a width of exactly 1 fragment
| points | vector of pairs of 2 points, both in gl coordinates |
References Shape().
|
static |
construct as set of connected lines
| points | {a1, a2, ..., an} will result in line segments {a1, a2}, {a2, a3}, ..., {an-1, an} |
References Shape().
|
overridevirtual |
expose as GObject
Implements mousetrap::SignalEmitter.
copy assignment, allocates new vertex array with identical vertex data
| other |
move assignment
| other |
construct a wireframe from a shapes outer vertices. Useful for generating frames or outlines
| shape | another shape, will generate minimum bounding polygon and construct a wireframe from that polygon |
References Shape().
|
static |
construct as 2d point that point is always rendered as exactly 1 fragment
| position | position gl coordinates |
References Shape().
|
static |
construct as set of points, each point is always rendered as exactly 1 fragment
| points | vector of points |
References Shape().
|
static |
construct as convex polygon
| points | points in gl coordinates, minimum bounding polygon is calculated on these, so some of the vertices ay be discarded |
References Shape().
|
static |
construct as filled rectangle from top left and size
| top_left | point in gl coordinates |
| size | length in gl coordinates |
References Shape().
|
static |
References Shape().
| void mousetrap::Shape::render | ( | const Shader & | shader, |
| GLTransform | transform | ||
| ) | const |
render the shape to the currently bound framebuffer
| shader | shader program to use |
| transform | transform to hand to the vertex shader |
References mousetrap::Shader::get_program_id(), mousetrap::Shader::get_uniform_location(), and mousetrap::GLTransform::transform.
| void mousetrap::Shape::rotate | ( | Angle | angle, |
| Vector2f | origin | ||
| ) |
rotate all vertices around origin
| angle | |
| origin | point in 2d space |
| 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
| new_position |
References get_centroid().
| void mousetrap::Shape::set_color | ( | RGBA | rgba | ) |
set color of all vertices at once
| rgba | color in RGBA |
| void mousetrap::Shape::set_is_visible | ( | bool | b | ) |
set whether shape should render when instructed
| b | if false, mousetrap::Shape::render will do nothing, true otherwise |
| 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
| texture | texture 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 |
| void mousetrap::Shape::set_top_left | ( | Vector2f | position | ) |
align top left of axis aligned bounding box with position
| position |
References get_bounding_box(), and mousetrap::Rectangle::top_left.
| 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
| index | vertex index |
| new_color |
References mousetrap::log::critical().
| void mousetrap::Shape::set_vertex_position | ( | uint64_t | index, |
| Vector3f | position | ||
| ) |
set vertex position in 3d space, does nothing if index out of bounds
| index | vertex index |
| position | position in 3d space |
References mousetrap::log::critical().
| 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
| index | vertex index |
| coordinate | new texture coordinate, {0, 0} for top left, {1, 1} for bottom right of texture |
References mousetrap::log::critical().
|
static |
construct as filled triangle
| a | point in gl coordinates |
| b | point in gl coordinates |
| c | point in gl coordinates |
References Shape().
|
static |
construct as a closed loop linesegment
| points | {a1, a2, ..., an} will result in line segments {a1, a2}, {a2, a3}, ..., {an-1, an}, {an, a1} |
References Shape().