Easy3D 2.6.1
Loading...
Searching...
No Matches
easy3d::shape Namespace Reference

A collection of functions for rendering basic shapes. More...

Functions

Functions for drawing
void draw_quad_wire (const Rect &rect, const vec4 &color, int width, int height, float depth)
 Draws a wire quad defined in the screen space.
 
void draw_quad_filled (const Rect &rect, const vec4 &color, int width, int height, float depth)
 Draws a solid quad defined in the screen space.
 
void draw_quad_filled (const Rect &rect, unsigned int texture, int width, int height, float depth)
 Draws a solid quad defined in the screen space.
 
void draw_full_screen_quad (unsigned int texture, float depth)
 Draws a full screen textured quad.
 
void draw_depth_texture (const Rect &rect, unsigned int texture, int width, int height, float depth)
 Draws a quad visualizing a depth texture in a region.
 
void draw_quad (unsigned int position_attrib, unsigned int texcoord_attrib, int x, int y, int w, int h, int vpw, int vph, float depth)
 Draws a quad defined in the screen space using a bound shader.
 
void draw_full_screen_quad (unsigned int position_attrib, unsigned int texcoord_attrib, float depth)
 Draws a full screen quad using the bound shader.
 
void draw_polygon_wire (const Polygon2 &polygon, const vec4 &color, int width, int height, float depth)
 Draws a polygon (line loop) in the screen space.
 
void draw_polygon_filled (const Polygon2 &polygon, const vec4 &color, int width, int height, float depth)
 Draws a filled polygon in the screen space.
 
void draw_sphere_big_circles (LinesDrawable *drawable, const mat4 &mvp, const mat4 &m, bool axes=true)
 Draws the outline (the 3 big circles) of a sphere.
 
void draw_box_wire (LinesDrawable *drawable, const mat4 &mvp, const mat4 &m, bool abstracted=false)
 Draws a box.
 
Functions for creating basic shapes (data preparation)
void create_grid (int x_steps, int y_steps, std::vector< vec3 > &points, float depth=0.0f, float scale=0.5f)
 Generates data for a grid as a set of line segments.
 
void create_box (std::vector< vec3 > &points, std::vector< vec3 > &colors, bool abstracted=false)
 Generates data for a unit box as a set of line segments.
 
void create_circle (int slices, std::vector< vec3 > &points, std::vector< unsigned int > &indices)
 Generates data for a unit circle as a set of line segments.
 
void create_sphere (const vec3 &center, double radius, int slices, int stacks, const vec3 &color, std::vector< vec3 > &points, std::vector< vec3 > &normals, std::vector< vec3 > &colors)
 Generates data (points, normals, and colors) for a 3D sphere.
 
void create_checker_sphere (const vec3 &center, double radius, int slices, int stacks, int checker_size, const vec3 &color1, const vec3 &color2, std::vector< vec3 > &points, std::vector< vec3 > &normals, std::vector< vec3 > &colors)
 Generates data (points, normals, and colors) for a 3D checker sphere.
 
void create_cylinder (double radius, int slices, const vec3 &s, const vec3 &t, const vec3 &color, std::vector< vec3 > &points, std::vector< vec3 > &normals, std::vector< vec3 > &colors)
 Prepares data (points, normals, and colors) for a 3D cylinder defined by two 3D points s and t.
 
void create_cone (double radius, int slices, const vec3 &s, const vec3 &t, const vec3 &color, std::vector< vec3 > &points, std::vector< vec3 > &normals, std::vector< vec3 > &colors)
 Prepares data (points, normals, and colors) for a 3D cone defined by two 3D points b and t.
 
void create_torus (double major_radius, double minor_radius, int major_slices, int minor_slices, std::vector< vec3 > &points, std::vector< vec3 > &normals)
 Prepares data for representing a torus.
 
void create_camera (std::vector< vec3 > &points, float width, float fov, float hw_ratio=0.6f)
 Generates data (points) for representing a camera in the 3D world as a set of lines.
 
void create_camera (std::vector< vec3 > &points, std::vector< unsigned int > &indices, float width, float fov, float hw_ratio=0.6f)
 Prepares data (points) for representing a camera in the 3D world as a set of triangles.
 

Detailed Description

A collection of functions for rendering basic shapes.

Function Documentation

◆ create_box()

void create_box ( std::vector< vec3 > & points,
std::vector< vec3 > & colors,
bool abstracted = false )

Generates data for a unit box as a set of line segments.

The box is centered at vec3(0, 0, 0) and is aligned with the main axes.

Parameters
pointsThe points to be returned.
colorsThe colors of the points.
abstractedtrue to draw an abstracted version (only part of its corners).

◆ create_camera() [1/2]

void create_camera ( std::vector< vec3 > & points,
float width,
float fov,
float hw_ratio = 0.6f )

Generates data (points) for representing a camera in the 3D world as a set of lines.

Parameters
pointsThe points to be returned.
widthThe width of the camera. A good value can be 5% of the scene radius, or 10% of the character height (in walking mode).
fovThe vertical field of view of the camera (in radians).
hw_ratioThe aspect ratio of the base quad defined as height/width (default 0.6).

◆ create_camera() [2/2]

void create_camera ( std::vector< vec3 > & points,
std::vector< unsigned int > & indices,
float width,
float fov,
float hw_ratio = 0.6f )

Prepares data (points) for representing a camera in the 3D world as a set of triangles.

Parameters
pointsThe points to be returned.
indicesThe vertex indices to be returned.
widthThe width of the camera. A good value can be 5% of the scene radius, or 10% of the character height (in walking mode).
fovThe vertical field of view of the camera (in radians).
hw_ratioThe aspect ratio of the base quad defined as height/width (default 0.6).

◆ create_checker_sphere()

void create_checker_sphere ( const vec3 & center,
double radius,
int slices,
int stacks,
int checker_size,
const vec3 & color1,
const vec3 & color2,
std::vector< vec3 > & points,
std::vector< vec3 > & normals,
std::vector< vec3 > & colors )

Generates data (points, normals, and colors) for a 3D checker sphere.

Parameters
centerthe center of the sphere.
radiusthe radius of the sphere.
slicesthe number of subdivisions around the z axis (similar to lines of longitude).
stacksthe number of subdivisions along the z axis(similar to lines of latitude).
checker_sizehow many tiles each checker will occupy.
color1one of the two interchanging colors.
color2the other one of the two interchanging colors.
pointsthe points to be returned.
normalsthe normals to be returned.
colorsthe colors to be returned.

◆ create_circle()

void create_circle ( int slices,
std::vector< vec3 > & points,
std::vector< unsigned int > & indices )

Generates data for a unit circle as a set of line segments.

The circle is centered at vec3(0, 0, 0) and lies on the XOY plane.

Parameters
slicesThe number of subdivisions.
pointsThe points to be returned.
indicesThe indices of the points.

◆ create_cone()

void create_cone ( double radius,
int slices,
const vec3 & s,
const vec3 & t,
const vec3 & color,
std::vector< vec3 > & points,
std::vector< vec3 > & normals,
std::vector< vec3 > & colors )

Prepares data (points, normals, and colors) for a 3D cone defined by two 3D points b and t.

Parameters
radiusThe radius of the cone.
slicesThe number of subdivisions around the z axis (similar to lines of longitude).
sThe base center.
tThe top center.
colorThe color of the cone.
pointsThe points to be returned.
normalsThe normals to be returned.
colorsThe colors to be returned.
Examples
Tutorial_203_Viewer_wxWidgets/main.cpp, and Tutorial_204_Viewer_Qt/main.cpp.

◆ create_cylinder()

void create_cylinder ( double radius,
int slices,
const vec3 & s,
const vec3 & t,
const vec3 & color,
std::vector< vec3 > & points,
std::vector< vec3 > & normals,
std::vector< vec3 > & colors )

Prepares data (points, normals, and colors) for a 3D cylinder defined by two 3D points s and t.

Parameters
radiusThe radius of the cylinder.
slicesThe number of subdivisions around the z axis (similar to lines of longitude).
sThe base center.
tThe top center.
colorThe color of the cylinder.
pointsThe points to be returned.
normalsThe normals to be returned.
colorsThe colors to be returned.
Examples
Tutorial_203_Viewer_wxWidgets/main.cpp, and Tutorial_204_Viewer_Qt/main.cpp.

◆ create_grid()

void create_grid ( int x_steps,
int y_steps,
std::vector< vec3 > & points,
float depth = 0.0f,
float scale = 0.5f )

Generates data for a grid as a set of line segments.

The grid is centered at vec3(0, 0, 0) and lies on the XOY plane.

Parameters
x_stepsThe number of subdivisions along X direction.
y_stepsThe number of subdivisions along Y direction.
depthThe depth (Z value) of the generated points.
pointsThe points to be returned.
scaleThe scaling factor

◆ create_sphere()

void create_sphere ( const vec3 & center,
double radius,
int slices,
int stacks,
const vec3 & color,
std::vector< vec3 > & points,
std::vector< vec3 > & normals,
std::vector< vec3 > & colors )

Generates data (points, normals, and colors) for a 3D sphere.

Parameters
centerthe center of the sphere.
radiusthe radius of the sphere.
slicesthe number of subdivisions around the z axis (similar to lines of longitude).
stacksthe number of subdivisions along the z axis(similar to lines of latitude).
colorthe color of the sphere.
pointsthe points to be returned.
normalsthe normals to be returned.
colorsthe colors to be returned.
Examples
Tutorial_203_Viewer_wxWidgets/main.cpp, and Tutorial_204_Viewer_Qt/main.cpp.

◆ create_torus()

void create_torus ( double major_radius,
double minor_radius,
int major_slices,
int minor_slices,
std::vector< vec3 > & points,
std::vector< vec3 > & normals )

Prepares data for representing a torus.

Parameters
major_radiusThe radius of major circle.
minor_radiusThe radius of minor circle.
major_slicesThe number of subdivisions along the major circle (suggested value 50).
minor_slicesThe number of subdivisions along the minor circle (suggested value 20).
pointsReturns the points.
normalsReturns the normals.

◆ draw_box_wire()

void draw_box_wire ( LinesDrawable * drawable,
const mat4 & mvp,
const mat4 & m,
bool abstracted = false )

Draws a box.

Parameters
drawableThe drawable.
mvpThe model view projection matrix.
mThe transformation matrix defining the box's location, sizes, and orientation.
abstractedtrue to draw an abstracted version (only part of its corners).

◆ draw_depth_texture()

void draw_depth_texture ( const Rect & rect,
unsigned int texture,
int width,
int height,
float depth )

Draws a quad visualizing a depth texture in a region.

This is function is similar to draw_quad_filled(... int texture...). The only difference is that a depth texture is rendered as a gray scale image. For depth textures from off-screen rendering (usually from an FBO), the depth values are stored in the R component of the texture.

Parameters
rectThe quad.
textureThe texture.
widthThe width of the viewer.
heightThe height of the viewer.
depthThe depth at which the quad will be drawn. The depth value is the Normalized Device Coordinates within the range [-1.0, 1.0], corresponding to the near and far clipping planes, respectively.

◆ draw_full_screen_quad() [1/2]

void draw_full_screen_quad ( unsigned int position_attrib,
unsigned int texcoord_attrib,
float depth )

Draws a full screen quad using the bound shader.

It binds the vertex position and UVs arrays to the given attribute array indices and draws the quad.

Parameters
position_attribThe vertex attribute array index that represents position in the current shader.
texcoord_attribThe vertex attribute array index that represents 2D UVs in the current shader.
depthThe depth at which the quad will be drawn. The depth value is the Normalized Device Coordinates within the range [-1.0, 1.0], corresponding to the near and far clipping planes, respectively.

◆ draw_full_screen_quad() [2/2]

void draw_full_screen_quad ( unsigned int texture,
float depth )

Draws a full screen textured quad.

Parameters
textureThe texture.
depthThe depth at which the quad will be drawn. The depth value is the Normalized Device Coordinates within the range [-1.0, 1.0], corresponding to the near and far clipping planes, respectively.

◆ draw_polygon_filled()

void draw_polygon_filled ( const Polygon2 & polygon,
const vec4 & color,
int width,
int height,
float depth )

Draws a filled polygon in the screen space.

Parameters
polygonThe polygon.
colorThe color.
widthThe width of the viewer.
heightThe height of the viewer.
depthThe depth at which the polygon will be drawn. The depth value is the Normalized Device Coordinates within the range [-1.0, 1.0], corresponding to the near and far clipping planes, respectively.

To make the polygon transparent, do the following

glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glDisable(GL_BLEND);
void draw_polygon_filled(const Polygon2 &polygon, const vec4 &color, int width, int height, float depth)
Draws a filled polygon in the screen space.
Definition shape.cpp:492

◆ draw_polygon_wire()

void draw_polygon_wire ( const Polygon2 & polygon,
const vec4 & color,
int width,
int height,
float depth )

Draws a polygon (line loop) in the screen space.

Parameters
polygonThe polygon.
colorThe color.
widthThe width of the viewer.
heightThe height of the viewer.
depthThe depth at which the polygon will be drawn. The depth value is the Normalized Device Coordinates within the range [-1.0, 1.0], corresponding to the near and far clipping planes, respectively.

◆ draw_quad()

void draw_quad ( unsigned int position_attrib,
unsigned int texcoord_attrib,
int x,
int y,
int w,
int h,
int vpw,
int vph,
float depth )

Draws a quad defined in the screen space using a bound shader.

It binds the vertex position and UVs arrays to the given attribute array indices and draws the quad.

Parameters
position_attribThe vertex attribute array index that represents position in the current shader.
texcoord_attribThe vertex attribute array index that represents 2D UVs in the current shader.
xThe x coordinate of the min corner of the quad.
yThe y coordinate of the min corner of the quad.
wThe width of the quad.
hThe height of the quad.
vpwThe width of the viewport (of the viewer).
vphThe height of the viewport (of the viewer).
depthThe depth at which the quad will be drawn. The depth value is the Normalized Device Coordinates within the range [-1.0, 1.0], corresponding to the near and far clipping planes, respectively.

◆ draw_quad_filled() [1/2]

void draw_quad_filled ( const Rect & rect,
const vec4 & color,
int width,
int height,
float depth )

Draws a solid quad defined in the screen space.

Parameters
rectThe quad.
colorThe color.
widthThe width of the viewer.
heightThe height of the viewer.
depthThe depth at which the quad will be drawn. The depth value is the Normalized Device Coordinates within the range [-1.0, 1.0], corresponding to the near and far clipping planes, respectively.

◆ draw_quad_filled() [2/2]

void draw_quad_filled ( const Rect & rect,
unsigned int texture,
int width,
int height,
float depth )

Draws a solid quad defined in the screen space.

Parameters
rectThe quad.
textureThe texture.
widthThe width of the viewer.
heightThe height of the viewer.
depthThe depth at which the quad will be drawn. The depth value is the Normalized Device Coordinates within the range [-1.0, 1.0], corresponding to the near and far clipping planes, respectively.

◆ draw_quad_wire()

void draw_quad_wire ( const Rect & rect,
const vec4 & color,
int width,
int height,
float depth )

Draws a wire quad defined in the screen space.

Parameters
rectThe quad.
colorThe color.
widthThe width of the viewer.
heightThe height of the viewer.
depthThe depth at which the quad will be drawn. The depth value is the Normalized Device Coordinates within the range [-1.0, 1.0], corresponding to the near and far clipping planes, respectively.

◆ draw_sphere_big_circles()

void draw_sphere_big_circles ( LinesDrawable * drawable,
const mat4 & mvp,
const mat4 & m,
bool axes = true )

Draws the outline (the 3 big circles) of a sphere.

Parameters
drawableThe drawable.
mvpThe model view projection matrix.
mThe transformation matrix defining the sphere's location, radius, and orientation.
axestrue will also draw the three main axes.