Skylicht Engine
Loading...
Searching...
No Matches
CParticleTrail.h
1/*
2!@
3MIT License
4
5Copyright (c) 2020 Skylicht Technology CO., LTD
6
7Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files
8(the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify,
9merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
10subject to the following conditions:
11
12The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
13
14THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
15INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
16IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
17WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
19
20This file is part of the "Skylicht Engine".
21https://github.com/skylicht-lab/skylicht-engine
22!#
23*/
24
25#pragma once
26
27#include "CGroup.h"
28
29namespace Skylicht
30{
31 class CCamera;
32
33 namespace Particle
34 {
36
38 {
39 core::vector3df Position;
40 float Width;
41 float Alpha;
42 };
43
44 struct STrailInfo
45 {
47 core::vector3df CurrentPosition;
48 core::vector3df LastPosition;
49 video::SColor CurrentColor;
50 int Flag;
51
52 STrailInfo()
53 {
54 Flag = 0;
55 Position = NULL;
56 }
57
58 void InitData()
59 {
60 Position = new core::array<SParticlePosition>();
61 }
62
63 void DeleteData()
64 {
65 if (Position)
66 {
67 delete Position;
68 Position = NULL;
69 }
70 }
71
72 void Copy(const STrailInfo& t)
73 {
74 CurrentPosition = t.CurrentPosition;
75 LastPosition = t.LastPosition;
76 CurrentColor = t.CurrentColor;
77 Flag = t.Flag;
78 *Position = *t.Position;
79 }
80 };
81
82 class COMPONENT_API CParticleTrail : public IParticleCallback
83 {
84 friend class CParticleTrailComponent;
85
86 protected:
89
91 std::wstring m_name;
92
95
98
101
104
107
109 float m_width;
110
112 float m_length;
113
116
119
122
124 std::string m_texturePath;
125
128
131
134
137
140
143
146
149
150 public:
151 CParticleTrail(CGroup* group);
152
153 virtual ~CParticleTrail();
154
156 virtual void update(CCamera* camera);
157
159 virtual void OnParticleUpdate(CParticle* particles, int num, CGroup* group, float dt);
160
162 virtual void OnParticleBorn(CParticle& p);
163
165 virtual void OnParticleDead(CParticle& p);
166
168 virtual void OnSwapParticleData(CParticle& p1, CParticle& p2);
169
171 virtual void OnGroupDestroy();
172
175 {
176 return m_meshBuffer;
177 }
178
181 {
182 return m_material;
183 }
184
186 inline void setWidth(float f)
187 {
188 m_width = f;
189 }
190
192 inline float getWidth()
193 {
194 return m_width;
195 }
196
198 inline void setSegmentLength(float f)
199 {
200 m_segmentLength = f;
201 }
202
204 inline float getSegmentLength()
205 {
206 return m_segmentLength;
207 }
208
211 {
213 }
214
217 {
219 }
220
223 {
225 }
226
228 inline void setDeadAlphaReduction(float a)
229 {
231 }
232
234 inline void enableCustomMaterial(bool b)
235 {
237 }
238
240 inline void setCustomMaterial(CMaterial* material)
241 {
242 m_customMaterial = material;
243 }
244
246 inline bool useCustomMaterial()
247 {
248 return m_useCustomMaterial;
249 }
250
252 inline const char* getCustomMaterial()
253 {
255 return m_customMaterial->getMaterialPath();
256 return "";
257 }
258
260 inline const wchar_t* getGroupName()
261 {
262 if (m_group)
263 return m_group->Name.c_str();
264 return m_name.c_str();
265 }
266
268 void setLength(float l);
269
271 inline float getLength()
272 {
273 return m_length;
274 }
275
277 void setTexture(ITexture* texture);
278
281
283 void setTexturePath(const char* path);
284
286 inline const char* getTexturePath()
287 {
288 return m_texturePath.c_str();
289 }
290
292 inline void setEmission(bool b)
293 {
294 m_emission = b;
295 }
296
298 inline bool isEmission()
299 {
300 return m_emission;
301 }
302
304 inline void setEmissionIntensity(float f)
305 {
307 }
308
310 inline float getEmissionIntensity()
311 {
312 return m_emissionIntensity;
313 }
314
316 inline void setBillboard(bool b)
317 {
318 m_billboard = b;
319 }
320
322 inline bool isBillboard()
323 {
324 return m_billboard;
325 }
326
328 inline void setUpVector(const core::vector3df& up)
329 {
330 m_upVector = up;
331 }
332
335 {
336 return m_upVector;
337 }
338
339 protected:
340
343
345 void setWorld(const core::matrix4& world)
346 {
347 m_world = world;
348 }
349
350 };
351 }
352}
This is an object class used to set up the camera, including its position, viewing angle,...
Definition CCamera.h:70
The object class describes material information such as which shader it's associated with,...
Definition CMaterial.h:84
Represents a group of particles with shared settings, emitters, and a renderer.
Definition CGroup.h:132
Individual particle data structure.
Definition CParticle.h:65
Component for adding ribbon/trail effects to particles.
Definition CParticleTrailComponent.h:55
u32 m_trailCount
Current count of active trails.
Definition CParticleTrail.h:115
core::matrix4 m_world
Local-to-world transform.
Definition CParticleTrail.h:136
float m_emissionIntensity
Emission intensity multiplier.
Definition CParticleTrail.h:142
void setTexturePath(const char *path)
Loads ribbon texture by path.
void setWorld(const core::matrix4 &world)
Internal: sets world matrix.
Definition CParticleTrail.h:345
const core::vector3df & getUpVector()
Gets custom up vector.
Definition CParticleTrail.h:334
virtual void update(CCamera *camera)
Updates ribbon geometry based on particle history and camera position.
float m_length
Total trail length in units.
Definition CParticleTrail.h:112
const char * getTexturePath()
Gets ribbon texture path.
Definition CParticleTrail.h:286
bool isEmission()
Checks if emission is enabled.
Definition CParticleTrail.h:298
virtual void OnParticleUpdate(CParticle *particles, int num, CGroup *group, float dt)
Callback: records new particle positions into trails.
CMaterial * getMaterial()
Gets active material.
Definition CParticleTrail.h:180
bool isBillboard()
Checks if billboarding is enabled.
Definition CParticleTrail.h:322
void setEmission(bool b)
Enables/disables emission.
Definition CParticleTrail.h:292
void setCustomMaterial(CMaterial *material)
Sets custom material.
Definition CParticleTrail.h:240
std::wstring m_name
Friendly name.
Definition CParticleTrail.h:91
bool m_billboard
Whether the ribbon always faces the camera.
Definition CParticleTrail.h:145
void setWidth(float f)
Sets ribbon width.
Definition CParticleTrail.h:186
bool isDestroyedWhenParticleDead()
Checks death destruction policy.
Definition CParticleTrail.h:210
core::array< STrailInfo > m_trails
Active trails for live particles.
Definition CParticleTrail.h:94
CGroup * m_group
The group whose particles generate these trails.
Definition CParticleTrail.h:88
bool useCustomMaterial()
Checks if custom material is active.
Definition CParticleTrail.h:246
float getLength()
Gets max trail length.
Definition CParticleTrail.h:271
core::vector3df m_upVector
Custom up vector if billboarding is disabled.
Definition CParticleTrail.h:148
u32 m_maxSegmentCount
Max number of segments per trail.
Definition CParticleTrail.h:106
bool m_emission
Whether the trail has emission.
Definition CParticleTrail.h:139
void setDeadAlphaReduction(float a)
Sets fading speed for dead trails.
Definition CParticleTrail.h:228
IMeshBuffer * m_meshBuffer
Internal mesh buffer for the trail ribbon.
Definition CParticleTrail.h:100
void setLength(float l)
Sets max trail length.
void setSegmentLength(float f)
Sets segment separation distance.
Definition CParticleTrail.h:198
virtual void OnGroupDestroy()
Callback: handles parent group destruction.
bool m_useCustomMaterial
Whether to use custom material.
Definition CParticleTrail.h:133
void setUpVector(const core::vector3df &up)
Sets custom up vector for orientation.
Definition CParticleTrail.h:328
CMaterial * m_customMaterial
Optional custom material.
Definition CParticleTrail.h:130
std::string m_texturePath
Path to the ribbon texture.
Definition CParticleTrail.h:124
float getSegmentLength()
Gets segment separation distance.
Definition CParticleTrail.h:204
float getDeadAlphaReduction()
Gets fading speed for dead trails.
Definition CParticleTrail.h:222
void setEmissionIntensity(float f)
Sets emission intensity.
Definition CParticleTrail.h:304
virtual void OnParticleBorn(CParticle &p)
Callback: initializes trail for a new particle.
core::array< STrailInfo > m_deadTrails
Fading trails for dead particles.
Definition CParticleTrail.h:97
float m_width
Ribbon width.
Definition CParticleTrail.h:109
virtual void OnSwapParticleData(CParticle &p1, CParticle &p2)
Callback: swaps trail indices when particles are reordered.
void setTexture(ITexture *texture)
Directly sets ribbon texture.
bool m_destroyWhenParticleDead
Whether to kill the trail immediately when its particle dies.
Definition CParticleTrail.h:118
float m_deadAlphaReduction
Fading speed for dead trails.
Definition CParticleTrail.h:121
void setBillboard(bool b)
Enables/disables camera billboarding.
Definition CParticleTrail.h:316
void updateDeadTrail()
Internal: manages fading of dead trails.
void enableDestroyWhenParticleDead(bool b)
Configures death destruction policy.
Definition CParticleTrail.h:216
const char * getCustomMaterial()
Gets path to custom material.
Definition CParticleTrail.h:252
void enableCustomMaterial(bool b)
Enables/disables custom material.
Definition CParticleTrail.h:234
const wchar_t * getGroupName()
Gets name of linked group.
Definition CParticleTrail.h:260
float m_segmentLength
Distance between ribbon segments.
Definition CParticleTrail.h:103
CMaterial * m_material
Default material for the ribbon.
Definition CParticleTrail.h:127
IMeshBuffer * getMeshBuffer()
Gets raw access to trail mesh.
Definition CParticleTrail.h:174
void applyMaterial()
Updates material parameters in the mesh buffer.
float getEmissionIntensity()
Gets emission intensity.
Definition CParticleTrail.h:310
float getWidth()
Gets ribbon width.
Definition CParticleTrail.h:192
virtual void OnParticleDead(CParticle &p)
Callback: moves trail to dead list for fading or removes it.
Self reallocating template array (like stl vector) with additional features.
Definition irrArray.h:23
Struct for holding a mesh with a single material.
Definition IMeshBuffer.h:42
Interface of a Video Driver dependent Texture.
Definition ITexture.h:119
Class representing a 32 bit ARGB color.
Definition SColor.h:285
Everything in the Skylicht Engine. You can start by looking at the topics.
Definition AudioDebugLog.h:29
vector3d< f32 > vector3df
Typedef for a f32 3d vector.
Definition vector3d.h:445
CMatrix4< f32 > matrix4
Typedef for f32 matrix.
Definition matrix4.h:2241
unsigned int u32
32 bit unsigned variable.
Definition irrTypes.h:58
Definition CParticleTrail.h:38