66 lines
1.3 KiB
C
66 lines
1.3 KiB
C
#include <math.h>
|
|
#include <stdint.h>
|
|
/* Types */
|
|
typedef float _v2f __attribute__((matrix_type(1,2)));
|
|
typedef float _v3f __attribute__((matrix_type(1,3)));
|
|
typedef float _v4f __attribute__((matrix_type(1,4)));
|
|
|
|
typedef struct {
|
|
union {
|
|
struct {
|
|
float first;
|
|
_v3f tail;
|
|
};
|
|
struct {
|
|
_v2f first_half;
|
|
_v2f second_half;
|
|
};
|
|
struct {
|
|
_v3f v3f;
|
|
float last;
|
|
};
|
|
_v4f v4f;
|
|
struct {
|
|
float r;
|
|
float g;
|
|
float b;
|
|
float a;
|
|
};
|
|
struct {
|
|
float x;
|
|
float y;
|
|
float z;
|
|
float w;
|
|
};
|
|
};
|
|
} vec4f;
|
|
|
|
typedef struct {
|
|
vec4f position; // center pos
|
|
float radius; // side length
|
|
uint32_t vao;
|
|
uint32_t ebo;
|
|
uint32_t vbo;
|
|
float vertices[7*3]; // 7 vert per hex
|
|
unsigned int indices[6*3]; // 6 triangles to render a hex
|
|
|
|
} hex_t;
|
|
|
|
typedef struct {
|
|
hex_t *hexes;
|
|
uint32_t rows;
|
|
uint32_t columns;
|
|
} hexgrid_t;
|
|
|
|
_Static_assert(sizeof(vec4f) == sizeof(float) * 4, "Bad vector size");
|
|
|
|
/* Functions */
|
|
double sint(double turns)
|
|
{
|
|
return sin(turns*2*M_PI);
|
|
}
|
|
|
|
double cost(double turns)
|
|
{
|
|
return cos(turns*2*M_PI);
|
|
}
|