-
Notifications
You must be signed in to change notification settings - Fork 75
/
mesh.h
127 lines (112 loc) · 5.33 KB
/
mesh.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#ifndef MESH_H__
#define MESH_H__
/*
Copyright (C) 2010 Stephen M. Cameron
Author: Stephen M. Cameron
This file is part of Spacenerds In Space.
Spacenerds in Space is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
Spacenerds in Space is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Spacenerds in Space; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifdef DEFINE_MESH_GLOBALS
#define GLOBAL
#else
#define GLOBAL extern
#endif
#define MESH_GEOMETRY_TRIANGLES 0
#define MESH_GEOMETRY_LINES 1
#define MESH_GEOMETRY_POINTS 2
#define MESH_GEOMETRY_PARTICLE_ANIMATION 3
#define MESH_LINE_STRIP (1<<1)
#define MESH_LINE_DOTTED (1<<2)
#include "snis_graph.h"
#include "open-simplex-noise.h"
struct mesh_line
{
struct vertex *start;
struct vertex *end;
int flag;
float additivity;
float opacity;
struct sng_color tint_color;
float time_offset;
};
struct texture_coord {
float u, v;
};
struct mesh {
int geometry_mode;
int ntriangles;
int nvertices;
int nlines;
struct triangle *t;
struct vertex *v;
struct mesh_line *l;
struct texture_coord *tex; /* if not null, contains 3 (u,v)'s per triangle */
struct material *material; /* for now just one material */
void *graph_ptr;
float radius;
};
GLOBAL float mesh_compute_radius(struct mesh *m);
GLOBAL float mesh_compute_nonuniform_scaled_radius(struct mesh *m, double sx, double sy, double sz);
GLOBAL void mesh_distort(struct mesh *m, float distortion, struct osn_context *osn);
GLOBAL void mesh_derelict(struct mesh *m, float distortion);
GLOBAL struct mesh *mesh_duplicate(struct mesh *original);
GLOBAL void mesh_scale(struct mesh *m, float scale);
GLOBAL void mesh_add_point(struct mesh *m, float x, float y, float z);
GLOBAL void mesh_add_line_last_2(struct mesh *m, int flag);
GLOBAL struct mesh *init_circle_mesh(double x, double y, double r, int npoints, double angle);
GLOBAL struct mesh *init_radar_circle_xz_plane_mesh(double x, double z, double r, int ticks, double tick_radius);
GLOBAL struct mesh *init_line_mesh(double x1, double y1, double z1, double x2, double y2, double z2);
GLOBAL struct mesh *mesh_fabricate_axes(void);
GLOBAL void mesh_graph_dev_init(struct mesh *m);
GLOBAL void mesh_graph_dev_cleanup(struct mesh *m);
GLOBAL void mesh_set_flat_shading_vertex_normals(struct mesh *m);
GLOBAL void mesh_set_spherical_vertex_normals(struct mesh *m);
GLOBAL void mesh_set_spherical_cubemap_tangent_and_bitangent(struct mesh *m);
GLOBAL void mesh_set_average_vertex_normals(struct mesh *m);
GLOBAL void mesh_set_reasonable_tangent_and_bitangent(struct vertex *vnormal,
struct vertex *vtangent, struct vertex *vbitangent);
GLOBAL void mesh_set_reasonable_tangents_and_bitangents(struct mesh *m);
GLOBAL void mesh_set_mikktspace_tangents_and_bitangents(struct mesh *m);
GLOBAL struct mesh *mesh_fabricate_crossbeam(float length, float radius);
GLOBAL void mesh_set_triangle_texture_coords(struct mesh *m, int triangle,
float u1, float v1, float u2, float v2, float u3, float v3);
GLOBAL struct mesh *mesh_fabricate_billboard(float width, float height);
GLOBAL struct mesh *mesh_fabricate_billboard_with_uv_map(float width, float height,
float u1, float v1, float u2, float v2);
GLOBAL struct mesh *mesh_fabricate_disc(float radius, int nslices);
GLOBAL struct mesh *mesh_unit_icosahedron(void);
GLOBAL struct mesh *mesh_unit_icosphere(int subdivisions);
GLOBAL struct mesh *mesh_unit_cube(int subdivisions);
GLOBAL struct mesh *mesh_unit_spherified_cube(int subdivisions);
GLOBAL void mesh_free(struct mesh *m);
GLOBAL void mesh_sphere_uv_map(struct mesh *m);
GLOBAL void mesh_cylindrical_yz_uv_map(struct mesh *m);
GLOBAL void mesh_cylindrical_xy_uv_map(struct mesh *m);
GLOBAL void mesh_cylindrical_xz_uv_map(struct mesh *m);
GLOBAL void mesh_unit_cube_uv_map(struct mesh *m);
GLOBAL void mesh_map_xy_to_uv(struct mesh *m);
GLOBAL void mesh_distort_and_random_uv_map(struct mesh *m, float distortion, struct osn_context *osn);
GLOBAL struct mesh *mesh_fabricate_planetary_ring(float ir, float or, int nvertices);
GLOBAL struct mesh *init_thrust_mesh(int streaks, double h, double r1);
GLOBAL struct mesh *init_burst_rod_mesh(int streaks, double h, double r1, double r2);
GLOBAL void mesh_update_material(struct mesh *m, struct material *material);
GLOBAL void mesh_rotate(struct mesh *m, union quat *q);
GLOBAL struct mesh *mesh_tube(float h, float r, float nfaces);
/* Given point x, y, z and assuming mesh m is at origin, return the index of the
* closest vertex to x, y, z. Distance is returned in *dist unless dist is NULL.
*/
GLOBAL int mesh_nearest_vertex(struct mesh *m, float x, float y, float z, float sx, float sy, float sz, float *dist);
/* Return axis aligned bounding box for a mesh in min[x,y,z], max[x,y,z] */
GLOBAL void mesh_aabb(struct mesh *m, float *minx, float *miny, float *minz, float *maxx, float *maxy, float *maxz);
#undef GLOBAL
#endif