Ray.cpp 804 B

1234567891011121314151617181920212223242526272829
  1. #include "client/math/Ray.h"
  2. #include "client/Utils.h"
  3. Ray::Ray() : lastLengthAngle(0), lengthAngle(0), lastWidthAngle(0), widthAngle(0) {
  4. }
  5. void Ray::store() {
  6. lastPosition = position;
  7. lastLengthAngle = lengthAngle;
  8. lastWidthAngle = widthAngle;
  9. }
  10. void Ray::set(const Vector& position, float lengthAngle, float widthAngle) {
  11. this->position = position;
  12. this->lengthAngle = lengthAngle;
  13. this->widthAngle = widthAngle;
  14. }
  15. Vector Ray::getPosition(float lag) const {
  16. Vector pos(lastPosition);
  17. pos.addMul(position, lag).addMul(lastPosition, -lag);
  18. return pos;
  19. }
  20. Vector Ray::getDirection(float lag) const {
  21. Vector direction;
  22. direction.setAngles(interpolate(lag, lastLengthAngle, lengthAngle), interpolate(lag, lastWidthAngle, widthAngle));
  23. return direction;
  24. }