feat: added reflect
parent
110e72e241
commit
0c7cbeaa6c
|
@ -39,6 +39,11 @@ Vecf Vecf::move_towards(Vecf const &from, Vecf const &to, float delta) {
|
|||
return Vecf::lerp(from, to, delta / Vecf::distance(from, to));
|
||||
}
|
||||
|
||||
Vecf Vecf::reflect(Vecf const &in, Vecf const &normal) {
|
||||
Vecf const midpoint{normal * Vecf::dot(normal, in)};
|
||||
return (midpoint - in) + midpoint;
|
||||
}
|
||||
|
||||
float Vecf::magnitude() const {
|
||||
return std::sqrt(this->x * this->x + this->y * this->y);
|
||||
}
|
||||
|
|
|
@ -22,6 +22,8 @@ struct Vecf {
|
|||
static Vecf lerp(Vecf const &from, Vecf const &to, float t);
|
||||
//! move towards a point by a set unit distance
|
||||
static Vecf move_towards(Vecf const &from, Vecf const &to, float delta);
|
||||
//! calculate the outgoing velocity of an object reflecting against a surface
|
||||
static Vecf reflect(Vecf const &in, Vecf const &normal);
|
||||
//! magnitude (a.k.a length or absolute) of this vector
|
||||
float magnitude() const;
|
||||
//! square of the magnitude, use for comparing lengths of vectors efficiently
|
||||
|
|
Loading…
Reference in New Issue