vmulf is now a Vector*Vector multiplication, Vector*float is now vmulff
This commit is contained in:
parent
85a1798a3e
commit
cb869cb647
43
src/vmath.h
43
src/vmath.h
|
@ -2,6 +2,15 @@
|
||||||
#define _fencer_vmath_h
|
#define _fencer_vmath_h
|
||||||
|
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
|
||||||
|
#if VMATH_SDL == 1
|
||||||
|
|
||||||
|
#include <SDL2/SDL_rect.h>
|
||||||
|
typedef SDL_FPoint Vector;
|
||||||
|
typedef SDL_Point IVector;
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
typedef struct Vector {
|
typedef struct Vector {
|
||||||
float x;
|
float x;
|
||||||
float y;
|
float y;
|
||||||
|
@ -12,6 +21,8 @@ typedef struct IVector {
|
||||||
int y;
|
int y;
|
||||||
} IVector;
|
} IVector;
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
// Vector Constant Macros
|
// Vector Constant Macros
|
||||||
#define ZeroVector (Vector){0.0f, 0.0f}
|
#define ZeroVector (Vector){0.0f, 0.0f}
|
||||||
#define InfinityVector (Vector){INFINITY, INFINITY}
|
#define InfinityVector (Vector){INFINITY, INFINITY}
|
||||||
|
@ -43,10 +54,14 @@ Vector vsubf(Vector a, Vector b) {
|
||||||
return (Vector){a.x - b.x, a.y - b.y};
|
return (Vector){a.x - b.x, a.y - b.y};
|
||||||
}
|
}
|
||||||
static inline
|
static inline
|
||||||
Vector vmulf(Vector a, float b) {
|
Vector vmulff(Vector a, float b) {
|
||||||
return (Vector){a.x * b, a.y * b};
|
return (Vector){a.x * b, a.y * b};
|
||||||
}
|
}
|
||||||
static inline
|
static inline
|
||||||
|
Vector vmulf(Vector a, Vector b) {
|
||||||
|
return (Vector) {a.x * b.x, a.y * b.y};
|
||||||
|
}
|
||||||
|
static inline
|
||||||
Vector vinvf(Vector a) {
|
Vector vinvf(Vector a) {
|
||||||
return (Vector){-a.x, -a.y};
|
return (Vector){-a.x, -a.y};
|
||||||
}
|
}
|
||||||
|
@ -64,7 +79,7 @@ float vsqrmagnitudef(Vector a) {
|
||||||
}
|
}
|
||||||
static inline
|
static inline
|
||||||
Vector vnormalizedf(Vector a) {
|
Vector vnormalizedf(Vector a) {
|
||||||
return vmulf(a, 1.0/vmagnitudef(a));
|
return vmulff(a, 1.0/vmagnitudef(a));
|
||||||
}
|
}
|
||||||
static inline
|
static inline
|
||||||
float vdotf(Vector a, Vector b) {
|
float vdotf(Vector a, Vector b) {
|
||||||
|
@ -78,5 +93,29 @@ static inline
|
||||||
float vsqrdistf(Vector a, Vector b) {
|
float vsqrdistf(Vector a, Vector b) {
|
||||||
return vsqrmagnitudef(vsubf(a, b));
|
return vsqrmagnitudef(vsubf(a, b));
|
||||||
}
|
}
|
||||||
|
static inline
|
||||||
|
Vector vreciprocalf(Vector a) {
|
||||||
|
return (Vector){1.0/a.x, 1.0/a.y};
|
||||||
|
}
|
||||||
|
static inline
|
||||||
|
Vector vrotatef(Vector a, float t) {
|
||||||
|
return (Vector){
|
||||||
|
cosf(t) * a.x - sinf(t) * a.y,
|
||||||
|
sinf(t) * a.x + cosf(t) * a.y
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline
|
||||||
|
IVector vaddi(IVector a, IVector b) {
|
||||||
|
return (IVector){a.x + b.x, a.y + b.y};
|
||||||
|
}
|
||||||
|
static inline
|
||||||
|
IVector vsubi(IVector a, IVector b) {
|
||||||
|
return (IVector){a.x - b.x, a.y - b.y};
|
||||||
|
}
|
||||||
|
static inline
|
||||||
|
IVector vmuli(IVector a, IVector b) {
|
||||||
|
return (IVector){a.x * b.x, a.y * b.y};
|
||||||
|
}
|
||||||
|
|
||||||
#endif // !_fencer_vmath_h
|
#endif // !_fencer_vmath_h
|
||||||
|
|
Loading…
Reference in a new issue