Simplify math/vector files

This commit is contained in:
twinaphex 2017-04-20 10:30:30 +02:00
parent fa347475e8
commit 9daa63437a
3 changed files with 35 additions and 57 deletions

View File

@ -37,27 +37,18 @@ float vec2_cross(const float *a, const float *b)
void vec2_add(float *dst, const float *src)
{
unsigned i;
unsigned n = 2;
for (i = 0; i < n; i++)
dst[i] += src[i];
dst[0] += src[0];
dst[1] += src[1];
}
void vec2_subtract(float *dst, const float *src)
{
unsigned i;
unsigned n = 2;
for (i = 0; i < n; i++)
dst[i] -= src[i];
dst[0] -= src[0];
dst[1] -= src[1];
}
void vec2_copy(float *dst, const float *src)
{
unsigned i;
unsigned n = 2;
for (i = 0; i < n; i++)
dst[i] = src[i];
dst[0] = src[0];
dst[1] = src[1];
}

View File

@ -40,44 +40,35 @@ void vec3_cross(float* dst, const float *a, const float *b)
float vec3_length(const float *a)
{
float length_sq = vec3_dot(a,a);
float length = sqrtf(length_sq);
return length;
return sqrtf(length_sq);
}
void vec3_add(float *dst, const float *src)
{
unsigned i;
unsigned n = 3;
for (i = 0; i < n; i++)
dst[i] += src[i];
dst[0] += src[0];
dst[1] += src[1];
dst[2] += src[2];
}
void vec3_subtract(float *dst, const float *src)
{
unsigned i;
unsigned n = 3;
for (i = 0; i < n; i++)
dst[i] -= src[i];
dst[0] -= src[0];
dst[1] -= src[1];
dst[2] -= src[2];
}
void vec3_scale(float *dst, const float scale)
{
unsigned i;
unsigned n = 3;
for (i = 0; i < n; i++)
dst[i] *= scale;
dst[0] *= scale;
dst[1] *= scale;
dst[2] *= scale;
}
void vec3_copy(float *dst, const float *src)
{
unsigned i;
unsigned n = 3;
for (i = 0; i < n; i++)
dst[i] = src[i];
dst[0] = src[0];
dst[1] = src[1];
dst[2] = src[2];
}
void vec3_normalize(float *dst)

View File

@ -27,36 +27,32 @@
void vec4_add(float *dst, const float *src)
{
unsigned i;
unsigned n = 4;
for (i = 0; i < n; i++)
dst[i] += src[i];
dst[0] += src[0];
dst[1] += src[1];
dst[2] += src[2];
dst[3] += src[3];
}
void vec4_subtract(float *dst, const float *src)
{
unsigned i;
unsigned n = 4;
for (i = 0; i < n; i++)
dst[i] -= src[i];
dst[0] -= src[0];
dst[1] -= src[1];
dst[2] -= src[2];
dst[3] -= src[3];
}
void vec4_scale(float *dst, const float scale)
{
unsigned i;
unsigned n = 4;
for (i = 0; i < n; i++)
dst[i] *= scale;
dst[0] *= scale;
dst[1] *= scale;
dst[2] *= scale;
dst[3] *= scale;
}
void vec4_copy(float *dst, const float *src)
{
unsigned i;
unsigned n = 4;
for (i = 0; i < n; i++)
dst[i] = src[i];
dst[0] = src[0];
dst[1] = src[1];
dst[2] = src[2];
dst[3] = src[3];
}