Skip to content
Snippets Groups Projects
Commit d2136abf authored by Pascal Engeler's avatar Pascal Engeler
Browse files

More vec3 operations

parent 7e30070a
No related branches found
No related tags found
No related merge requests found
......@@ -26,10 +26,16 @@ unsigned ij2index(unsigned i, unsigned j, unsigned Ny);
std::array<float, 3> operator+=(std::array<float, 3>&, const std::array<float, 3>&);
std::array<float, 3> operator-(std::array<float, 3>, const std::array<float, 3>&);
std::array<float, 3> cross(const std::array<float, 3>&, const std::array<float, 3>&);
std::array<float, 3> operator/=(std::array<float, 3>&, const float);
float length(const std::array<float, 3>&);
std::array<float, 3> normal(const std::array<float, 3>&, const std::array<float, 3>&, const std::array<float, 3>&);
glm::mat4 scale_z(float z0, float factor);
......
......@@ -45,6 +45,13 @@ std::array<float, 3> operator+=(std::array<float, 3>& lhs, const std::array<floa
return lhs;
}
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];
......@@ -62,6 +69,18 @@ std::array<float, 3> operator/=(std::array<float, 3>& v, const float d){
return v;
}
float length(const std::array<float, 3>& v) {
return std::sqrt(v[0] * v[0] + v[1] * v[1] + v[2] * v[2]);
}
std::array<float, 3> normal(const std::array<float, 3>& p1, const std::array<float, 3>& p2, const std::array<float, 3>& p3) {
std::array<float, 3> v1 = p2 - p1;
std::array<float, 3> v2 = p3 - p1;
std::array<float, 3> crs = cross(v1, v2);
crs /= length(crs);
return crs;
}
glm::mat4 scale_z(float z0, float factor){
glm::mat4 transf (1.f);
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));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment