summaryrefslogtreecommitdiffstats
path: root/dev/a6-harold/edge_mesh.h
diff options
context:
space:
mode:
authorMatt Strapp <matt@mattstrapp.net>2021-12-17 13:17:58 -0600
committerMatt Strapp <matt@mattstrapp.net>2021-12-17 13:17:58 -0600
commite0a8f6b97c473d28af96f28ca6b46d41b91646a3 (patch)
tree8faef1da18b809c9585c11ba5917f1f8268cddf6 /dev/a6-harold/edge_mesh.h
parentAdd README (diff)
parentClarify how to get eye point in Sky::ScreenPtHitsSky (diff)
downloadcsci4611-e0a8f6b97c473d28af96f28ca6b46d41b91646a3.tar
csci4611-e0a8f6b97c473d28af96f28ca6b46d41b91646a3.tar.gz
csci4611-e0a8f6b97c473d28af96f28ca6b46d41b91646a3.tar.bz2
csci4611-e0a8f6b97c473d28af96f28ca6b46d41b91646a3.tar.lz
csci4611-e0a8f6b97c473d28af96f28ca6b46d41b91646a3.tar.xz
csci4611-e0a8f6b97c473d28af96f28ca6b46d41b91646a3.tar.zst
csci4611-e0a8f6b97c473d28af96f28ca6b46d41b91646a3.zip
Merge branch 'support-code' of https://github.umn.edu/umn-csci-4611-f21/shared-upstream
Diffstat (limited to 'dev/a6-harold/edge_mesh.h')
-rw-r--r--dev/a6-harold/edge_mesh.h82
1 files changed, 82 insertions, 0 deletions
diff --git a/dev/a6-harold/edge_mesh.h b/dev/a6-harold/edge_mesh.h
new file mode 100644
index 0000000..5120d0b
--- /dev/null
+++ b/dev/a6-harold/edge_mesh.h
@@ -0,0 +1,82 @@
+/** CSci-4611 Assignment 5: Art Render
+ */
+
+#ifndef EDGE_MESH_H
+#define EDGE_MESH_H
+
+#include <mingfx.h>
+using namespace mingfx;
+
+#include <vector>
+
+
+/** This special kind of mesh stores two triangles that form a quadralateral
+ along each edge of an existing mesh. The quad initially has a width=0, but
+ when rendered, two of the vertices are extended along the surfaces normal
+ direction, which creates a "fin" that can be drawn as a thick border. This
+ can be used to create a silhouette edge renderer if the shader only extends
+ the edges that lie along a silhouette of the mesh.
+ */
+class EdgeMesh {
+public:
+ EdgeMesh();
+ virtual ~EdgeMesh();
+
+ /// Creates two triangles along each edge of the mesh passed in.
+ void CreateFromMesh(const Mesh &mesh);
+
+ /// Saves the mesh data to the GPU - must be called with InitOpenGL or Draw.
+ void UpdateGPUMemory();
+
+ /// Num vertices in the edge mesh
+ int num_vertices() const;
+
+ /// Num triangles in the edge mesh
+ int num_triangles() const;
+
+ /// Access to vertex position by vertex number
+ Point3 vertex(int vertexID) const;
+
+ /// Access to vertex normal by vertex number
+ Vector3 normal(int vertexID) const;
+
+ /// Access to vertex color by vertex number
+ Color color(int vertexID) const;
+
+ /// Access to vertex texture coords by vertex number
+ Point2 tex_coords(int textureUnit, int vertexID) const;
+
+
+ /// Draws the mesh assuming a shader has already been bound.
+ void Draw();
+
+private:
+
+ // Some routines and variables are needed internally to construct the edge
+ // mesh from a regular mesh.
+
+ typedef std::map<std::pair<int,int>,int> EdgeMap;
+ EdgeMap edgeMap;
+
+ void addEdge(std::vector<Point3> *vertices,
+ std::vector<Vector3> *normals,
+ std::vector<Vector3> *leftNormals,
+ std::vector<Vector3> *rightNormals,
+ std::vector< std::vector<unsigned int> > *triangles,
+ const Mesh &mesh, int v0, int v1, Vector3 n);
+
+ std::vector<float> verts_; // vertex positions
+ std::vector<float> norms_; // normals
+ std::vector<unsigned int> indices_; // indices
+ std::vector<float> leftNorms_; // normals of adjacent triangles
+ std::vector<float> rightNorms_;
+
+ GLuint vertexBuffer_;
+ GLuint vertexArray_;
+ GLuint elementBuffer_;
+
+ bool gpuDirty_;
+};
+
+#endif
+