commit
e783869545
5 changed files with 119 additions and 61 deletions
|
@ -49,6 +49,7 @@ namespace CompFab
|
||||||
|
|
||||||
Vec3iStruct();
|
Vec3iStruct();
|
||||||
Vec3iStruct(int x, int y, int z);
|
Vec3iStruct(int x, int y, int z);
|
||||||
|
Vec3iStruct(int i);
|
||||||
union
|
union
|
||||||
{
|
{
|
||||||
int m_pos[3];
|
int m_pos[3];
|
||||||
|
@ -106,6 +107,14 @@ namespace CompFab
|
||||||
|
|
||||||
Vec3 operator+(const Vec3 & v1, const Vec3 & v2);
|
Vec3 operator+(const Vec3 & v1, const Vec3 & v2);
|
||||||
|
|
||||||
|
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
|
//Cross Product
|
||||||
Vec3 operator%(const Vec3 &v1, const Vec3 &v2);
|
Vec3 operator%(const Vec3 &v1, const Vec3 &v2);
|
||||||
|
|
||||||
|
|
|
@ -48,6 +48,14 @@ CompFab::Vec3iStruct::Vec3iStruct(int x, int y, int z)
|
||||||
m_z = z;
|
m_z = z;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CompFab::Vec3iStruct::Vec3iStruct(int i)
|
||||||
|
{
|
||||||
|
m_x = i;
|
||||||
|
m_y = i;
|
||||||
|
m_z = i;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
CompFab::Vec2fStruct::Vec2fStruct()
|
CompFab::Vec2fStruct::Vec2fStruct()
|
||||||
{
|
{
|
||||||
m_x = m_y = 0.0;
|
m_x = m_y = 0.0;
|
||||||
|
@ -99,9 +107,30 @@ CompFab::Vec3 CompFab::operator+(const Vec3 &v1, const Vec3 &v2)
|
||||||
return v3;
|
return v3;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CompFab::Vec3i CompFab::operator+(const Vec3i &v1, const Vec3i &v2)
|
||||||
|
{
|
||||||
|
Vec3i v3i;
|
||||||
|
v3i[0] = v1[0] + v2[0];
|
||||||
|
v3i[1] = v1[1] + v2[1];
|
||||||
|
v3i[2] = v1[2] + v2[2];
|
||||||
|
|
||||||
|
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
|
//Cross Product
|
||||||
Vec3 CompFab::operator%(const Vec3 &v1, const Vec3 &v2)
|
CompFab::Vec3 CompFab::operator%(const Vec3 &v1, const Vec3 &v2)
|
||||||
{
|
{
|
||||||
Vec3 v3;
|
Vec3 v3;
|
||||||
v3[0] = v1[1]*v2[2] - v1[2]*v2[1];
|
v3[0] = v1[1]*v2[2] - v1[2]*v2[1];
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
#include "PerlinNoise.h"
|
#include "../include/PerlinNoise.h"
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <random>
|
#include <random>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
100
source/main.cpp
100
source/main.cpp
|
@ -63,7 +63,7 @@ void findLW(Mesh &m, double &l, double &w)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Calculate translation matrices and output them as a vector of Vec3s.
|
// Calculate translation matrices and output them as a vector of Vec3s.
|
||||||
std::vector<CompFab::Vec3> createVec3d(int layers, double spacing, double length, double width)
|
std::vector<CompFab::Vec3> createVec3d(std::vector<CompFab::Vec3> &t, int layers, double spacing, double length, double width)
|
||||||
{
|
{
|
||||||
std::vector<CompFab::Vec3> *output = new std::vector<CompFab::Vec3>();
|
std::vector<CompFab::Vec3> *output = new std::vector<CompFab::Vec3>();
|
||||||
|
|
||||||
|
@ -71,36 +71,63 @@ std::vector<CompFab::Vec3> createVec3d(int layers, double spacing, double length
|
||||||
double ws = width + spacing;
|
double ws = width + spacing;
|
||||||
|
|
||||||
// Will be used later to determine the direction of the translation matrix.
|
// Will be used later to determine the direction of the translation matrix.
|
||||||
// This is used to bypass needing to create a rotation matrix.
|
|
||||||
// Should consider doing so anyway to speed up process, use less memory, and add modularization.
|
|
||||||
double angle = 0.0;
|
double angle = 0.0;
|
||||||
|
|
||||||
CompFab::Vec3 *temp = new CompFab::Vec3(-ls, -ws, 0);
|
CompFab::Vec3 *temp = new CompFab::Vec3(-ls, -ws, 0);
|
||||||
|
|
||||||
// Vec3 to hold our current translation matrix.
|
// Vec3 to hold our current translation matrix.
|
||||||
CompFab::Vec3 *trans = new CompFab::Vec3(0, spacing, 0);
|
CompFab::Vec3 *trans = new CompFab::Vec3(ls, ws, 0);
|
||||||
|
|
||||||
|
//Vec3 to hold our current height multiplication materx.
|
||||||
|
CompFab::Vec3 *mult = new CompFab::Vec3(1,1,1);
|
||||||
|
|
||||||
|
//push_back initial templat's mesh, multiplied by the height multiplication matrix.
|
||||||
|
for(int i = 0; i < t.size(); i++)
|
||||||
|
{
|
||||||
|
output->push_back(mmult(*mult, t[i]));
|
||||||
|
}
|
||||||
|
|
||||||
CompFab::Vec3 *coord = new CompFab::Vec3(0.5,0.5,0);
|
CompFab::Vec3 *coord = new CompFab::Vec3(0.5,0.5,0);
|
||||||
|
|
||||||
|
PerlinNoise *p = new PerlinNoise();
|
||||||
|
|
||||||
// cl for current layer.
|
// cl for current layer.
|
||||||
for(int cl = 1; cl < layers; cl++)
|
for(int cl = 1; cl < layers; cl++)
|
||||||
{
|
{
|
||||||
// Constructor used to bypass needing to create a new operator override for multiplication.
|
// Constructor used to re-initialize temp.
|
||||||
// Should also consider doing so anyway to speed up process, use less memory, and add modularization.
|
|
||||||
*temp = CompFab::Vec3(-ls*cl, -ws*cl, 0);
|
*temp = CompFab::Vec3(-ls*cl, -ws*cl, 0);
|
||||||
|
|
||||||
for(int c = 0; c < cl*8; c++)
|
for(int c = 0; c < cl*8; c++)
|
||||||
{
|
{
|
||||||
angle = (c/(2*cl))*(0.5*PI);
|
angle = (c/(2*cl))*(0.5*PI);
|
||||||
*trans = CompFab::Vec3(ls*cos(angle), ws*sin(angle), 0);
|
*trans = CompFab::Vec3(ls*cos(angle), ws*sin(angle), 0);
|
||||||
*temp = *temp + *trans;
|
*temp += *trans;
|
||||||
|
|
||||||
output->push_back(*temp);
|
*coord = *coord + mmult(*trans, CompFab::Vec3((1/(layers*2.0-1)/2.0), (1/(layers*2.0-1)/2.0), 0));
|
||||||
|
|
||||||
*coord = *coord + mmult(trans, Vec3(1/(layers*2-1)/2),1/(layers*2-1)/2,0);
|
// Used to change the multiplciation matrix per layer.
|
||||||
|
mult->m_z = jerfunc(coord->m_x, coord->m_y, *p);
|
||||||
|
|
||||||
|
for(int j = 0; j < t.size(); j++)
|
||||||
|
{
|
||||||
|
output->push_back(mmult(*mult, t[j]) + *temp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
*temp=mmult(temp,Vec3(1,1,n));
|
return *output;
|
||||||
|
}
|
||||||
|
std::vector<CompFab::Vec3i> createVec3id(std::vector<CompFab::Vec3i> &t, std::vector<CompFab::Vec3> &v, int layers)
|
||||||
|
{
|
||||||
|
std::vector<CompFab::Vec3i> *output = new std::vector<CompFab::Vec3i>();
|
||||||
|
*output = t;
|
||||||
|
|
||||||
|
for(int n = 1; n < pow((2*layers - 1), 2); n++)
|
||||||
|
{
|
||||||
|
CompFab::Vec3i *offset = new CompFab::Vec3i(v.size()*n);
|
||||||
|
for(int k = 0; k < t.size(); k++)
|
||||||
|
{
|
||||||
|
output->push_back(t[k] + *offset);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -113,17 +140,26 @@ int main(int argc, char **argv)
|
||||||
// Error checking.
|
// Error checking.
|
||||||
if(argc < 3)
|
if(argc < 3)
|
||||||
{
|
{
|
||||||
std::cout << "Usage: [executable] [template].obj output.obj [optional: -d for debugging output]" << std::endl;
|
std::cout << "Usage: [executable] [template].obj output.obj [mode (-g, etc.)] [optional: -d for debugging output]" << std::endl;
|
||||||
std::exit(1);
|
std::exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Initialization of needed output variables.
|
||||||
|
std::vector<CompFab::Vec3> vv;
|
||||||
|
std::vector<CompFab::Vec3i> tt;
|
||||||
|
Mesh *output = new Mesh();
|
||||||
|
|
||||||
|
// Debugging
|
||||||
|
if(argc > 3)
|
||||||
|
{
|
||||||
|
if(strcmp(argv[3], "-g") == 0 || strcmp(argv[3], "-d") == 0)
|
||||||
|
{
|
||||||
// TODO: Modularize these.
|
// TODO: Modularize these.
|
||||||
int layers = 10;
|
int layers = 10;
|
||||||
double spacing = 1.0;
|
double spacing = 1;
|
||||||
|
|
||||||
// Create Mesh object from file, output to manipulate from template Mesh.
|
// Create Mesh object from file, output to manipulate from template Mesh.
|
||||||
Mesh *test = new Mesh(argv[1], false);
|
Mesh *test = new Mesh(argv[1], false);
|
||||||
Mesh *output = new Mesh(test->v, test->t);
|
|
||||||
|
|
||||||
double l = 0, w = 0;
|
double l = 0, w = 0;
|
||||||
double *length = &l, *width = &w;
|
double *length = &l, *width = &w;
|
||||||
|
@ -131,43 +167,27 @@ int main(int argc, char **argv)
|
||||||
// Find the X and Y dimensions for the mesh. Assumes the mesh is facing upright.
|
// Find the X and Y dimensions for the mesh. Assumes the mesh is facing upright.
|
||||||
findLW(*test, *length, *width);
|
findLW(*test, *length, *width);
|
||||||
|
|
||||||
// Calculate the translation matrices needed.
|
// Calculate the translation matrices needed and apply them.
|
||||||
std::vector<CompFab::Vec3> d = createVec3d(layers, spacing, *length, *width);
|
vv = createVec3d(test->v, layers, spacing, *length, *width);
|
||||||
|
|
||||||
// Duplicating template, will later be replaced with a much more robust procedural generation function.
|
|
||||||
for(int i = 0; i < d.size(); i++)
|
|
||||||
{
|
|
||||||
for(int j = 0; j < test->v.size(); j++)
|
|
||||||
{
|
|
||||||
output->v.push_back(CompFab::Vec3(test->v[j] + d[i]));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Copying needed triangle data.
|
// Copying needed triangle data.
|
||||||
for(int n = 1; n < pow((2*layers - 1), 2); n++)
|
tt = createVec3id(test->t, test->v, layers);
|
||||||
{
|
|
||||||
int offset = test->v.size()*n;
|
// Using contructor to create new output Mesh.
|
||||||
for(int k = 0; k < test->t.size(); k++)
|
*output = Mesh(vv, tt);
|
||||||
{
|
|
||||||
output->t.push_back(CompFab::Vec3i(test->t[k].m_x +offset, test->t[k].m_y + offset, test->t[k].m_z + offset));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Debugging
|
if(strcmp(argv[argc - 1], "-d") == 0)
|
||||||
if(argc > 3)
|
|
||||||
{
|
{
|
||||||
|
|
||||||
// {
|
|
||||||
for(int j = 0; j < output->v.size(); j++)
|
for(int j = 0; j < output->v.size(); j++)
|
||||||
{
|
{
|
||||||
std::cout << output->v[j].m_x << " " << output->v[j].m_y << " " << output->v[j].m_z << std::endl;
|
std::cout << output->v[j].m_x << " " << output->v[j].m_y << " " << output->v[j].m_z << std::endl;
|
||||||
std::cout << output->t[j].m_x << " " << output->t[j].m_y << " " << output->t[j].m_z << std::endl;
|
}
|
||||||
std::cout << std::endl;
|
std::cout << std::endl;
|
||||||
}
|
for(int k = 0; k < output->t.size(); k++)
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
std::cout << "Usage: [executable] [template].obj output.obj [optional: -d for debugging output]" << std::endl;
|
std::cout << output->t[k].m_x << " " << output->t[k].m_y << " " << output->t[k].m_z << std::endl;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <exception>
|
#include <exception>
|
||||||
|
|
||||||
#include "ppm.h"
|
#include "../include/ppm.h"
|
||||||
|
|
||||||
//init with default values
|
//init with default values
|
||||||
|
|
||||||
|
|
Reference in a new issue