home *** CD-ROM | disk | FTP | other *** search
- /*
- * Copyright 1992, 1993, 1994, Silicon Graphics, Inc.
- * All Rights Reserved.
- *
- * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
- * the contents of this file may not be disclosed to third parties, copied or
- * duplicated in any form, in whole or in part, without the prior written
- * permission of Silicon Graphics, Inc.
- *
- * RESTRICTED RIGHTS LEGEND:
- * Use, duplication or disclosure by the Government is subject to restrictions
- * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
- * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
- * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
- * rights reserved under the Copyright Laws of the United States.
- */
-
- /* Tom Davis -- 1992 */
-
- #include "3d.h"
- #include <stdio.h>
- #include <math.h>
- #define PI 3.1415926535
-
- pwlin_t *newpwlin()
- {
- pwlin_t *c = (pwlin_t *)malloc(sizeof(pwlin_t));
- c->n = 0;
- c->verts = 0;
- return c;
- }
-
- pwlin_t *makepwlin(long n, float *data)
- {
- long i;
- pwlin_t *c = newpwlin();
-
- c->n = n;
- c->verts = (float *)malloc(n*3*sizeof(float));
- for (i = 0; i < n*3; i++)
- c->verts[i] = *data++;
- return c;
- }
-
- void freepwlin(pwlin_t *p)
- {
- if (p->verts) free(p->verts);
- free(p);
- }
-
- pwlin_t *appendpwlins(pwlin_t *p1, pwlin_t *p2)
- {
- pwlin_t *p = newpwlin();
- long i, dup = 0;
- float *f;
-
- if (p1->verts[3*p1->n-3] == p2->verts[0] &&
- p1->verts[3*p1->n-2] == p2->verts[1] &&
- p1->verts[3*p1->n-1] == p2->verts[2]) dup = 1;
- p->n = p1->n + p2->n - dup;
- p->verts = f = (float *)malloc(p->n*3*sizeof(float));
- for (i = 0; i < 3*p1->n; i++)
- *f++ = p1->verts[i];
- for (i = dup ? 3 : 0; i < 3*p2->n; i++)
- *f++ = p2->verts[i];
- return p;
- }
-
- /* solidofrevolution rotates about the y-axis */
-
- void smoothsave(long n, float n0[3], float p0[3],
- float n1[3], float p1[3], float n2[3],
- float p2[3], float n3[3], float p3[3])
- {
- addquad(p0, p1, p2, p3, n0);
- }
-
- /* The following code rotates a piecewise linear curve about
- * the y-axis and makes a series of little quadrilaterals.
- */
-
- void solidofrevolution(pwlin_t *pwc, long n, void (*savefunc)())
- {
- long i, j;
- float theta, theta1;
- float c, s, c1, s1;
- float x, y, z = 0.0, x1, y1, z1 = 0.0;
- float p0[3], p1[3], p2[3], p3[3];
- float n0[3], n1[3], n2[3], n3[3];
-
- for (i = 0; i < pwc->n-1; i++)
- for (j = 0; j < n; j++) {
- theta = j*2.0*PI/n;
- theta1 = (j < n-1) ? (j+1)*2.0*PI/n : 0.0;
- c = cos(theta); s = sin(theta);
- c1 = cos(theta1); s1 = sin(theta1);
- x = pwc->verts[3*i]; y = pwc->verts[3*i+1];
- z = pwc->verts[3*i+2]; x1 = pwc->verts[3*i+3];
- y1 = pwc->verts[3*i+4]; z1 = pwc->verts[3*i+5];
-
- p3[0] = x*c - z*s;
- p3[1] = y;
- p3[2] = x*s + z*c;
-
- p2[0] = x1*c - z1*s;
- p2[1] = y1;
- p2[2] = x1*s + z1*c;
-
- p1[0] = x1*c1 - z1*s1;
- p1[1] = y1;
- p1[2] = x1*s1 + z1*c1;
-
- p0[0] = x*c1 - z*s1;
- p0[1] = y;
- p0[2] = x*s1 + z*c1;
-
- if (samepoint(p0, p1) || samepoint(p1, p2))
- perpnorm(p0, p2, p3, n0);
- else
- perpnorm(p0, p1, p2, n0);
-
- m_xformpt(p0, p0, n0, n1);
- m_xformptonly(p1, p1);
- m_xformptonly(p2, p2);
- m_xformptonly(p3, p3);
-
- (*savefunc)(ADD_QUAD, n1, p3, n1, p2, n1, p1, n1, p0);
-
- }
- }
-
- void smoothsolidofrevolution(pwlin_t *pwc, long n, void (*savefunc)())
- {
- solidofrevolution(pwc, n, smoothsave);
- doverts();
- doquads(savefunc);
- }
-
-