-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgeometry.h
60 lines (48 loc) · 1.43 KB
/
geometry.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#ifndef GEOMETRY_H_
#define GEOMETRY_H_
#include <stdio.h>
#include <stdbool.h>
#include <limits.h>
#define INIT_BUFSIZE_VERTICES 1024
#define INIT_BUFSIZE_FACES 1024
#define ERROR_VERTEX UINT_MAX
// Utility
#define FREE(P) do { if(P) free(P); P = NULL; } while(0)
#define error_printf(...) do {\
fprintf(stderr, "ERROR(%s) : ", __func__);\
fprintf(stderr, __VA_ARGS__);\
} while(0)
typedef struct {
double x;
double y;
double z;
} vertex_t;
typedef unsigned vertex_id;
typedef struct {
vertex_id v1;
vertex_id v2;
vertex_id v3;
} face_t;
void init_geometry();
void finalize_geometry();
bool is_valid_id(const vertex_id id);
// Constructors
vertex_id new_vertex(const double x, const double y, const double z);
vertex_id copy_vertex(const vertex_id v);
void new_face(const vertex_id v1, const vertex_id v2, const vertex_id v3);
// Accessor
double get_x(const vertex_id v);
double get_y(const vertex_id v);
double get_z(const vertex_id v);
vertex_t get_point(const vertex_id v);
// Affine transformations
bool vertex_translate(const vertex_id *vs, const unsigned len,
const double x, const double y, const double z);
bool vertex_scale(const vertex_id *vs, const unsigned len,
const double x, const double y, const double z);
bool vertex_rotate(const vertex_id *vs,
const unsigned len, const double degree,
const double nx, const double ny, const double nz);
// Flush as Wavefront OBJ file format
bool flushOBJ(FILE *fp);
#endif