[Add] vect_reflect() - Mirror a vector off another.
This commit is contained in:
parent
4dbc934722
commit
0bcc2c3135
@ -74,6 +74,17 @@ void vect_cadd(Vec2* v, const double x, const double y) {
|
|||||||
v->angle = ANGLE(v->x, v->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! */
|
/* SOLID! */
|
||||||
|
@ -33,6 +33,7 @@ void vectcpy(Vec2* dest, const Vec2* src);
|
|||||||
void vectnull(Vec2* v);
|
void vectnull(Vec2* v);
|
||||||
double vect_angle(const Vec2* ref, const Vec2* v);
|
double vect_angle(const Vec2* ref, const Vec2* v);
|
||||||
void vect_cadd(Vec2* v, const double x, const double y);
|
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. */
|
/* Describe any solid in 2D space. */
|
||||||
typedef struct Solid_ {
|
typedef struct Solid_ {
|
||||||
|
Loading…
Reference in New Issue
Block a user