Skip to content

Commit

Permalink
beep
Browse files Browse the repository at this point in the history
  • Loading branch information
jwerle committed Feb 7, 2016
1 parent 220d811 commit 8b04e9a
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 43 deletions.
10 changes: 2 additions & 8 deletions include/glisy/math.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,7 @@

#define GLISY_EPSILON 0.000001

#include <glisy/math/vec2.h>
#include <glisy/math/vec3.h>
#include <glisy/math/vec4.h>
#include <glisy/math/mat2.h>
#include <glisy/math/mat3.h>
#include <glisy/math/mat4.h>
#include <glisy/math/quat.h>

#include <glisy/math/vector.h>
#include <glisy/math/matrix.h>

#endif
12 changes: 6 additions & 6 deletions include/glisy/math/mat4.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,12 @@ struct mat4 {
* Transposes mat4 a.
*/

#define mat4_transpose(a) (mat4) ({ \
mat4(a.m11, a.m21, a.m31, a.m41, \
a.m12, a.m22, a.m32, a.m42, \
a.m13, a.m23, a.m33, a.m43, \
a.m14, a.m24, a.m34, a.m44); \
})
#define mat4_transpose(a) (mat4) { \
a.m11, a.m21, a.m31, a.m41, \
a.m12, a.m22, a.m32, a.m42, \
a.m13, a.m23, a.m33, a.m43, \
a.m14, a.m24, a.m34, a.m44 \
}

/**
* Calculates and returns inverse for
Expand Down
8 changes: 8 additions & 0 deletions include/glisy/math/matrix.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#ifndef GLISY_MATRIX_H
#define GLISY_MATRIX_H

#include <glisy/mat2.h>
#include <glisy/mat3.h>
#include <glisy/mat4.h>

#endif
7 changes: 1 addition & 6 deletions include/glisy/math/quat.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,7 @@
*/

typedef struct quat quat;
struct quat {
float x;
float y;
float z;
float w;
};
struct quat { float x; float y; float z; float w; };

/**
* quat initializer.
Expand Down
33 changes: 17 additions & 16 deletions include/glisy/math/vec2.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@
*/

typedef struct vec2 vec2;
struct vec2 {
float x;
float y;
};
struct vec2 { float x; float y; };

/**
* vec2 initializer.
Expand Down Expand Up @@ -59,7 +56,7 @@ struct vec2 {
* Copy vec2 b into vec2 a
*/

#define vec2_copy(a, b) (vec2) ({ \
#define vec2_copy(a, b) ({ \
vec2 *tmp = &a; \
(tmp->x = b.x); \
(tmp->y = b.y); \
Expand All @@ -70,7 +67,7 @@ struct vec2 {
* Sets x and y component of vec2.
*/

#define vec2_set(v, a, b) (vec2) ({ \
#define vec2_set(v, a, b) ({ \
vec2 *tmp = &v; \
tmp->x = ((float) a); \
tmp->y = ((float) b); \
Expand All @@ -81,35 +78,31 @@ struct vec2 {
* Add two vectors together.
*/

#define vec2_add(a, b) ((vec2) {(a.x + b.x), \
(a.y + b.y)})
#define vec2_add(a, b) ((vec2) {(a.x + b.x), (a.y + b.y)})

/**
* Returns the maximum of two vec2 inputs.
*/

#define vec2_max(a, b) ((vec2) {fmaxf(a.x, b.x), \
fmaxf(a.y, b.y)})
#define vec2_max(a, b) ((vec2) {fmaxf(a.x, b.x),fmaxf(a.y, b.y)})

/**
* Returns the minimum of two vec2 inputs.
*/

#define vec2_min(a, b) ((vec2) {fminf(a.x, b.x), \
fminf(a.y, b.y)})
#define vec2_min(a, b) ((vec2) {fminf(a.x, b.x), fminf(a.y, b.y)})

/**
* Scale a vec2 by a scalar number.
*/

#define vec2_scale(a, s) ((vec2) {(a.x * s), \
(a.y * s)})
#define vec2_scale(a, s) ((vec2) {(a.x * s), (a.y * s)})

/**
* Calculates the Euclidean distance for a vec2.
*/

#define vec2_distance(a, b) (float) sqrt(powf(b.x - a.x, 2) + \
#define vec2_distance(a, b) (float) sqrt(powf(b.x - a.x, 2) + \
powf(b.y - a.y, 2))

/**
Expand Down Expand Up @@ -214,7 +207,15 @@ struct vec2 {
(vec2(x, y)); \
})

// @TODO(werle) - mat4 transform
/**
* Transform vec2 with mat4.
*/

#define vec2_transform_mat4(a, m) (vec2) ({ \
float x = m.m11 * a.x + m.m21 * a.y + m.m31; \
float y = m.m12 * a.x + m.m22 * a.y + m.m32; \
(vec2(x, y)); \
})

/**
* Returns a string representation of vec2 a.
Expand Down
6 changes: 1 addition & 5 deletions include/glisy/math/vec3.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,7 @@
*/

typedef struct vec3 vec3;
struct vec3 {
float x;
float y;
float z;
};
struct vec3 { float x; float y; float z; };

/**
* vec3 initializer.
Expand Down
8 changes: 8 additions & 0 deletions include/glisy/math/vector.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#ifndef GLISY_VECTOR_H
#define GLISY_VECTOR_H

#include <glisy/vec2.h>
#include <glisy/vec3.h>
#include <glisy/vec4.h>

#endif
1 change: 1 addition & 0 deletions test/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ math/mat3
math/vec2
math/vec3
renderer/renderer
shader/shader
4 changes: 2 additions & 2 deletions test/shader/shader.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ int
main (void) {
glisy_shader vertex;
glisy_shader fragment;
assert(glisy_shader_init(&vertex, GL_VERTEX_SHADER, vertexSource));
assert(glisy_shader_init(&fragment, GL_FRAGMENT_SHADER, fragmentSource));
//assert(glisy_shader_init(&vertex, GL_VERTEX_SHADER, vertexSource));
//assert(glisy_shader_init(&fragment, GL_FRAGMENT_SHADER, fragmentSource));
return 0;
}

0 comments on commit 8b04e9a

Please sign in to comment.