began for maemo
[xscreensaver] / xscreensaver / hacks / glx / extrusion-screw.c
1 /* 
2  * screw.c
3  * 
4  * FUNCTION:
5  * Draws a screw shape.
6  *
7  * HISTORY:
8  * -- created by Linas Vepstas October 1991
9  * -- heavily modified to draw more texas shapes, Feb 1993, Linas
10  * -- converted to use GLUT -- December 1995, Linas
11  *
12  */
13
14 #include "extrusion.h"
15 #include <stdlib.h>
16 #include <math.h>
17
18 /* =========================================================== */
19
20 #define SCALE 1.3
21 #define CONTOUR(x,y) {                                  \
22    double ax, ay, alen;                                 \
23    contour[i][0] = SCALE * (x);                         \
24    contour[i][1] = SCALE * (y);                         \
25    if (i!=0) {                                          \
26       ax = contour[i][0] - contour[i-1][0];             \
27       ay = contour[i][1] - contour[i-1][1];             \
28       alen = 1.0 / sqrt (ax*ax + ay*ay);                \
29       ax *= alen;   ay *= alen;                         \
30       norms [i-1][0] = ay;                              \
31       norms [i-1][1] = -ax;                             \
32    }                                                    \
33    i++;                                                 \
34 }
35
36 #define NUM_PTS (25)
37
38 static double contour [NUM_PTS][2];
39 static double norms [NUM_PTS][2];
40
41 static void init_contour (void)
42 {
43    int i;
44
45    /* outline of extrusion */
46    i=0;
47    CONTOUR (1.0, 1.0);
48    CONTOUR (1.0, 2.9);
49    CONTOUR (0.9, 3.0);
50    CONTOUR (-0.9, 3.0);
51    CONTOUR (-1.0, 2.9);
52
53    CONTOUR (-1.0, 1.0);
54    CONTOUR (-2.9, 1.0);
55    CONTOUR (-3.0, 0.9);
56    CONTOUR (-3.0, -0.9);
57    CONTOUR (-2.9, -1.0);
58
59    CONTOUR (-1.0, -1.0);
60    CONTOUR (-1.0, -2.9);
61    CONTOUR (-0.9, -3.0);
62    CONTOUR (0.9, -3.0);
63    CONTOUR (1.0, -2.9);
64
65    CONTOUR (1.0, -1.0);
66    CONTOUR (2.9, -1.0);
67    CONTOUR (3.0, -0.9);
68    CONTOUR (3.0, 0.9);
69    CONTOUR (2.9, 1.0);
70
71    CONTOUR (1.0, 1.0);   /* repeat so that last normal is computed */
72 }
73    
74 /* =========================================================== */
75
76 /* controls shape of object */
77 extern float lastx;
78 extern float lasty;
79
80 void InitStuff_screw (void)
81 {
82    int style;
83
84    /* configure the pipeline */
85    style = TUBE_JN_CAP;
86    style |= TUBE_CONTOUR_CLOSED;
87    style |= TUBE_NORM_FACET;
88    style |= TUBE_JN_ANGLE;
89    gleSetJoinStyle (style);
90
91    init_contour();
92 }
93
94 /* =========================================================== */
95
96 void DrawStuff_screw (void) {
97
98    glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
99    glColor3f (0.5, 0.6, 0.6);
100
101    /* set up some matrices so that the object spins with the mouse */
102    glPushMatrix ();
103    /* glTranslatef (0.0, 0.0, -80.0); */
104    /* glRotatef (130.0, 0.0, 1.0, 0.0); */
105    /* glRotatef (65.0, 1.0, 0.0, 0.0); */
106
107    /* draw the brand and the handle */
108    gleScrew (20, contour, norms, 
109                  NULL, -6.0, 9.0, lasty);
110
111    glPopMatrix ();
112 }
113
114 /* ===================== END OF FILE ================== */