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