1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
use super::*;
use super::super::common::math::*;
use super::super::common::settings::*;
use std::slice;
#[repr(C)]
#[derive(Debug)]
pub struct ParticleSystemDef {
pub strict_contact_check: bool,
pub density: Float32,
pub gravity_scale: Float32,
pub radius: Float32,
pub max_count: Int32,
pub pressure_strength: Float32,
pub damping_strength: Float32,
pub elastic_strength: Float32,
pub spring_strength: Float32,
pub viscous_strength: Float32,
pub surface_tension_pressure_strength: Float32,
pub surface_tension_normal_strength: Float32,
pub repulsive_strength: Float32,
pub powder_strength: Float32,
pub ejection_strength: Float32,
pub static_pressure_strength: Float32,
pub static_pressure_relaxation: Float32,
pub static_pressure_iterations: Int32,
pub color_mixing_strength: Float32,
pub destroy_by_age: bool,
pub lifetime_granularity: Float32,
}
impl Default for ParticleSystemDef {
fn default () -> ParticleSystemDef {
ParticleSystemDef {
strict_contact_check: false,
density: 1.0,
gravity_scale: 1.0,
radius: 1.0,
max_count: 0,
pressure_strength: 0.05,
damping_strength: 1.0,
elastic_strength: 0.25,
spring_strength: 0.25,
viscous_strength: 0.25,
surface_tension_pressure_strength: 0.2,
surface_tension_normal_strength: 0.2,
repulsive_strength: 1.0,
powder_strength: 0.5,
ejection_strength: 0.5,
static_pressure_strength: 0.2,
static_pressure_relaxation: 0.2,
static_pressure_iterations: 8,
color_mixing_strength: 0.5,
destroy_by_age: true,
lifetime_granularity: 1.0 / 60.0,
}
}
}
pub enum B2ParticleSystem {}
extern {
fn b2ParticleSystem_CreateParticle(ps: *mut B2ParticleSystem, pd: &B2ParticleDef) -> Int32;
fn b2ParticleSystem_DestroyParticle(ps: *mut B2ParticleSystem, index: Int32);
fn b2ParticleSystem_GetParticleCount(ps: *mut B2ParticleSystem) -> Int32;
fn b2ParticleSystem_GetParticleFlags(ps: *mut B2ParticleSystem, index: Int32) -> UInt32;
fn b2ParticleSystem_GetNext(ps: *mut B2ParticleSystem) -> *mut B2ParticleSystem;
fn b2ParticleSystem_GetPositionBuffer(ps: *mut B2ParticleSystem) -> *mut Vec2;
}
#[allow(raw_pointer_derive)]
#[derive(Clone)]
pub struct ParticleSystem {
pub ptr: *mut B2ParticleSystem
}
impl ParticleSystem {
pub fn create_particle(&self, pd: &ParticleDef) -> Int32 {
unsafe {
b2ParticleSystem_CreateParticle(self.ptr, &B2ParticleDef::from(pd))
}
}
pub fn destroy_particle(&self, index: Int32) {
unsafe {
b2ParticleSystem_DestroyParticle(self.ptr, index);
}
}
pub fn get_particle_count(&self) -> Int32 {
unsafe {
b2ParticleSystem_GetParticleCount(self.ptr)
}
}
pub fn get_particle_flags(&self, index: Int32) -> Option<ParticleFlags> {
unsafe {
ParticleFlags::from_bits(b2ParticleSystem_GetParticleFlags(self.ptr, index))
}
}
pub fn get_next(&self) -> Option<ParticleSystem> {
let ptr: *mut B2ParticleSystem;
unsafe {
ptr = b2ParticleSystem_GetNext(self.ptr);
}
if ptr.is_null() {
None
} else {
Some(ParticleSystem { ptr: ptr })
}
}
pub fn get_position_buffer(&self) -> &[Vec2] {
unsafe {
slice::from_raw_parts(b2ParticleSystem_GetPositionBuffer(self.ptr), self.get_particle_count() as usize)
}
}
}