MinGfx Toolkit  1.0
A minimal library for writing cross-platform (Windows, OSX, linux) graphics programs.
quick_shapes.h
Go to the documentation of this file.
1 /*
2  This file is part of the MinGfx Project.
3 
4  Copyright (c) 2017,2018 Regents of the University of Minnesota.
5  All Rights Reserved.
6 
7  Original Author(s) of this File:
8  Dan Keefe, 2017, University of Minnesota
9 
10  Author(s) of Significant Updates/Modifications to the File:
11  ...
12  */
13 
14 #ifndef SRC_QUICK_SHAPES_H_
15 #define SRC_QUICK_SHAPES_H_
16 
17 #include "color.h"
18 #include "default_shader.h"
19 #include "mesh.h"
20 #include "point3.h"
21 #include "shader_program.h"
22 #include "texture2d.h"
23 #include "vector3.h"
24 #include "matrix4.h"
25 
26 #include <vector>
27 
28 
29 
30 namespace mingfx {
31 
69 class QuickShapes {
70 public:
71 
73  virtual ~QuickShapes();
74 
75 
76  // -------- 3D PRIMITIVES --------
77 
81  void DrawCube(const Matrix4 &modelMatrix,
82  const Matrix4 &viewMatrix,
83  const Matrix4 &projectionMatrix,
84  const Color &color);
85 
90  void DrawCylinder(const Matrix4 &modelMatrix,
91  const Matrix4 &viewMatrix,
92  const Matrix4 &projectionMatrix,
93  const Color &color);
94 
99  void DrawCone(const Matrix4 &modelMatrix,
100  const Matrix4 &viewMatrix,
101  const Matrix4 &projectionMatrix,
102  const Color &color);
103 
107  void DrawSphere(const Matrix4 &modelMatrix,
108  const Matrix4 &viewMatrix,
109  const Matrix4 &projectionMatrix,
110  const Color &color);
111 
116  void DrawBrush(const Matrix4 &modelMatrix,
117  const Matrix4 &viewMatrix,
118  const Matrix4 &projectionMatrix,
119  const Color &color);
120 
121 
122  // -------- 3D COMPOSITE SHAPES --------
123 
126  void DrawLineSegment(const Matrix4 &modelMatrix,
127  const Matrix4 &viewMatrix,
128  const Matrix4 &projectionMatrix,
129  const Color &color,
130  const Point3 &p1,
131  const Point3 &p2,
132  float radius);
133 
134  enum class LinesType {
135  LINES,
136  LINE_STRIP,
137  LINE_LOOP
138  };
139 
156  void DrawLines(const Matrix4 &modelMatrix,
157  const Matrix4 &viewMatrix,
158  const Matrix4 &projectionMatrix,
159  const Color &color,
160  const std::vector<Point3> &points,
161  LinesType linesType,
162  float radius);
163 
168  void DrawArrow(const Matrix4 &modelMatrix,
169  const Matrix4 &viewMatrix,
170  const Matrix4 &projectionMatrix,
171  const Color &color,
172  Point3 p, Vector3 dir, float radius);
173 
178  void DrawAxes(const Matrix4 &modelMatrix,
179  const Matrix4 &viewMatrix,
180  const Matrix4 &projectionMatrix);
181 
182 
183  // -------- 2D PRIMITIVES --------
184 
189  void DrawSquare(const Matrix4 &modelMatrix, const Matrix4 &viewMatrix,
190  const Matrix4 &projectionMatrix, const Color &color);
191 
198  void DrawSquare(const Matrix4 &modelMatrix, const Matrix4 &viewMatrix,
199  const Matrix4 &projectionMatrix, const Color &color,
200  const Texture2D &texture);
201 
205  void DrawFullscreenTexture(const Color &color, const Texture2D &texture);
206 
207 
212 
218 
219 
220 private:
221 
222  void DrawWithFullscreen(const Color &color, Mesh *mesh, const Texture2D &tex);
223 
224  Mesh cubeMesh_;
225  void initCube();
226 
227  Mesh squareMesh_;
228  void initSquare();
229 
230  Mesh fullMesh_;
231  void initFull();
232 
233  Mesh cylMesh_;
234  void initCyl();
235 
236  Mesh coneMesh_;
237  void initCone();
238 
239  Mesh sphereMesh_;
240  void initSph();
241 
242  Mesh brushMesh_;
243  void initBrush();
244 
245  DefaultShader defaultShader_;
246  DefaultShader::MaterialProperties defaultMaterial_;
247  Texture2D emptyTex_;
248 
249  ShaderProgram fullscreenShader_;
250 };
251 
252 } // end namespace
253 
254 #endif
Represents a 4-component (R,G,B,A) color, stored internally in a float array to be compatable with Op...
Definition: color.h:41
Small data structure to hold properties of the material to be lit.
A simple GLSL shader for textured per-fragment Phong shading with multiple light sources.
A 4x4 transformation matrix stored internally as an array of floats in column-major order so as to be...
Definition: matrix4.h:50
A triangle mesh data structure that can be rendered with a ShaderProgram like DefaultShader.
Definition: mesh.h:127
A 3D Point with floating point coordinates, used for storing vertices and all sorts of other 3D graph...
Definition: point3.h:52
This class provides a quick way to draw shapes for use in debugging or simple scenes.
Definition: quick_shapes.h:69
void DrawLineSegment(const Matrix4 &modelMatrix, const Matrix4 &viewMatrix, const Matrix4 &projectionMatrix, const Color &color, const Point3 &p1, const Point3 &p2, float radius)
Draws a cylinder between the two points.
void DrawCone(const Matrix4 &modelMatrix, const Matrix4 &viewMatrix, const Matrix4 &projectionMatrix, const Color &color)
Draws a cone with radius 1 and height y=-1 to 1 given the model, view, and projection matrices provid...
virtual ~QuickShapes()
void DrawSquare(const Matrix4 &modelMatrix, const Matrix4 &viewMatrix, const Matrix4 &projectionMatrix, const Color &color)
Draws a square in the X-Y plane with extents -1 to 1 and normal in the +Y direction.
void DrawAxes(const Matrix4 &modelMatrix, const Matrix4 &viewMatrix, const Matrix4 &projectionMatrix)
Draws a right handed set of axes at the coordinate frame specified by the modelMatrix.
void DrawCylinder(const Matrix4 &modelMatrix, const Matrix4 &viewMatrix, const Matrix4 &projectionMatrix, const Color &color)
Draws a cylinder with radius 1 and height y=-1 to 1 given the model, view, and projection matrices pr...
void DrawSquare(const Matrix4 &modelMatrix, const Matrix4 &viewMatrix, const Matrix4 &projectionMatrix, const Color &color, const Texture2D &texture)
Draws a square, which you can deform into some other shape by adjusting the model matrix,...
void DrawSphere(const Matrix4 &modelMatrix, const Matrix4 &viewMatrix, const Matrix4 &projectionMatrix, const Color &color)
Draws a sphere with radius 1 given the model, view, and projection matrices provided and using the su...
DefaultShader * default_shader()
Returns a pointer to the default shader used internally by the Draw class so that you may change the ...
void DrawBrush(const Matrix4 &modelMatrix, const Matrix4 &viewMatrix, const Matrix4 &projectionMatrix, const Color &color)
Draws the classic 3D paintbrush cursor from the 2001 Keefe et al.
void DrawFullscreenTexture(const Color &color, const Texture2D &texture)
Draws a background texture across the whole screen.
DefaultShader::MaterialProperties * material()
Returns a pointer to the default material properties for the shapes so that you may adjust the reflec...
void DrawCube(const Matrix4 &modelMatrix, const Matrix4 &viewMatrix, const Matrix4 &projectionMatrix, const Color &color)
Draws a cube with extents -1 to 1 given the model, view, and projection matrices provided and using t...
void DrawArrow(const Matrix4 &modelMatrix, const Matrix4 &viewMatrix, const Matrix4 &projectionMatrix, const Color &color, Point3 p, Vector3 dir, float radius)
Draws an arrow originating at point p and extending in the direction and length specified by dir.
void DrawLines(const Matrix4 &modelMatrix, const Matrix4 &viewMatrix, const Matrix4 &projectionMatrix, const Color &color, const std::vector< Point3 > &points, LinesType linesType, float radius)
Draws a series of line segments.
A wrapper around GLSL shader programs.
A wrapper around a 2D texture that supports loading images from files or setting texture color data d...
Definition: texture2d.h:42
A 3D Vector with floating point coordinates, used for storing normals and all sorts of other 3D graph...
Definition: vector3.h:62
Namespace for the MinGfx Toolkit.
Definition: aabb.h:21