Start adding grid
This commit is contained in:
parent
9301769d58
commit
f04d86e0ad
37 changed files with 709 additions and 211 deletions
|
@ -0,0 +1,90 @@
|
|||
#include "MeshPrimitives.h"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
std::unique_ptr<TriMesh> MeshPrimitives::build(const Rectangle& rectangle)
|
||||
{
|
||||
const auto bottom_left = rectangle.getLocation();
|
||||
const auto width = rectangle.getWidth();
|
||||
const auto height = rectangle.getHeight();
|
||||
|
||||
VecPoints locations = {
|
||||
bottom_left,
|
||||
Point(bottom_left, width, 0),
|
||||
Point(bottom_left, width, height),
|
||||
Point(bottom_left, 0, height)
|
||||
};
|
||||
|
||||
EdgeIds edge_ids = {
|
||||
{0, 1},
|
||||
{1, 2},
|
||||
{2, 0},
|
||||
{2, 3},
|
||||
{3, 0}
|
||||
};
|
||||
|
||||
FaceIds face_ids = {
|
||||
{0, 1, 2},
|
||||
{2, 3, 4}
|
||||
};
|
||||
|
||||
return MeshBuilder::buildTriMesh(locations, edge_ids, face_ids);
|
||||
}
|
||||
|
||||
std::unique_ptr<TriMesh> MeshPrimitives::buildExplodedGrid(unsigned numX, unsigned numY)
|
||||
{
|
||||
double delta_x = 1.0/double(numX);
|
||||
double delta_y = 1.0/double(numY);
|
||||
|
||||
VecPoints locations (4 * numX * numY);
|
||||
double offset_x = delta_x;
|
||||
double offset_y = delta_y;
|
||||
for (unsigned idx=0; idx<numY; idx++)
|
||||
{
|
||||
for(unsigned jdx=0; jdx<numX; jdx++)
|
||||
{
|
||||
auto locX0 = offset_x - delta_x/2.0;
|
||||
auto locX1 = offset_x + delta_x/2.0;
|
||||
auto locY0 = offset_y - delta_y/2.0;
|
||||
auto locY1 = offset_y + delta_y/2.0;
|
||||
|
||||
auto id_offset = 4* (jdx + numX*idx);
|
||||
locations[id_offset] = Point(locX0, locY0);
|
||||
locations[id_offset + 1] = Point(locX1, locY0);
|
||||
locations[id_offset + 2] = Point(locX1, locY1);
|
||||
locations[id_offset + 3] = Point(locX0, locY1);
|
||||
offset_x += delta_x;
|
||||
}
|
||||
offset_x = delta_x;
|
||||
offset_y += delta_y;
|
||||
}
|
||||
|
||||
EdgeIds edge_ids(5 * numX * numY);
|
||||
for (unsigned idx=0; idx<numY; idx++)
|
||||
{
|
||||
for(unsigned jdx=0; jdx<numX; jdx++)
|
||||
{
|
||||
unsigned node_offset = 4 * (jdx + numX * idx);
|
||||
auto id_offset = 5* (jdx + numX*idx);
|
||||
edge_ids[id_offset] = {node_offset, node_offset + 1};
|
||||
edge_ids[id_offset + 1] = {node_offset + 1, node_offset + 2};
|
||||
edge_ids[id_offset + 2] = {node_offset + 2, node_offset + 3};
|
||||
edge_ids[id_offset + 3] = {node_offset + 3, node_offset};
|
||||
edge_ids[id_offset + 4] = {node_offset + 2, node_offset};
|
||||
}
|
||||
}
|
||||
|
||||
FaceIds face_ids(2 *numX * numY);
|
||||
for (unsigned idx=0; idx<numY; idx++)
|
||||
{
|
||||
for(unsigned jdx=0; jdx<numX; jdx++)
|
||||
{
|
||||
unsigned edge_offset = 5 * (jdx + numX * idx);
|
||||
unsigned face_offset = 2 * (jdx + numX * idx);
|
||||
face_ids[face_offset] = {edge_offset, edge_offset + 1, edge_offset + 4};
|
||||
face_ids[face_offset + 1] = {edge_offset + 4, edge_offset + 2, edge_offset + 3};
|
||||
}
|
||||
}
|
||||
|
||||
return MeshBuilder::buildTriMesh(locations, edge_ids, face_ids);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue