AGL
A graphics library
teapot.h
1 // Copyright 2020, Savvy Sine, Aline Normoyle
2 
3 #ifndef AGL_MESH_TEAPOT_H_
4 #define AGL_MESH_TEAPOT_H_
5 
6 #include "agl/mesh/triangle_mesh.h"
7 #include <vector>
8 #include <glm/glm.hpp>
9 
10 namespace agl {
11 
15 class Teapot : public TriangleMesh {
16  public:
27  Teapot(int grid, const glm::mat4& lidTransform);
28 
29  protected:
30  void init() override;
31 
32  private:
33  int _grid;
34  glm::mat4 _lidTransform;
35 
36  // From: OpenGL 4.0 Shading language cookbook (David Wolf 2011)
37  void generatePatches(std::vector<GLfloat> & p,
38  std::vector<GLfloat> & n,
39  std::vector<GLfloat> & tc,
40  std::vector<GLuint> & el, int grid);
41 
42  void buildPatchReflect(int patchNum,
43  std::vector<GLfloat> & B, std::vector<GLfloat> & dB,
44  std::vector<GLfloat> & v, std::vector<GLfloat> & n,
45  std::vector<GLfloat> & tc, std::vector<GLuint> & el,
46  int &index, int &elIndex, int &tcIndex, int grid,
47  bool reflectX, bool reflectY);
48 
49  void buildPatch(glm::vec3 patch[][4],
50  std::vector<GLfloat> & B, std::vector<GLfloat> & dB,
51  std::vector<GLfloat> & v, std::vector<GLfloat> & n,
52  std::vector<GLfloat> & tc, std::vector<GLuint> & el,
53  int &index, int &elIndex, int &tcIndex, int grid,
54  glm::mat3 reflect, bool invertNormal);
55 
56  void getPatch(int patchNum, glm::vec3 patch[][4], bool reverseV);
57 
58  void computeBasisFunctions(std::vector<GLfloat> & B,
59  std::vector<GLfloat>& dB, int grid);
60 
61  glm::vec3 evaluate(int gridU, int gridV, std::vector<GLfloat> & B,
62  glm::vec3 patch[][4]);
63 
64  glm::vec3 evaluateNormal(int gridU, int gridV, std::vector<GLfloat>& B,
65  std::vector<GLfloat> & dB, glm::vec3 patch[][4]);
66 
67  void fitUnitBox(std::vector<GLfloat>& p, std::vector<GLfloat>& n);
68 
69  void moveLid(int grid, std::vector<GLfloat>& p,
70  const glm::mat4& lidTransform);
71 
72 };
73 
74 } // namespace agl
75 #endif // AGL_MESH_TEAPOT_H_
agl::Teapot
Draw a teapot mesh.
Definition: teapot.h:15
agl::Teapot::init
void init() override
Override init to specifiy vertex data for the mesh.
Definition: teapot.cpp:18
agl::TriangleMesh
Base class for indexed triangle meshes.
Definition: triangle_mesh.h:16
agl::Teapot::Teapot
Teapot(int grid, const glm::mat4 &lidTransform)
Create a Teapot mesh.
Definition: teapot.cpp:13