MCPcopy Create free account
hub / github.com/ddnet/ddnet / MovePoint

Method MovePoint

src/game/collision.cpp:469–505  ·  view source on GitHub ↗

TODO: OPT: rewrite this smarter!

Source from the content-addressed store, hash-verified

467
468// TODO: OPT: rewrite this smarter!
469void CCollision::MovePoint(vec2 *pInoutPos, vec2 *pInoutVel, float Elasticity, int *pBounces) const
470{
471 if(pBounces)
472 *pBounces = 0;
473
474 vec2 Pos = *pInoutPos;
475 vec2 Vel = *pInoutVel;
476 if(CheckPoint(Pos + Vel))
477 {
478 int Affected = 0;
479 if(CheckPoint(Pos.x + Vel.x, Pos.y))
480 {
481 pInoutVel->x *= -Elasticity;
482 if(pBounces)
483 (*pBounces)++;
484 Affected++;
485 }
486
487 if(CheckPoint(Pos.x, Pos.y + Vel.y))
488 {
489 pInoutVel->y *= -Elasticity;
490 if(pBounces)
491 (*pBounces)++;
492 Affected++;
493 }
494
495 if(Affected == 0)
496 {
497 pInoutVel->x *= -Elasticity;
498 pInoutVel->y *= -Elasticity;
499 }
500 }
501 else
502 {
503 *pInoutPos = Pos + Vel;
504 }
505}
506
507bool CCollision::TestBox(vec2 Pos, vec2 Size) const
508{

Callers 3

DoBounceMethod · 0.80
UpdateMethod · 0.80
DoBounceMethod · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected