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
|
/*
* screw.c
*
* FUNCTION:
* Draws a screw shape.
*
* HISTORY:
* -- created by Linas Vepstas October 1991
* -- heavily modified to draw more texas shapes, Feb 1993, Linas
* -- converted to use GLUT -- December 1995, Linas
* Copyright (c) 1991, 1993, 1995 Linas Vepstas <linas@linas.org>
*
*/
/* required include files */
#include <math.h>
#include <stdlib.h>
#include <GL/gl.h>
#include <GL/glut.h>
#include <GL/gle.h>
#include "main.h"
#include "texture.h"
/* =========================================================== */
#define SCALE 1.3
#define CONTOUR(x,y) { \
double ax, ay, alen; \
contour[i][0] = SCALE * (x); \
contour[i][1] = SCALE * (y); \
if (i!=0) { \
ax = contour[i][0] - contour[i-1][0]; \
ay = contour[i][1] - contour[i-1][1]; \
alen = 1.0 / sqrt (ax*ax + ay*ay); \
ax *= alen; ay *= alen; \
norms [i-1][0] = ay; \
norms [i-1][1] = -ax; \
} \
i++; \
}
#define NUM_PTS (25)
double contour [NUM_PTS][2];
double norms [NUM_PTS][2];
static void init_contour (void)
{
int i;
/* outline of extrusion */
i=0;
CONTOUR (1.0, 1.0);
CONTOUR (1.0, 2.9);
CONTOUR (0.9, 3.0);
CONTOUR (-0.9, 3.0);
CONTOUR (-1.0, 2.9);
CONTOUR (-1.0, 1.0);
CONTOUR (-2.9, 1.0);
CONTOUR (-3.0, 0.9);
CONTOUR (-3.0, -0.9);
CONTOUR (-2.9, -1.0);
CONTOUR (-1.0, -1.0);
CONTOUR (-1.0, -2.9);
CONTOUR (-0.9, -3.0);
CONTOUR (0.9, -3.0);
CONTOUR (1.0, -2.9);
CONTOUR (1.0, -1.0);
CONTOUR (2.9, -1.0);
CONTOUR (3.0, -0.9);
CONTOUR (3.0, 0.9);
CONTOUR (2.9, 1.0);
CONTOUR (1.0, 1.0); /* repeat so that last normal is computed */
}
/* =========================================================== */
void InitStuff (void)
{
int style;
/* pick model-vertex-cylinder coords for texture mapping */
TextureStyle (509);
/* configure the pipeline */
style = TUBE_JN_CAP;
style |= TUBE_CONTOUR_CLOSED;
style |= TUBE_NORM_FACET;
style |= TUBE_JN_ANGLE;
gleSetJoinStyle (style);
lastx = 121.0;
lasty = 121.0;
init_contour();
}
/* =========================================================== */
void DrawStuff (void)
{
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glColor3f (0.5, 0.6, 0.6);
/* set up some matrices so that the object spins with the mouse */
glPushMatrix ();
glTranslatef (0.0, 0.0, -80.0);
glRotatef (130.0, 0.0, 1.0, 0.0);
glRotatef (65.0, 1.0, 0.0, 0.0);
/* draw the brand and the handle */
gleScrew (20, contour, norms,
NULL, -6.0, 9.0, lasty);
glPopMatrix ();
glutSwapBuffers ();
}
/* ===================== END OF FILE ================== */
|