]> git.lizzy.rs Git - minetest.git/blob - src/particles.h
Allow vertical axis particle rotation constraint
[minetest.git] / src / particles.h
1 /*
2 Minetest
3 Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation; either version 2.1 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 GNU Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19
20 #ifndef PARTICLES_HEADER
21 #define PARTICLES_HEADER
22
23 #define DIGGING_PARTICLES_AMOUNT 10
24
25 #include <iostream>
26 #include "irrlichttypes_extrabloated.h"
27 #include "tile.h"
28 #include "localplayer.h"
29 #include "environment.h"
30
31 class Particle : public scene::ISceneNode
32 {
33         public:
34         Particle(
35                 IGameDef* gamedef,
36                 scene::ISceneManager* mgr,
37                 LocalPlayer *player,
38                 ClientEnvironment &env,
39                 v3f pos,
40                 v3f velocity,
41                 v3f acceleration,
42                 float expirationtime,
43                 float size,
44                 bool collisiondetection,
45                 bool vertical,
46                 video::ITexture *texture,
47                 v2f texpos,
48                 v2f texsize
49         );
50         ~Particle();
51
52         virtual const core::aabbox3d<f32>& getBoundingBox() const
53         {
54                 return m_box;
55         }
56
57         virtual u32 getMaterialCount() const
58         {
59                 return 1;
60         }
61
62         virtual video::SMaterial& getMaterial(u32 i)
63         {
64                 return m_material;
65         }
66
67         virtual void OnRegisterSceneNode();
68         virtual void render();
69
70         void step(float dtime, ClientEnvironment &env);
71
72         bool get_expired ()
73         { return m_expiration < m_time; }
74
75 private:
76         void updateLight(ClientEnvironment &env);
77         void updateVertices();
78
79         video::S3DVertex m_vertices[4];
80         float m_time;
81         float m_expiration;
82
83         IGameDef *m_gamedef;
84         core::aabbox3d<f32> m_box;
85         core::aabbox3d<f32> m_collisionbox;
86         video::SMaterial m_material;
87         v2f m_texpos;
88         v2f m_texsize;
89         v3f m_pos;
90         v3f m_velocity;
91         v3f m_acceleration;
92         LocalPlayer *m_player;
93         float m_size;
94         u8 m_light;
95         bool m_collisiondetection;
96         bool m_vertical;
97 };
98
99 class ParticleSpawner
100 {
101         public:
102         ParticleSpawner(IGameDef* gamedef,
103                 scene::ISceneManager *smgr,
104                 LocalPlayer *player,
105                 u16 amount,
106                 float time,
107                 v3f minp, v3f maxp,
108                 v3f minvel, v3f maxvel,
109                 v3f minacc, v3f maxacc,
110                 float minexptime, float maxexptime,
111                 float minsize, float maxsize,
112                 bool collisiondetection,
113                 bool vertical,
114                 video::ITexture *texture,
115                 u32 id);
116
117         ~ParticleSpawner();
118
119         void step(float dtime, ClientEnvironment &env);
120
121         bool get_expired ()
122         { return (m_amount <= 0) && m_spawntime != 0; }
123
124         private:
125         float m_time;
126         IGameDef *m_gamedef;
127         scene::ISceneManager *m_smgr;
128         LocalPlayer *m_player;
129         u16 m_amount;
130         float m_spawntime;
131         v3f m_minpos;
132         v3f m_maxpos;
133         v3f m_minvel;
134         v3f m_maxvel;
135         v3f m_minacc;
136         v3f m_maxacc;
137         float m_minexptime;
138         float m_maxexptime;
139         float m_minsize;
140         float m_maxsize;
141         video::ITexture *m_texture;
142         std::vector<float> m_spawntimes;
143         bool m_collisiondetection;
144         bool m_vertical;
145 };
146
147 void allparticles_step (float dtime, ClientEnvironment &env);
148 void allparticlespawners_step (float dtime, ClientEnvironment &env);
149
150 void delete_particlespawner (u32 id);
151 void clear_particles ();
152
153 void addDiggingParticles(IGameDef* gamedef, scene::ISceneManager* smgr,
154         LocalPlayer *player, ClientEnvironment &env, v3s16 pos,
155         const TileSpec tiles[]);
156
157 void addPunchingParticles(IGameDef* gamedef, scene::ISceneManager* smgr,
158         LocalPlayer *player, ClientEnvironment &env, v3s16 pos,
159         const TileSpec tiles[]);
160
161 void addNodeParticle(IGameDef* gamedef, scene::ISceneManager* smgr,
162         LocalPlayer *player, ClientEnvironment &env, v3s16 pos,
163         const TileSpec tiles[]);
164
165 #endif