altEngine
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
common.h
Go to the documentation of this file.
1 #include "include.h"
2 
3 #ifndef COMMON_H
4 #define COMMON_H
5 
6 //random in the range [0, 1]
7 #define random() ((rand () & 0x7fff) / ((float)0x7fff))
8 //random in the range [-1, 1]
9 #define crandom() (2.0f * (random() - 0.5f))
10 
11 // When colliding with a wall, velocity towards the wall is clipped
12 // This is extra clipping past what is necessary, making you stay further away from walls
13 #define BOUNCE 1.2f
14 
15 
16 #pragma pack(1)
17 typedef struct
18 {
19  unsigned char b;
20  unsigned char g;
21  unsigned char r;
22 } pixel_t;
23 #pragma pack(8)
24 
25 typedef struct
26 {
27  int sequence;
28  double time;
29 } ping_t;
30 
31 
32 //float fabs(float val);
33 void gen_normalmap(float scale, const pixel_t *pixel, pixel_t *pixelout, int width, int height);
34 bool aabb_visible(vec3 &min, vec3 &max, matrix4 &mvp);
35 bool RayTriangleMT(vec3 &origin, vec3 &dir, vec3 &a, vec3 &b, vec3 &c, float &t, float &u, float &v);
36 bool RaySphere(vec3 &origin, vec3 &dir, vec3 &sphere, float radius, float &t);
37 bool RayPlane(vec3 &origin, vec3 &dir, vec3 &normal, float d, vec3 &point);
38 bool RayBoxSlab(vec3 &origin, vec3 &dir, vec3 &min, vec3 &max, float &distance);
39 void quadratic_bezier_curve(vec3 &a, vec3 &b, vec3 &c, float time, vec3 &out);
40 void cubic_bezier_curve(vec3 &a, vec3 &b, vec3 &c, vec3 &d, float time, vec3 &out);
41 void bicubic_bezier_surface(vec3 *control, float time_x, float time_y, vec3 &out);
42 void quadratic_bezier_surface(vec3 *control, float time_x, float time_y, vec3 &out);
43 void tessellate_quadratic_bezier_surface(vec3 *control, vertex_t *&vertex, int *&index, int &num_vertex, int &num_index, float level);
44 void CreateSphere(int sides, float radius, vertex_t *&vertex, unsigned int *&index, unsigned int &num_vertex, unsigned int &num_index, bool invert);
45 void make_skybox(Graphics &gfx, unsigned int num_vertex, unsigned int &num_index, int &skybox_vertex, int &skybox_index, bool sphere);
46 
47 char *get_file(char *filename, int *size);
48 int get_zipfile(char *zipfile, char *file, unsigned char **data, int *size);
49 int list_zipfile(char *zipfile, char *filelist);
50 int write_file(char *filename, const char *bytes, int size);
51 float sign(float x);
52 void newlinelist(char *filename, char **list, unsigned int &num, char **file);
53 void calc_hash(char *filename, char *hash);
54 
55 void navdata_to_graph(ref_t *&ref, graph_node_t *&node, vector<Entity *> &entity_list, int start);
56 void print_graph(graph_node_t *node, int num_node);
57 void print_path(int *path, int path_length, graph_node_t *node);
58 float rand_float(float fMin, float fAdd);
59 int gen_spiral(Graphics &gfx, unsigned int &ibo, unsigned int &vbo);
60 int gen_lightning(Graphics &gfx, unsigned int &ibo, unsigned int &vbo);
61 void WriteObj(char *filename, vertex_t *vertex_array, unsigned int num_vertex, unsigned int *index_array, unsigned int num_index);
62 
63 void delta_compress(char *output, char *input, char *delta, int size);
64 void delta_uncompress(char *output, char *input, char *delta, int size);
65 void runlength_encode(uint8_t *output, rletable_t *table, int *table_size, uint8_t *input, unsigned int *size);
66 void runlength_decode(uint8_t *output, rletable_t *table, uint8_t *input, unsigned int *size);
67 char *get_pakfile(char *pakfile, char *file);
68 char *get_wadfile(char *wadfile, char *lump, int *lump_size, char **file);
69 void lump_to_wave(char *lump_data, int size, wave_t *wave);
70 void write_bitmap(char *filename, int width, int height, int *data);
71 void ping_time_start(int sequence);
72 double ping_time_end(int sequence);
73 int clamp(int value, int min, int max);
74 float clamp(float value, float min, float max);
75 int gjk(const vec3 *shape1, const vec3 *shape2, const int iterations, const int num_vert_one, const int num_vert_two);
76 void ClipVelocity(vec3 &in, vec3 &normal);
77 
78 float random_float();
79 
80 double GetCounter(double freq);
81 extern double freq;
82 void pid_controller(const vec3 &target, const float timestep, const vec3 &pos, vec3 &thrust, const float kd);
83 
84 void init_pid(pid_state_t *pid);
85 void update_pid(pid_state_t *pid, const vec3 &target, const vec3 &position, vec3 &output);
86 
87 int auto_complete(const char *a, const char *b);
88 
89 int separating_axis_theorem(const vec3 *box_a, const vec3 *box_b);
90 
91 struct cpuinfo
92 {
93  char vendor[13], serial[9];
96 };
97 
98 struct cpuinfo2
99 {
100  char vendor[13], serial[9];
103 };
104 
105 
106 // Lerp between A and B where time is within [0,1]
107 inline void lerp(vec3 &a, vec3 &b, float time, vec3 &out)
108 {
109  out = a * (1 - time) + b * time;
110 }
111 
112 #endif