Wizard Engine
2D cross-platform game engine built around SDL2
 
Loading...
Searching...
No Matches
wze::collider Class Reference
Inheritance diagram for wze::collider:
wze::entity wze::component

Public Member Functions

polygon const & body () const
 
void set_body (polygon const &body)
 
float force () const
 
void set_force (float force)
 
float mass () const
 
void set_mass (float mass)
 
uint8_t world () const
 
void set_world (uint8_t world)
 
float x () const final
 
void set_x (float x) final
 
float y () const final
 
void set_y (float y) final
 
float angle () const final
 
void set_angle (float angle) final
 
float scale () const
 
void set_scale (float scale)
 
float x_offset () const final
 
void set_x_offset (float x_offset) final
 
float y_offset () const final
 
void set_y_offset (float y_offset) final
 
float angle_offset () const final
 
void set_angle_offset (float angle_offset) final
 
bool attach_x () const final
 
void set_attach_x (bool attach_x) final
 
bool attach_y () const final
 
void set_attach_y (bool attach_y) final
 
bool attach_angle () const final
 
void set_attach_angle (bool attach_angle) final
 
bool x_angle_lock () const final
 
void set_x_angle_lock (bool x_angle_lock) final
 
bool y_angle_lock () const final
 
void set_y_angle_lock (bool y_angle_lock) final
 
 collider (polygon const &body=polygon(), float force=0, float mass=0, uint8_t world=std::numeric_limits< uint8_t >::max(), std::vector< std::weak_ptr< component > > const &components={})
 
 collider (collider const &other)
 
collideroperator= (collider const &other)
 
- Public Member Functions inherited from wze::entity
virtual std::vector< std::weak_ptr< component > > const & components () const
 
virtual std::vector< std::weak_ptr< component > > & components ()
 
void set_x (float x) override
 
void set_y (float y) override
 
void set_angle (float angle) override
 
virtual std::array< float, 4 > const & transformation_matrix () const
 
float x_offset () const override
 
float y_offset () const override
 
float angle_offset () const override
 
bool attach_x () const override
 
bool attach_y () const override
 
bool attach_angle () const override
 
bool x_angle_lock () const override
 
bool y_angle_lock () const override
 
 entity (std::vector< std::weak_ptr< component > > const &components={}, float x=0, float y=0, float angle=0, float x_offset=0, float y_offset=0, float angle_offset=0, bool attach_x=true, bool attach_y=true, bool attach_angle=true, bool x_angle_lock=true, bool y_angle_lock=true)
 
virtual void recompose ()
 
- Public Member Functions inherited from wze::component

Detailed Description

Definition at line 36 of file collider.hpp.

Constructor & Destructor Documentation

◆ collider() [1/2]

wze::collider::collider ( polygon const & body = polygon(),
float force = 0,
float mass = 0,
uint8_t world = std::numeric_limits<uint8_t>::max(),
std::vector< std::weak_ptr< component > > const & components = {} )
explicit

Definition at line 323 of file collider.cpp.

326 : entity(components), _world(std::numeric_limits<uint8_t>::max()) {
327 set_body(body);
328 set_force(force);
329 set_mass(mass);
330 set_world(world);
331}

◆ collider() [2/2]

wze::collider::collider ( collider const & other)

Definition at line 333 of file collider.cpp.

334 : entity(other), _world(std::numeric_limits<uint8_t>::max()) {
335 *this = other;
336}

◆ ~collider()

wze::collider::~collider ( )
override

Definition at line 338 of file collider.cpp.

338 {
339 if (world() != std::numeric_limits<uint8_t>::max()) {
340 _worlds.at(world()).erase(std::find(_worlds.at(world()).begin(),
341 _worlds.at(world()).end(), this));
342 }
343}

Member Function Documentation

◆ body()

wze::polygon const & wze::collider::body ( ) const
nodiscard

Definition at line 131 of file collider.cpp.

131 {
132 return _body;
133}

◆ set_body()

void wze::collider::set_body ( polygon const & body)

Definition at line 135 of file collider.cpp.

135 {
136 _body = body;
137 entity::set_x(this->body().x());
138 entity::set_y(this->body().y());
139 entity::set_angle(this->body().angle());
140 entity::set_x_offset(this->body().x_offset());
141 entity::set_y_offset(this->body().y_offset());
142 entity::set_angle_offset(this->body().angle_offset());
143 entity::set_attach_x(this->body().attach_x());
144 entity::set_attach_y(this->body().attach_y());
145 entity::set_attach_angle(this->body().attach_angle());
146 entity::set_x_angle_lock(this->body().x_angle_lock());
147 entity::set_y_angle_lock(this->body().y_angle_lock());
148}

◆ force()

float wze::collider::force ( ) const
nodiscard

Definition at line 150 of file collider.cpp.

150 {
151 return _force;
152}

◆ set_force()

void wze::collider::set_force ( float force)

Definition at line 154 of file collider.cpp.

154 {
155 _force = force;
156}

◆ mass()

float wze::collider::mass ( ) const
nodiscard

Definition at line 158 of file collider.cpp.

158 {
159 return _mass;
160}

◆ set_mass()

void wze::collider::set_mass ( float mass)

Definition at line 162 of file collider.cpp.

162 {
163 _mass = mass;
164}

◆ world()

uint8_t wze::collider::world ( ) const
nodiscard

Definition at line 166 of file collider.cpp.

166 {
167 return _world;
168}

◆ set_world()

void wze::collider::set_world ( uint8_t world)

Definition at line 170 of file collider.cpp.

170 {
171 if (this->world() != std::numeric_limits<uint8_t>::max()) {
172 _worlds.at(this->world())
173 .erase(std::find(_worlds.at(this->world()).begin(),
174 _worlds.at(this->world()).end(), this));
175 }
176 _world = world;
177 if (this->world() != std::numeric_limits<uint8_t>::max()) {
178 _worlds.at(this->world()).push_back(this);
179 }
180}

◆ x()

float wze::collider::x ( ) const
nodiscardfinalvirtual

Reimplemented from wze::entity.

Definition at line 182 of file collider.cpp.

182 {
183 return _body.x();
184}

◆ set_x()

void wze::collider::set_x ( float x)
finalvirtual

Implements wze::component.

Definition at line 186 of file collider.cpp.

186 {
187 _body.set_x(x);
188
189 if (world() == std::numeric_limits<uint8_t>::max()) {
190 entity::set_x(body().x());
191 return;
192 }
193
194 push<&collider::solo_static_resolver<&polygon::x, &polygon::set_x>,
195 &collider::solo_dynamic_resolver<&polygon::x, &polygon::set_x>>(
196 force());
197 align_entities();
198}

◆ y()

float wze::collider::y ( ) const
nodiscardfinalvirtual

Reimplemented from wze::entity.

Definition at line 200 of file collider.cpp.

200 {
201 return body().y();
202}

◆ set_y()

void wze::collider::set_y ( float y)
finalvirtual

Implements wze::component.

Definition at line 204 of file collider.cpp.

204 {
205 _body.set_y(y);
206
207 if (world() == std::numeric_limits<uint8_t>::max()) {
208 entity::set_y(body().y());
209 return;
210 }
211
212 push<&collider::solo_static_resolver<&polygon::y, &polygon::set_y>,
213 &collider::solo_dynamic_resolver<&polygon::y, &polygon::set_y>>(
214 force());
215 align_entities();
216}

◆ angle()

float wze::collider::angle ( ) const
nodiscardfinalvirtual

Reimplemented from wze::entity.

Definition at line 218 of file collider.cpp.

218 {
219 return _body.angle();
220}

◆ set_angle()

void wze::collider::set_angle ( float angle)
finalvirtual

Implements wze::component.

Definition at line 222 of file collider.cpp.

222 {
223 _body.set_angle(angle);
224
225 if (world() == std::numeric_limits<uint8_t>::max()) {
226 entity::set_angle(body().angle());
227 return;
228 }
229
230 push<&collider::dual_static_resolver, &collider::dual_dynamic_resolver>(
231 force());
232 align_entities();
233}

◆ scale()

float wze::collider::scale ( ) const
nodiscard

Definition at line 235 of file collider.cpp.

235 {
236 return body().scale();
237}

◆ set_scale()

void wze::collider::set_scale ( float scale)

Definition at line 239 of file collider.cpp.

239 {
240 _body.set_scale(scale);
241
242 if (world() == std::numeric_limits<uint8_t>::max()) {
243 return;
244 }
245
246 push<&collider::dual_static_resolver, &collider::dual_dynamic_resolver>(
247 force());
248 align_entities();
249}

◆ x_offset()

float wze::collider::x_offset ( ) const
nodiscardfinalvirtual

Implements wze::component.

Definition at line 251 of file collider.cpp.

251 {
252 return _body.x_offset();
253}

◆ set_x_offset()

void wze::collider::set_x_offset ( float x_offset)
finalvirtual

Reimplemented from wze::entity.

Definition at line 255 of file collider.cpp.

255 {
256 _body.set_x_offset(x_offset);
257 entity::set_x_offset(body().x_offset());
258}

◆ y_offset()

float wze::collider::y_offset ( ) const
nodiscardfinalvirtual

Implements wze::component.

Definition at line 260 of file collider.cpp.

260 {
261 return body().y_offset();
262}

◆ set_y_offset()

void wze::collider::set_y_offset ( float y_offset)
finalvirtual

Reimplemented from wze::entity.

Definition at line 264 of file collider.cpp.

264 {
265 _body.set_y_offset(y_offset);
266 entity::set_y_offset(body().y_offset());
267}

◆ angle_offset()

float wze::collider::angle_offset ( ) const
nodiscardfinalvirtual

Implements wze::component.

Definition at line 269 of file collider.cpp.

269 {
270 return body().angle_offset();
271}

◆ set_angle_offset()

void wze::collider::set_angle_offset ( float angle_offset)
finalvirtual

Reimplemented from wze::entity.

Definition at line 273 of file collider.cpp.

273 {
274 _body.set_angle_offset(angle_offset);
275 entity::set_angle_offset(body().angle_offset());
276}

◆ attach_x()

bool wze::collider::attach_x ( ) const
nodiscardfinalvirtual

Implements wze::component.

Definition at line 278 of file collider.cpp.

278 {
279 return body().attach_x();
280}

◆ set_attach_x()

void wze::collider::set_attach_x ( bool attach_x)
finalvirtual

Reimplemented from wze::entity.

Definition at line 282 of file collider.cpp.

282 {
283 _body.set_attach_x(attach_x);
284 entity::set_attach_x(body().attach_x());
285}

◆ attach_y()

bool wze::collider::attach_y ( ) const
nodiscardfinalvirtual

Implements wze::component.

Definition at line 287 of file collider.cpp.

287 {
288 return body().attach_y();
289}

◆ set_attach_y()

void wze::collider::set_attach_y ( bool attach_y)
finalvirtual

Reimplemented from wze::entity.

Definition at line 291 of file collider.cpp.

291 {
292 _body.set_attach_y(attach_y);
293 entity::set_attach_y(body().attach_y());
294}

◆ attach_angle()

bool wze::collider::attach_angle ( ) const
nodiscardfinalvirtual

Implements wze::component.

Definition at line 296 of file collider.cpp.

296 {
297 return body().attach_angle();
298}

◆ set_attach_angle()

void wze::collider::set_attach_angle ( bool attach_angle)
finalvirtual

Reimplemented from wze::entity.

Definition at line 300 of file collider.cpp.

300 {
301 _body.set_attach_angle(attach_angle);
302 entity::set_attach_angle(attach_angle);
303}

◆ x_angle_lock()

bool wze::collider::x_angle_lock ( ) const
nodiscardfinalvirtual

Implements wze::component.

Definition at line 305 of file collider.cpp.

305 {
306 return body().x_angle_lock();
307}

◆ set_x_angle_lock()

void wze::collider::set_x_angle_lock ( bool x_angle_lock)
finalvirtual

Reimplemented from wze::entity.

Definition at line 309 of file collider.cpp.

309 {
310 _body.set_x_angle_lock(x_angle_lock);
311 entity::set_x_angle_lock(body().x_angle_lock());
312}

◆ y_angle_lock()

bool wze::collider::y_angle_lock ( ) const
nodiscardfinalvirtual

Implements wze::component.

Definition at line 314 of file collider.cpp.

314 {
315 return body().y_angle_lock();
316}

◆ set_y_angle_lock()

void wze::collider::set_y_angle_lock ( bool y_angle_lock)
finalvirtual

Reimplemented from wze::entity.

Definition at line 318 of file collider.cpp.

318 {
319 _body.set_y_angle_lock(y_angle_lock);
320 entity::set_y_angle_lock(body().y_angle_lock());
321}

◆ operator=()

wze::collider & wze::collider::operator= ( collider const & other)

Definition at line 345 of file collider.cpp.

345 {
346 if (&other != this) {
347 entity::operator=(other);
348 set_body(other.body());
349 set_force(other.force());
350 set_mass(other.mass());
351 set_world(other.world());
352 }
353
354 return *this;
355}

The documentation for this class was generated from the following files: