From http://www.jwz.org/xscreensaver/xscreensaver-5.31.tar.gz
[xscreensaver] / hacks / glx / involute.h
1 /* involute, Copyright (c) 2004-2014 Jamie Zawinski <jwz@jwz.org>
2  *
3  * Permission to use, copy, modify, distribute, and sell this software and its
4  * documentation for any purpose is hereby granted without fee, provided that
5  * the above copyright notice appear in all copies and that both that
6  * copyright notice and this permission notice appear in supporting
7  * documentation.  No representations are made about the suitability of this
8  * software for any purpose.  It is provided "as is" without express or 
9  * implied warranty.
10  *
11  * Utilities for rendering OpenGL gears with involute teeth.
12  */
13
14 #ifndef __GEAR_INVOLUTE_H__
15 #define __GEAR_INVOLUTE_H__
16
17 typedef struct {
18   unsigned long id;          /* unique name */
19   double x, y, z;            /* position */
20   double r;                  /* radius of the gear, at middle of teeth */
21   double th;                 /* rotation (degrees) */
22
23   GLint nteeth;              /* how many teeth */
24   double tooth_w, tooth_h;   /* size of teeth */
25
26   double tooth_slope;        /* 0 for normal right-angle gear; 1 = 45 deg. */
27   double inner_r;            /* radius of the (larger) inside hole */
28   double inner_r2;           /* radius of the (smaller) inside hole, if any */
29   double inner_r3;           /* yet another */
30
31   double thickness;          /* height of the edge */
32   double thickness2;         /* height of the (smaller) inside disc if any */
33   double thickness3;         /* yet another */
34   int spokes;                /* how many spokes inside, if any */
35   int nubs;                  /* how many little nubbly bits, if any */
36   double spoke_thickness;    /* spoke versus hole */
37   double wobble;             /* factory defect! */
38   int motion_blur_p;         /* whether it's spinning too fast to draw */
39   int polygons;              /* how many polys in this gear */
40
41   double ratio;              /* gearing ratio with previous gears */
42   double rpm;                /* approximate revolutions per minute */
43
44   Bool inverted_p;           /* whether this gear has teeth on the inside */
45   Bool base_p;               /* whether this gear begins a new train */
46   int coax_p;                /* whether this is one of a pair of bound gears.
47                                 1 for first, 2 for second. */
48   double coax_displacement;  /* distance between gear planes */
49
50   double coax_thickness;     /* thickness of the other gear in the pair */
51
52   enum { INVOLUTE_SMALL, 
53          INVOLUTE_MEDIUM, 
54          INVOLUTE_LARGE, 
55          INVOLUTE_HUGE } size;  /* Controls complexity of mesh. */
56   GLfloat color[4];
57   GLfloat color2[4];
58
59   GLuint dlist;
60 } gear;
61
62 /* Render one gear, unrotated at 0,0.
63    Returns the number of polygons.
64  */
65 extern int draw_involute_gear (gear *g, Bool wire_p);
66
67 /* Draws a much simpler representation of a gear.
68    Returns the number of polygons.
69  */
70 extern int draw_involute_schematic (gear *g, Bool wire_p);
71
72 /* Which of the gear's inside rings is the biggest? 
73  */
74 extern int involute_biggest_ring (gear *g,
75                                   double *posP, double *sizeP,
76                                   double *heightP);
77
78 #endif /* __GEAR_INVOLUTE_H__ */