Added matrix and scalar multiplications and height modification.

This commit is contained in:
Alex 2016-11-28 19:49:37 -06:00
parent 71ffe9df12
commit db17de29f4
3 changed files with 31 additions and 5 deletions

View file

@ -109,6 +109,12 @@ namespace CompFab
Vec3i operator+(const Vec3i & v1, const Vec3i & v2);
//Matrix multiplication
Vec3 mmult(const Vec3 & v1, const Vec3 & v2);
//Scalar multiplication
Vec3 smult(double s, const Vec3 & v);
//Cross Product
Vec3 operator%(const Vec3 &v1, const Vec3 &v2);

View file

@ -117,9 +117,20 @@ CompFab::Vec3i CompFab::operator+(const Vec3i &v1, const Vec3i &v2)
return v3i;
}
//Matrix multiplication
CompFab::Vec3 CompFab::mmult(const Vec3& v1, const Vec3& v2)
{
return Vec3(v1.m_x*v2.m_x, v1.m_y*v2.m_y, v1.m_z*v2.m_z);
}
//Scalar multiplication
CompFab::Vec3 CompFab::smult(double s, const Vec3 & v)
{
return mmult(CompFab::Vec3(s,s,s), v);
}
//Cross Product
Vec3 CompFab::operator%(const Vec3 &v1, const Vec3 &v2)
CompFab::Vec3 CompFab::operator%(const Vec3 &v1, const Vec3 &v2)
{
Vec3 v3;
v3[0] = v1[1]*v2[2] - v1[2]*v2[1];

View file

@ -55,7 +55,14 @@ std::vector<CompFab::Vec3> createVec3d(std::vector<CompFab::Vec3> &t, int layers
// Vec3 to hold our current translation matrix.
CompFab::Vec3 *trans = new CompFab::Vec3(0, spacing, 0);
*output = t;
//Vec3 to hold our current height multiplier.
CompFab::Vec3 *mult = new CompFab::Vec3(1,1,1);
for(int i = 0; i < t.size(); i++)
{
output->push_back(mmult(*mult, t[i]));
}
// cl for current layer.
for(int cl = 1; cl < layers; cl++)
@ -63,6 +70,8 @@ std::vector<CompFab::Vec3> createVec3d(std::vector<CompFab::Vec3> &t, int layers
// Constructor used to bypass needing to create a new operator override for multiplication.
// Should also consider doing so anyway to speed up process, use less memory, and add modularization.
*temp = CompFab::Vec3(-ls*cl, -ws*cl, 0);
mult->m_z = 1.0 - (cl*1.0)/layers;
for(int c = 0; c < cl*8; c++)
{
@ -71,7 +80,7 @@ std::vector<CompFab::Vec3> createVec3d(std::vector<CompFab::Vec3> &t, int layers
*temp += *trans;
for(int j = 0; j < t.size(); j++)
{
output->push_back(t[j] + *temp);
output->push_back(mmult(*mult, t[j]) + *temp);
}
}
}
@ -106,8 +115,8 @@ int main(int argc, char **argv)
}
// TODO: Modularize these.
int layers = 5;
double spacing = 1;
int layers = 10;
double spacing = 0.5;
// Create Mesh object from file, output to manipulate from template Mesh.
Mesh *test = new Mesh(argv[1], false);