http://packetstormsecurity.org/UNIX/admin/xscreensaver-4.04.2.tar.gz
[xscreensaver] / hacks / glx / marching.h
1 /* xscreensaver, Copyright (c) 2002 Jamie Zawinski <jwz@jwz.org>
2  * Utility functions to create "marching cubes" meshes from 3d fields.
3  *
4  * Permission to use, copy, modify, distribute, and sell this software and its
5  * documentation for any purpose is hereby granted without fee, provided that
6  * the above copyright notice appear in all copies and that both that
7  * copyright notice and this permission notice appear in supporting
8  * documentation.  No representations are made about the suitability of this
9  * software for any purpose.  It is provided "as is" without express or 
10  * implied warranty.
11  */
12
13 #ifndef __MARCHING_H__
14 #define __MARCHING_H__
15
16 /* Given a function capable of generating a value at any XYZ position,
17    creates OpenGL faces for the solids defined.
18
19    init_fn is called at the beginning for initial, and returns an object.
20    free_fn is called at the end.
21
22    compute_fn is called for each XYZ in the specified grid, and returns
23    the double value of that coordinate.  If smoothing is on, then
24    compute_fn will also be called twice more for each emitted vertex,
25    in order to calculate vertex normals (so don't assume it will only
26    be called with values falling on the grid boundaries.)
27
28    Points are inside an object if the are less than `isolevel', and
29    outside otherwise.
30
31    If polygon_count is specified, the number of faces generated will be
32    returned there.
33 */
34 extern void
35 marching_cubes (int grid_size,     /* density of the mesh */
36                 double isolevel,   /* cutoff point for "in" versus "out" */
37                 int wireframe_p,   /* wireframe, or solid */
38                 int smooth_p,      /* smooth, or faceted */
39
40                 void * (*init_fn)    (double grid_size, void *closure1),
41                 double (*compute_fn) (double x, double y, double z,
42                                       void *closure2),
43                 void   (*free_fn)    (void *closure2),
44                 void *closure1,
45
46                 unsigned long *polygon_count);
47
48 #endif /* __MARCHING_H__ */