Skip to content

Commit

Permalink
okay
Browse files Browse the repository at this point in the history
  • Loading branch information
jwerle committed Feb 3, 2016
1 parent 6331a0f commit aaf2c4d
Show file tree
Hide file tree
Showing 23 changed files with 260 additions and 223 deletions.
1 change: 0 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
## Source files
SRC += $(wildcard src/*.c)
SRC += $(wildcard src/math/*.c)

## Source objects
OBJS := $(SRC:.c=.o)
Expand Down
4 changes: 2 additions & 2 deletions include/glisy/camera/perspective.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#ifndef GLISY_CAMERA_PERSPECTIVE_H
#define GLISY_CAMERA_PERSPECTIVE_H

typedef struct glisy_camera_perspective glisy_camera_perspective;
struct glisy_camera_perspective {
typedef struct glisy_perspective_camera glisy_perspective_camera;
struct glisy_perspective_camera {

/**
* Vertical camera field of view in degrees.
Expand Down
2 changes: 1 addition & 1 deletion include/glisy/context.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,6 @@ glisy_context_use (glisy_context *, const void *);
*/

int
glisy_context_should_update (const glisy_context);
glisy_context_should_update (glisy_context *);

#endif
36 changes: 0 additions & 36 deletions include/glisy/events.h

This file was deleted.

1 change: 0 additions & 1 deletion include/glisy/gl.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,4 @@
#include <GL/glut.h>
#endif

#include <GLFW/glfw3.h>
#endif
6 changes: 3 additions & 3 deletions include/glisy/glisy.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
*/

#include <glisy/gl.h>
#include <glisy/events.h>
#include <glisy/window.h>
#include <glisy/mesh.h>
#include <glisy/shader.h>
#include <glisy/program.h>
#include <glisy/context.h>
#include <glisy/renderer.h>
Expand Down Expand Up @@ -52,5 +52,5 @@ glisy_terminate (void);
void
glisy_render (const glisy_renderer,
const glisy_scene,
const glisy_camera_perspective);
const glisy_perspective_camera);
#endif
8 changes: 6 additions & 2 deletions include/glisy/math/mat3.h
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,10 @@ struct mat3 {
(1 - xx - yy)); \
}))

/**
* Calculates Frobenius norm mat3 a.
*/

#define mat3_frob(a) (float) sqrt( \
powf(a.m11, 2.0) + \
powf(a.m12, 2.0) + \
Expand All @@ -259,8 +263,8 @@ struct mat3 {

#define mat3_string(a) (const char *) ({ \
char str[BUFSIZ]; \
mat3 b; \
mat3_copy(b, a); \
mat3 b; \
mat3_copy(b, a); \
memset(str, 0, BUFSIZ); \
sprintf(str, "mat3(%f, %f, %f, %f, %f, %f, %f, %f, %f)", \
b.m11, b.m12, b.m13, \
Expand Down
99 changes: 99 additions & 0 deletions include/glisy/math/mat4.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
#ifndef GLISY_MAT4_H
#define GLISY_MAT4_H

/**
* mat4 struct type.
*/

typedef struct mat4 mat4;
struct mat4 {
float m11; float m12; float m13; float m14;
float m21; float m22; float m23; float m24;
float m31; float m32; float m33; float m34;
float m41; float m42; float m43; float m44;
};

/**
* mat4 initializer.
*/

#define mat4_create() mat4(1,0,0,0, \
0,1,0,0, \
0,0,1,0, \
0,0,0,1)

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

/**
* Clones and returns mat4 a.
*/

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

/**
* Copies mat4 b into mat4 a.
*/

#define mat4_copy(a, b) (mat4) ({ \
mat4 *c = &a; \
(c->m11 = b.m11), (c->m12 = b.m12), (c->m13 = b.m13), (c->m14 = b.m14); \
(c->m21 = b.m21), (c->m22 = b.m22), (c->m23 = b.m23), (c->m24 = b.m24); \
(c->m31 = b.m31), (c->m32 = b.m32), (c->m33 = b.m33), (c->m34 = b.m34); \
(c->m41 = b.m41), (c->m42 = b.m42), (c->m43 = b.m43), (c->m44 = b.m44); \
(*c); \
})

/**
* Sets an identity for mat4 a.
*/

#define mat4_identity(a) (mat4) ({ \
mat4 *b = &a; \
(b->m11 = 1), (b->m12 = 0), (b->m13 = 0), (b->m14 = 0); \
(b->m21 = 0), (b->m22 = 1), (b->m23 = 0), (b->m24 = 0); \
(b->m31 = 0), (b->m32 = 0), (b->m33 = 1), (b->m34 = 0); \
(b->m41 = 0), (b->m42 = 0), (b->m43 = 0), (b->m44 = 1); \
(*b); \
})

/**
* 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); \
})

/**
* Returns a string representation of mat4 a.
*/

#define mat4_string(a) (const char *) ({ \
char str[BUFSIZ]; \
mat4 b; \
mat4_copy(b, a); \
memset(str, 0, BUFSIZ); \
sprintf(str, "mat4(%f, %f, %f, %f," \
"%f, %f, %f, %f,", \
"%f, %f, %f, %f,", \
"%f, %f, %f, %f)", \
b.m11, b.m12, b.m13, b.m14, \
b.m21, b.m22, b.m23, b.m24, \
b.m31, b.m32, b.m33, b.m34, \
b.m41, b.m42, b.m43, b.m44); \
(strdup(str)); \
})

#endif
29 changes: 17 additions & 12 deletions include/glisy/math/vec2.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,21 +36,24 @@ struct vec2 {
*/

#define vec2_sub vec2_subtract
#define vec2_subtract(a, b) ((vec2) {(a.x - b.x), (a.y - b.y)})
#define vec2_subtract(a, b) ((vec2) {(a.x - b.x), \
(a.y - b.y)})

/**
* Multiply two vec2.
*/

#define vec2_mul vec2_multiply
#define vec2_multiply(a, b) ((vec2) {(a.x * b.x), (a.y * b.y)})
#define vec2_multiply(a, b) ((vec2) {(a.x * b.x), \
(a.y * b.y)})

/**
* Divide two vec2 a by vec2 b
*/

#define vec2_div vec2_divide
#define vec2_divide(a, b) ((vec2) {(a.x / b.x), (a.y / b.y)})
#define vec2_divide(a, b) ((vec2) {(a.x / b.x), \
(a.y / b.y)})

/**
* Copy vec2 b into vec2 a
Expand Down Expand Up @@ -78,25 +81,29 @@ 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.
Expand All @@ -117,16 +124,14 @@ struct vec2 {
*/

#define vec2_length(a) (float) ( \
sqrt(pow(a.x, 2) + pow(a.y, 2)) \
sqrt(powf(a.x, 2) + powf(a.y, 2)) \
)

/**
* Calculates the squard length of a vec2.
*/

#define vec2_length_squared(a) (float) ( \
pow(a.x, 2) + pow(a.y, 2) \
)
#define vec2_length_squared(a) (float) (powf(a.x, 2) + powf(a.y, 2))

/**
* Returns the negation of a vec2.
Expand Down Expand Up @@ -186,7 +191,7 @@ struct vec2 {
#define vec2_random(scale) (vec2) ({ \
srand((unsigned int) time(NULL)); \
float rad = 2.0 * M_PI * rand(); \
(vec2(cos(rad) * scale, sin(rad) * scale)); \
(vec2(cosf(rad) * scale, sinf(rad) * scale)); \
})

/**
Expand Down
File renamed without changes.
38 changes: 38 additions & 0 deletions include/glisy/shader.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#ifndef GLISY_SHADER_H
#define GLISY_SHADER_H

#include <stdio.h>

#define GLISY_GLSL_SHADER_HEADER \
"uniform mat3 gl_NormalMatrix;" \
"uniform mat4 gl_ModelViewMatrix;" \
"uniform mat4 gl_ProjectionMatrix;" \
"uniform mat4 gl_ModelViewProjectionMatrix;" \
"uniform mat4 gl_ModelViewMatrixInverse;" \
"uniform mat4 gl_ProjectionMatrixInverse;" \
"uniform mat4 gl_ModelViewProjectionMatrixInverse;" \

#define GLISY_GLSL_VERTEX_SHADER_HEADER GLISY_GLSL_SHADER_HEADER \
"attribute vec4 gl_TexCoord;" \
"attribute vec4 gl_Vertex;" \
"attribute vec3 gl_Normal;" \
"attribute vec4 gl_Color;" \
"vec4 ftransform() {" \
"return gl_ModelViewProjectionMatrix * gl_Vertex;" \
"};" \

#define GLISY_GLSL_FRAGMENT_SHADER_HEADER \
"precision highp float;" \
GLISY_GLSL_SHADER_HEADER \

typedef struct glisy_shader glisy_shader;
struct glisy_shader {
const unsigned char source[BUFSIZ];
unsigned int type;
};


int
glisy_shader_init (glisy_shader, const char *, const char *);

#endif
19 changes: 19 additions & 0 deletions include/glisy/texture.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#ifndef GLISY_TEXTURE_H
#define GLISY_TEXTURE_H
#include <glisy/gl.h>

typedef struct glisy_texture_options glisy_texture_options;
struct glisy_texture_options {
GLuint format;
unsigned int width;
unsigned int height;
};

typedef struct glisy_texture glisy_texture;
struct glisy_texture {
GLuint id;
};


glisy_texture_init (glisy_texture_options);
#endif
Loading

0 comments on commit aaf2c4d

Please sign in to comment.