diff --git a/src/utility.cpp b/src/utility.cpp index 55340cd486302afd6f6d0b40ad6586895a2482b7..83c5c3bb4074025604af7c2aaebf061b2f200c1b 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; +}