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