PeriDyno 1.0.0
Loading...
Searching...
No Matches
SquareEmitter.cpp
Go to the documentation of this file.
1#include "SquareEmitter.h"
3
4#include <time.h>
5
6#include <stdlib.h>
7
8namespace dyno
9{
10 template<typename TDataType>
12 : ParticleEmitter<TDataType>()
13 {
14 srand(time(0));
15
16 this->varWidth()->setRange(0.01, 10.0f);
17 this->varHeight()->setRange(0.01, 10.0f);
18
19 this->stateOutline()->setDataPtr(std::make_shared<EdgeSet<TDataType>>());
20
21 auto callback = std::make_shared<FCallBackFunc>(std::bind(&SquareEmitter<TDataType>::tranformChanged, this));
22
23 this->varLocation()->attach(callback);
24 this->varScale()->attach(callback);
25 this->varRotation()->attach(callback);
26
27 this->varWidth()->attach(callback);
28 this->varHeight()->attach(callback);
29
30 auto wireRender = std::make_shared<GLWireframeVisualModule>();
31 wireRender->setColor(Color(0, 1, 0));
32 this->stateOutline()->connect(wireRender->inEdgeSet());
33 this->graphicsPipeline()->pushModule(wireRender);
34 }
35
36 template<typename TDataType>
40
41 template<typename TDataType>
43 {
44 auto sampling_distance = this->varSamplingDistance()->getData();
45
46 if (sampling_distance < EPSILON)
47 sampling_distance = Real(0.005);
48
49 auto center = this->varLocation()->getData();
50 auto scale = this->varScale()->getData();
51
52 auto quat = this->computeQuaternion();
53
54 Transform<Real, 3> tr(center, quat.toMatrix3x3(), scale);
55
56 std::vector<Coord> pos_list;
57 std::vector<Coord> vel_list;
58
59 Coord v0 = this->varVelocityMagnitude()->getData()*quat.rotate(Vec3f(0, -1, 0));
60
61 auto w = 0.5 * this->varWidth()->getData();
62 auto h = 0.5 * this->varHeight()->getData();
63
64 for (Real x = -w; x <= w; x += sampling_distance)
65 {
66 for (Real z = -h; z <= h; z += sampling_distance)
67 {
68 Coord p = Coord(x, 0, z);
69 //if (rand() % 5 == 0)
70 {
71 pos_list.push_back(tr * p);
72 vel_list.push_back(v0);
73 }
74 }
75 }
76
77 if (pos_list.size() > 0)
78 {
79 this->mPosition.resize(pos_list.size());
80 this->mVelocity.resize(pos_list.size());
81
82 this->mPosition.assign(pos_list);
83 this->mVelocity.assign(vel_list);
84 }
85
86
87 pos_list.clear();
88 vel_list.clear();
89 }
90
91 template<typename TDataType>
93 {
94 std::vector<Coord> vertices;
95 std::vector<TopologyModule::Edge> edges;
96
97 auto center = this->varLocation()->getData();
98 auto scale = this->varScale()->getData();
99
100 auto quat = this->computeQuaternion();
101
102 auto w = this->varWidth()->getData();
103 auto h = this->varHeight()->getData();
104
105 Transform<Real, 3> tr(Coord(0), quat.toMatrix3x3(), scale);
106
107 auto Nx = tr * Coord(0.5 * w, 0, 0);
108 auto Nz = tr * Coord(0, 0, 0.5 * h);
109
110 vertices.push_back(center + Nx + Nz);
111 vertices.push_back(center + Nx - Nz);
112 vertices.push_back(center - Nx - Nz);
113 vertices.push_back(center - Nx + Nz);
114
115 edges.push_back(TopologyModule::Edge(0, 1));
116 edges.push_back(TopologyModule::Edge(1, 2));
117 edges.push_back(TopologyModule::Edge(2, 3));
118 edges.push_back(TopologyModule::Edge(3, 0));
119
120 auto edgeTopo = this->stateOutline()->getDataPtr();
121
122 edgeTopo->setPoints(vertices);
123 edgeTopo->setEdges(edges);
124
125 vertices.clear();
126 edges.clear();
127 }
128
129
130 template<typename TDataType>
137
139}
#define DEFINE_CLASS(name)
Definition Object.h:140
double Real
Definition Typedef.inl:23
std::shared_ptr< GraphicsPipeline > graphicsPipeline()
Definition Node.cpp:320
Quat< Real > computeQuaternion()
void resetStates() override
DArray< Coord > mVelocity
DArray< Coord > mPosition
void resetStates() override
void generateParticles() override
TDataType::Coord Coord
TDataType::Real Real
VectorND< PointType, 2 > Edge
This is an implementation of AdditiveCCD based on peridyno.
Definition Array.h:25
constexpr Real EPSILON
Definition Typedef.inl:42
Vector< float, 3 > Vec3f
Definition Vector3D.h:93
vgm::Quat quat
Definition vgMath.h:633