Particle.hpp
Go to the documentation of this file.
1 //
3 // Thor C++ Library
4 // Copyright (c) 2011-2015 Jan Haller
5 //
6 // This software is provided 'as-is', without any express or implied
7 // warranty. In no event will the authors be held liable for any damages
8 // arising from the use of this software.
9 //
10 // Permission is granted to anyone to use this software for any purpose,
11 // including commercial applications, and to alter it and redistribute it
12 // freely, subject to the following restrictions:
13 //
14 // 1. The origin of this software must not be misrepresented; you must not
15 // claim that you wrote the original software. If you use this software
16 // in a product, an acknowledgment in the product documentation would be
17 // appreciated but is not required.
18 //
19 // 2. Altered source versions must be plainly marked as such, and must not be
20 // misrepresented as being the original software.
21 //
22 // 3. This notice may not be removed or altered from any source distribution.
23 //
25 
28 
29 #ifndef THOR_PARTICLE_HPP
30 #define THOR_PARTICLE_HPP
31 
32 #include <Thor/Config.hpp>
33 
34 #include <SFML/System/Time.hpp>
35 #include <SFML/System/Vector2.hpp>
36 #include <SFML/Graphics/Color.hpp>
37 
38 
39 namespace thor
40 {
41 
44 
49 class THOR_API Particle
50 {
51  // ---------------------------------------------------------------------------------------------------------------------------
52  // Public member functions
53  public:
56  explicit Particle(sf::Time totalLifetime);
57 
58 
59  // ---------------------------------------------------------------------------------------------------------------------------
60  // Public variables
61  public:
62  sf::Vector2f position;
63  sf::Vector2f velocity;
64  float rotation;
65  float rotationSpeed;
66  sf::Vector2f scale;
67  sf::Color color;
68  unsigned int textureIndex;
69 
70 
71  // ---------------------------------------------------------------------------------------------------------------------------
72  // Private variables
73  private:
74  sf::Time passedLifetime; // Time passed since emitted.
75  sf::Time totalLifetime; // Total time to live.
76 
77 
78  // ---------------------------------------------------------------------------------------------------------------------------
79  // Friends
81  friend class ParticleSystem;
82  friend sf::Time THOR_API getElapsedLifetime(const Particle& particle);
83  friend sf::Time THOR_API getTotalLifetime(const Particle& particle);
84  friend void THOR_API abandonParticle(Particle& particle);
86 };
87 
90 sf::Time THOR_API getElapsedLifetime(const Particle& particle);
91 
94 sf::Time THOR_API getTotalLifetime(const Particle& particle);
95 
98 sf::Time THOR_API getRemainingLifetime(const Particle& particle);
99 
102 float THOR_API getElapsedRatio(const Particle& particle);
103 
106 float THOR_API getRemainingRatio(const Particle& particle);
107 
113 void THOR_API abandonParticle(Particle& particle);
114 
116 
117 } // namespace thor
118 
119 #endif // THOR_PARTICLE_HPP
unsigned int textureIndex
Index of the used texture rect, returned by ParticleSystem::addTextureRect()
Definition: Particle.hpp:68
sf::Color color
Particle color.
Definition: Particle.hpp:67
sf::Vector2f position
Current position.
Definition: Particle.hpp:62
float rotation
Current rotation angle.
Definition: Particle.hpp:64
Definition: Animator.hpp:42
Configuration header of the library.
sf::Vector2f scale
Scale, where (1,1) represents the original size.
Definition: Particle.hpp:66
sf::Vector2f velocity
Velocity (change in position per second).
Definition: Particle.hpp:63
Class for particle systems.
Definition: ParticleSystem.hpp:75
Particle class
Definition: Particle.hpp:49
float rotationSpeed
Angular velocity (change in rotation per second).
Definition: Particle.hpp:65