1 /* 2 V3D Model Primitives 3 4 Data types for basic V3D model primitives used to represent 5 data and used for OpenGL style drawing. 6 7 When adding new types, make sure you update V3DMPCreate() and 8 V3DMPDup() to allocate the correct size of the data type structure 9 and update V3DMPDestroy() to deallocate and members that may point 10 to allocated resources. Externally, you may need to update other 11 functions. 12 13 */ 14 15 #ifndef V3DMP_H 16 #define V3DMP_H 17 18 #include <sys/types.h> 19 20 #ifdef __cplusplus 21 extern "C" { 22 #endif /* __cplusplus */ 23 24 25 /* General purpose vertex structure. */ 26 typedef struct { 27 28 double x, y, z, m; 29 30 } mp_vertex_struct; 31 32 33 /* Model primitives structure type codes. */ 34 #define V3DMP_TYPE_COMMENT 1 35 36 #define V3DMP_TYPE_TRANSLATE 10 37 #define V3DMP_TYPE_UNTRANSLATE 11 38 #define V3DMP_TYPE_ROTATE 12 39 #define V3DMP_TYPE_UNROTATE 13 40 41 #define V3DMP_TYPE_POINT 20 42 #define V3DMP_TYPE_LINE 21 43 #define V3DMP_TYPE_LINE_STRIP 22 44 #define V3DMP_TYPE_LINE_LOOP 23 45 #define V3DMP_TYPE_TRIANGLE 24 46 #define V3DMP_TYPE_TRIANGLE_STRIP 25 47 #define V3DMP_TYPE_TRIANGLE_FAN 26 48 #define V3DMP_TYPE_QUAD 27 49 #define V3DMP_TYPE_QUAD_STRIP 28 50 #define V3DMP_TYPE_POLYGON 29 51 52 #define V3DMP_TYPE_COLOR 50 53 #define V3DMP_TYPE_TEXTURE_SELECT 51 54 #define V3DMP_TYPE_TEXTURE_ORIENT_XY 52 55 #define V3DMP_TYPE_TEXTURE_ORIENT_YZ 53 56 #define V3DMP_TYPE_TEXTURE_ORIENT_XZ 54 57 #define V3DMP_TYPE_TEXTURE_OFF 55 58 #define V3DMP_TYPE_HEIGHTFIELD_LOAD 56 59 60 61 /* 62 * Model primitive structures: 63 */ 64 65 /* Comment. */ 66 typedef struct { 67 int type; /* Must be V3DMP_TYPE_COMMENT. */ 68 char **line; 69 int total_lines; 70 } mp_comment_struct; 71 72 73 /* Translate. */ 74 typedef struct { 75 int type; /* Must be V3DMP_TYPE_TRANSLATE. */ 76 double x, y, z; /* In meters. */ 77 } mp_translate_struct; 78 /* Untranslate. */ 79 typedef struct { 80 int type; /* Must be V3DMP_TYPE_UNTRANSLATE. */ 81 } mp_untranslate_struct; 82 83 /* Rotate. */ 84 typedef struct { 85 int type; /* Must be V3DMP_TYPE_ROTATE. */ 86 double heading, bank, pitch; /* In radians. */ 87 } mp_rotate_struct; 88 /* Unrotate. */ 89 typedef struct { 90 int type; /* Must be V3DMP_TYPE_UNROTATE. */ 91 } mp_unrotate_struct; 92 93 94 /* Point. */ 95 typedef struct { 96 int type; /* Must be V3DMP_TYPE_POINT. */ 97 #define V3DMP_POINT_NVERTEX 1 98 mp_vertex_struct v[V3DMP_POINT_NVERTEX]; 99 mp_vertex_struct n[V3DMP_POINT_NVERTEX]; 100 mp_vertex_struct tc[V3DMP_POINT_NVERTEX]; 101 double r; 102 } mp_point_struct; 103 104 /* Line. */ 105 typedef struct { 106 int type; /* Must be V3DMP_TYPE_LINE. */ 107 #define V3DMP_LINE_NVERTEX 2 108 mp_vertex_struct v[V3DMP_LINE_NVERTEX]; 109 mp_vertex_struct n[V3DMP_LINE_NVERTEX]; 110 mp_vertex_struct tc[V3DMP_LINE_NVERTEX]; 111 } mp_line_struct; 112 113 /* Line strip. */ 114 typedef struct { 115 int type; /* Must be V3DMP_TYPE_LINE_STRIP. */ 116 mp_vertex_struct **v; 117 mp_vertex_struct **n; 118 mp_vertex_struct **tc; 119 int total; 120 } mp_line_strip_struct; 121 122 /* Line loop. */ 123 typedef struct { 124 int type; /* Must be V3DMP_TYPE_LINE_LOOP. */ 125 mp_vertex_struct **v; 126 mp_vertex_struct **n; 127 mp_vertex_struct **tc; 128 int total; 129 } mp_line_loop_struct; 130 131 /* Triangle. */ 132 typedef struct { 133 int type; /* Must be V3DMP_TYPE_TRIANGLE. */ 134 #define V3DMP_TRIANGLE_NVERTEX 3 135 mp_vertex_struct v[V3DMP_TRIANGLE_NVERTEX]; 136 mp_vertex_struct n[V3DMP_TRIANGLE_NVERTEX]; 137 mp_vertex_struct tc[V3DMP_TRIANGLE_NVERTEX]; 138 } mp_triangle_struct; 139 140 /* Triangle strip. */ 141 typedef struct { 142 int type; /* Must be V3DMP_TYPE_TRIANGLE_STRIP. */ 143 mp_vertex_struct **v; 144 mp_vertex_struct **n; 145 mp_vertex_struct **tc; 146 int total; 147 } mp_triangle_strip_struct; 148 149 /* Triangle fan. */ 150 typedef struct { 151 int type; /* Must be V3DMP_TYPE_TRIANGLE_FAN. */ 152 mp_vertex_struct **v; 153 mp_vertex_struct **n; 154 mp_vertex_struct **tc; 155 int total; 156 } mp_triangle_fan_struct; 157 158 /* Quad. */ 159 typedef struct { 160 int type; /* Must be V3DMP_TYPE_QUAD. */ 161 #define V3DMP_QUAD_NVERTEX 4 162 mp_vertex_struct v[V3DMP_QUAD_NVERTEX]; 163 mp_vertex_struct n[V3DMP_QUAD_NVERTEX]; 164 mp_vertex_struct tc[V3DMP_QUAD_NVERTEX]; 165 } mp_quad_struct; 166 167 /* Quad strip. */ 168 typedef struct { 169 int type; /* Must be V3DMP_TYPE_QUAD_STRIP. */ 170 mp_vertex_struct **v; 171 mp_vertex_struct **n; 172 mp_vertex_struct **tc; 173 int total; 174 } mp_quad_strip_struct; 175 176 /* Polygon. */ 177 typedef struct { 178 int type; /* Must be V3DMP_TYPE_POLYGON. */ 179 mp_vertex_struct **v; 180 mp_vertex_struct **n; 181 mp_vertex_struct **tc; 182 int total; 183 } mp_polygon_struct; 184 185 186 /* Color. */ 187 typedef struct { 188 int type; /* Must be V3DMP_TYPE_COLOR. */ 189 double a, r, g, b; 190 double ambient, diffuse, specular, shininess, emission; 191 } mp_color_struct; 192 193 /* Texture select by reference name. */ 194 typedef struct { 195 int type; /* Must be V3DMP_TYPE_TEXTURE_SELECT. */ 196 char *name; /* Texture reference name. */ 197 void *client_data; /* Client data (can be a number too). */ 198 } mp_texture_select_struct; 199 200 /* Texture orient about xy plane. */ 201 typedef struct { 202 int type; /* Must be V3DMP_TYPE_TEXTURE_ORIENT_XY. */ 203 double x, y; 204 double dx, dy; /* Goes -x to +x and -y to +y. */ 205 } mp_texture_orient_xy_struct; 206 207 /* Texture orient about yz plane. */ 208 typedef struct { 209 int type; /* Must be V3DMP_TYPE_TEXTURE_ORIENT_YZ. */ 210 double y, z; 211 double dy, dz; /* Goes +y to -y and -z to +z. */ 212 } mp_texture_orient_yz_struct; 213 214 /* Texture orient about xz plane. */ 215 typedef struct { 216 int type; /* Must be V3DMP_TYPE_TEXTURE_ORIENT_XZ. */ 217 double x, z; 218 double dx, dz; /* Goes -x to +x and -z to +z. */ 219 } mp_texture_orient_xz_struct; 220 221 /* Texture off (unselect). */ 222 typedef struct { 223 int type; /* Must be V3DMP_TYPE_TEXTURE_OFF. */ 224 } mp_texture_off_struct; 225 226 /* Heightfield load. */ 227 typedef struct { 228 int type; /* Must be V3DMP_TYPE_HEIGHTFIELD_LOAD. */ 229 char *path; 230 void *gl_list; /* GL list (can be NULL). */ 231 double *data; /* Array of heightfield z points (can be NULL). */ 232 int x_points, y_points, total_points; 233 double x_length, y_length, z_length; /* Span. */ 234 double x, y, z; /* Translation. */ 235 double heading, pitch, bank; /* Rotation in radians. */ 236 } mp_heightfield_load_struct; 237 238 239 extern void *V3DMPCreate(int type); 240 extern void *V3DMPDup(const void *p); 241 extern int V3DMPInsertVertex( 242 void *p, int i, 243 mp_vertex_struct **v_rtn, mp_vertex_struct **n_rtn, 244 mp_vertex_struct **tc_rtn 245 ); 246 extern void V3DMPDestroy(void *p); 247 248 #define V3DMPGetType(p) (((p) != NULL) ? (*(int *)(p)) : 0) 249 extern void *V3DMPListGetPtr(void **list, int total, int i); 250 extern void *V3DMPListInsert( 251 void ***list, int *total, int i, 252 int type 253 ); 254 extern void V3DMPListDelete(void ***list, int *total, int i); 255 extern void V3DMPListDeleteAll(void ***list, int *total); 256 257 extern mp_vertex_struct *V3DMPGetNormal(void *p, int i); 258 extern mp_vertex_struct *V3DMPGetVertex(void *p, int i); 259 extern mp_vertex_struct *V3DMPGetTexCoord(void *p, int i); 260 extern int V3DMPGetTotal(void *p); 261 262 extern int V3DMPUnitlizeNormal(void *p); 263 extern int V3DMPFlipWinding( 264 void *p, int flip_normals, int flip_texcoords 265 ); 266 267 268 #ifdef __cplusplus 269 } 270 #endif /* __cplusplus */ 271 272 #endif /* V3DMP_H */ 273