15 this->varWidth()->setRange(0.01, 10.0f);
16 this->varHeight()->setRange(0.01, 10.0f);
18 this->stateOutline()->setDataPtr(std::make_shared<EdgeSet>());
20 auto callback = std::make_shared<FCallBackFunc>(std::bind(&SquareEmitter::tranformChanged,
this));
22 this->varLocation()->attach(callback);
23 this->varScale()->attach(callback);
24 this->varRotation()->attach(callback);
26 this->varWidth()->attach(callback);
27 this->varHeight()->attach(callback);
30 SquareEmitter::~SquareEmitter()
34 void SquareEmitter::generateParticles()
36 auto sampling_distance = this->varSamplingDistance()->getData();
38 if (sampling_distance < EPSILON)
39 sampling_distance = 0.005f;
41 auto center = this->varLocation()->getData();
42 auto scale = this->varScale()->getData();
44 auto quat = this->computeQuaternion();
46 Transform<float, 3> tr(center,
quat.toMatrix3x3(), scale);
48 std::vector<Vec3f> pos_list;
49 std::vector<Vec3f> vel_list;
51 Vec3f v0 = this->varVelocityMagnitude()->getData()*
quat.rotate(
Vec3f(0, -1, 0));
53 auto w = 0.5 * this->varWidth()->getData();
54 auto h = 0.5 * this->varHeight()->getData();
56 for (
float x = -w; x <= w; x += sampling_distance)
58 for (
float z = -h; z <= h; z += sampling_distance)
63 pos_list.push_back(tr * p);
64 vel_list.push_back(v0);
69 if (pos_list.size() > 0)
71 this->mPosition.resize(pos_list.size());
72 this->mVelocity.resize(pos_list.size());
74 this->mPosition.assign(pos_list);
75 this->mVelocity.assign(vel_list);
83 void SquareEmitter::tranformChanged()
85 std::vector<Vec3f> vertices;
86 std::vector<TopologyModule::Edge> edges;
88 auto center = this->varLocation()->getData();
89 auto scale = this->varScale()->getData();
91 auto quat = this->computeQuaternion();
93 auto w = this->varWidth()->getData();
94 auto h = this->varHeight()->getData();
96 Transform<float, 3> tr(Coord(0),
quat.toMatrix3x3(), scale);
98 auto Nx = tr *
Vec3f(0.5 * w, 0, 0);
99 auto Nz = tr *
Vec3f(0, 0, 0.5 * h);
101 vertices.push_back(center + Nx + Nz);
102 vertices.push_back(center + Nx - Nz);
103 vertices.push_back(center - Nx - Nz);
104 vertices.push_back(center - Nx + Nz);
106 edges.push_back(TopologyModule::Edge(0, 1));
107 edges.push_back(TopologyModule::Edge(1, 2));
108 edges.push_back(TopologyModule::Edge(2, 3));
109 edges.push_back(TopologyModule::Edge(3, 0));
111 auto edgeTopo = this->stateOutline()->getDataPtr();
113 edgeTopo->setPoints(vertices);
114 edgeTopo->setEdges(edges);
120 void SquareEmitter::resetStates()
#define IMPLEMENT_CLASS(name)
This is an implementation of AdditiveCCD based on peridyno.
TEMPLATE_TYPENAME_T MAT4_T scale(MAT4_T const &m, VEC3_T const &v)