TODO: OPT: rewrite this smarter!
| 467 | |
| 468 | // TODO: OPT: rewrite this smarter! |
| 469 | void 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 | |
| 507 | bool CCollision::TestBox(vec2 Pos, vec2 Size) const |
| 508 | { |