From 4798912da3fe8f2b539866f2c7269d5945db247e Mon Sep 17 00:00:00 2001 From: Pascal Engeler <engelerp@phys.ethz.ch> Date: Sun, 29 May 2022 18:58:20 +0200 Subject: [PATCH] Added array functions, scale calculation function --- src/utility.cpp | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/src/utility.cpp b/src/utility.cpp index 55340cd..83c5c3b 100644 --- a/src/utility.cpp +++ b/src/utility.cpp @@ -34,4 +34,36 @@ std::array<double, 3> extract_triplet(const std::string& str_in, size_t& start) unsigned ij2index(unsigned i, unsigned j, unsigned Ny) { return i * Ny + j; -} \ No newline at end of file +} + + +std::array<float, 3> operator+=(std::array<float, 3>& lhs, const std::array<float, 3>& rhs){ + lhs[0] += rhs[0]; + lhs[1] += rhs[1]; + lhs[2] += rhs[2]; + + return lhs; +} + +std::array<float, 3> cross(const std::array<float, 3>& v, const std::array<float, 3>& w){ + std::array<float, 3> cp; + cp[0] = v[1]*w[2] - v[2]*w[1]; + cp[1] = v[2]*w[0] - v[0]*w[2]; + cp[2] = v[0]*w[1] - v[1]*w[0]; + + return cp; +} + +std::array<float, 3> operator/=(std::array<float, 3>& v, const float d){ + v[0] /= d; + v[1] /= d; + v[2] /= d; + + return v; +} + +glm::mat4 scale_z(float z0, float factor){ + glm::mat4 transf (1.f); + glm::mat4 transf = glm::translate(glm::scale(glm::translate(transf, glm::vec3(0.f,0.f,-z0)), glm::vec3(1.,1.,factor)), glm::vec3(0.,0.,z0)); + return transf; +} -- GitLab