diff options
author | sotech117 <michael_foiani@brown.edu> | 2024-04-09 03:14:17 -0400 |
---|---|---|
committer | sotech117 <michael_foiani@brown.edu> | 2024-04-09 03:14:17 -0400 |
commit | 7a8d0d8bc2572707c9d35006f30ea835c86954b0 (patch) | |
tree | dedb9a65c1698202ad485378b4186b667008abe5 /src/graphics/shape.h | |
parent | 818324678bd5dca790c57048e5012d2937a4b5e5 (diff) |
first draft to generate waves
Diffstat (limited to 'src/graphics/shape.h')
-rw-r--r-- | src/graphics/shape.h | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/src/graphics/shape.h b/src/graphics/shape.h new file mode 100644 index 0000000..3ba81fb --- /dev/null +++ b/src/graphics/shape.h @@ -0,0 +1,72 @@ +#pragma once + +#include <GL/glew.h> +#include <vector> +#include <unordered_set> + +#define EIGEN_DONT_VECTORIZE +#define EIGEN_DISABLE_UNALIGNED_ARRAY_ASSERT +#include "Eigen/StdVector" +EIGEN_DEFINE_STL_VECTOR_SPECIALIZATION(Eigen::Matrix2f) +EIGEN_DEFINE_STL_VECTOR_SPECIALIZATION(Eigen::Matrix3f) +EIGEN_DEFINE_STL_VECTOR_SPECIALIZATION(Eigen::Matrix3i) +#include "Eigen/Dense" + +enum SelectMode +{ + None = 0, + Anchor = 1, + Unanchor = 2 +}; + +class Shader; + +class Shape +{ +public: + Shape(); + + void init(const std::vector<Eigen::Vector3f> &vertices, const std::vector<Eigen::Vector3i> &triangles); + void setVertices(const std::vector<Eigen::Vector3f> &vertices); + + void setModelMatrix(const Eigen::Affine3f &model); + + void draw(Shader *shader, GLenum mode); + SelectMode select(Shader *shader, int vertex); + bool selectWithSpecifiedMode(Shader *shader, int vertex, SelectMode mode); + int getClosestVertex(Eigen::Vector3f start, Eigen::Vector3f ray, float threshold); + bool getAnchorPos(int lastSelected, Eigen::Vector3f& pos, Eigen::Vector3f ray, Eigen::Vector3f start); + + const std::vector<Eigen::Vector3f>& getVertices(); + const std::vector<Eigen::Vector3i>& getFaces(); + const std::unordered_set<int>& getAnchors(); + +private: + GLuint m_surfaceVao; + GLuint m_surfaceVbo; + GLuint m_surfaceIbo; + + unsigned int m_numSurfaceVertices; + unsigned int m_verticesSize; + float m_red; + float m_blue; + float m_green; + float m_alpha; + + std::vector<Eigen::Vector3i> m_faces; + std::vector<Eigen::Vector3f> m_vertices; + std::unordered_set<int> m_anchors; + + Eigen::Matrix4f m_modelMatrix; + int lastSelected = -1; + + // Helpers + + void selectHelper(); + Eigen::Vector3f getNormal(const Eigen::Vector3i& face); + void updateMesh(const std::vector<Eigen::Vector3i> &triangles, + const std::vector<Eigen::Vector3f> &vertices, + std::vector<Eigen::Vector3f>& verts, + std::vector<Eigen::Vector3f>& normals, + std::vector<Eigen::Vector3f>& colors); +}; |