From 0ee4d84638c3f21efeecc4075229af101f2ea3d6 Mon Sep 17 00:00:00 2001 From: Jessie Speert Date: Mon, 22 Mar 2021 16:20:26 -0700 Subject: Uploading Assignment 5 (and worksheet) --- dev/a5-artrender/edge_mesh.h | 82 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 dev/a5-artrender/edge_mesh.h (limited to 'dev/a5-artrender/edge_mesh.h') diff --git a/dev/a5-artrender/edge_mesh.h b/dev/a5-artrender/edge_mesh.h new file mode 100644 index 0000000..5120d0b --- /dev/null +++ b/dev/a5-artrender/edge_mesh.h @@ -0,0 +1,82 @@ +/** CSci-4611 Assignment 5: Art Render + */ + +#ifndef EDGE_MESH_H +#define EDGE_MESH_H + +#include +using namespace mingfx; + +#include + + +/** 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,int> EdgeMap; + EdgeMap edgeMap; + + void addEdge(std::vector *vertices, + std::vector *normals, + std::vector *leftNormals, + std::vector *rightNormals, + std::vector< std::vector > *triangles, + const Mesh &mesh, int v0, int v1, Vector3 n); + + std::vector verts_; // vertex positions + std::vector norms_; // normals + std::vector indices_; // indices + std::vector leftNorms_; // normals of adjacent triangles + std::vector rightNorms_; + + GLuint vertexBuffer_; + GLuint vertexArray_; + GLuint elementBuffer_; + + bool gpuDirty_; +}; + +#endif + -- cgit v1.2.3