Easy3D 2.5.3
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. More...
 
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. More...
 
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. More...
 
void draw_full_screen_quad (unsigned int texture, float depth)
 Draws a full screen textured quad. More...
 
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. More...
 
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. More...
 
void draw_full_screen_quad (unsigned int position_attrib, unsigned int texcoord_attrib, float depth)
 Draws a full screen quad using the bound shader. More...
 
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. More...
 
void draw_polygon_filled (const Polygon2 &polygon, const vec4 &color, int width, int height, float depth)
 Draws a filled polygon in the screen space. More...
 
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. More...
 
void draw_box_wire (LinesDrawable *drawable, const mat4 &mvp, const mat4 &m, bool abstracted=false)
 Draws a box. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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. s is the base center and t is the tip.
 
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. More...
 
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. More...
 
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. More...
 

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
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
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
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
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
color1and color2: the two interchanging colors

◆ 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
slices.The number of subdivisions.

◆ 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.
scaleThe scaling factor
pointsThe points to be returned.

◆ 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
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).
Examples
Tutorial_203_Viewer_wxWidgets, and Tutorial_204_Viewer_Qt.

◆ 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.
(x,y)The position (i.e., min corner) of the quad.
(w,h)The size (i.e., width and height) of the quad.
(vpw,vph)The size (i.e., width and 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.