[Add] vect_reflect() - Mirror a vector off another.

This commit is contained in:
Allanis 2013-08-07 12:14:47 +01:00
parent 4dbc934722
commit 0bcc2c3135
2 changed files with 12 additions and 0 deletions

View File

@ -74,6 +74,17 @@ void vect_cadd(Vec2* v, const double x, const double y) {
v->angle = ANGLE(v->x, v->y);
}
/* Mirrors a vector off another, stores results in vector. */
void vect_reflect(Vec2* r, Vec2* v, Vec2* n) {
double dot;
dot = (v->x*n->x) + (v->y*n->y);
r->x = v->x - ((2. * dot) * n->x);
r->y = v->y - ((2. * dot) * n->y);
r->mod = MOD(r->x, r->y);
r->angle = MOD(r->x, r->y);
}
/* ================ */
/* SOLID! */

View File

@ -33,6 +33,7 @@ void vectcpy(Vec2* dest, const Vec2* src);
void vectnull(Vec2* v);
double vect_angle(const Vec2* ref, const Vec2* v);
void vect_cadd(Vec2* v, const double x, const double y);
void vect_reflect(Vec2* r, Vec2* v, Vec2* n);
/* Describe any solid in 2D space. */
typedef struct Solid_ {