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
-
- /* The analyticsurface routine takes a surface description:
- *
- * (x(s, t), y(s, t), z(s, t)),
- *
- * together with the analytic partial derivitives in the s and t
- * directions:
- *
- * (xs(s, t), ys(s, t), zs(s, t)),
- * (xt(s, t), yt(s, t), zt(s, t)),
- *
- * The domains of s values and t values, and counts for the number of
- * subdivisions to take in each direction. If the flag flipnormals is 1,
- * the directions of the calculated normal vectors will be reversed.
- *
- */
-
- void analyticsurface(float (*x)(float, float), float (*y)(float, float),
- float (*z)(float, float),
- float (*xs)(float, float), float (*ys)(float, float),
- float (*zs)(float, float),
- float (*xt)(float, float), float (*yt)(float, float),
- float (*zt)(float, float),
- long scount, float smin, float smax,
- long tcount, float tmin, float tmax,
- long flipnormals,
- void (*savefunc)())
- {
- float s, t, s1, t1;
- long is, it;
- float n0[3], n1[3], n2[3], n3[3];
- float p0[3], p1[3], p2[3], p3[3];
- float v[3], w[3];
-
- for (is = 0; is < scount; is++) {
- s = smin + is*(smax - smin)/scount;
- s1 = s + (smax - smin)/scount;
- for (it = 0; it < tcount; it++) {
- t = smin + it*(tmax - tmin)/scount;
- t1 = t + (tmax - tmin)/scount;
- p0[0] = x(s, t); p0[1] = y(s, t); p0[2] = z(s, t);
- p1[0] = x(s1, t); p1[1] = y(s1, t); p1[2] = z(s1, t);
- p2[0] = x(s1, t1); p2[1] = y(s1, t1); p2[2] = z(s1, t1);
- p3[0] = x(s, t1); p3[1] = y(s, t1); p3[2] = z(s, t1);
-
- /* now calculate the normal vectors: */
-
- v[0] = xs(s, t); v[1] = ys(s, t); v[2] = zs(s, t);
- w[0] = xt(s, t); w[1] = yt(s, t); w[2] = zt(s, t);
- crossprod(v, w, n0);
- normalize(n0);
- if (flipnormals) scalarmult(-1.0, n0, n0);
-
- v[0] = xs(s1, t); v[1] = ys(s1, t); v[2] = zs(s1, t);
- w[0] = xt(s1, t); w[1] = yt(s1, t); w[2] = zt(s1, t);
- crossprod(v, w, n1);
- normalize(n1);
- if (flipnormals) scalarmult(-1.0, n1, n1);
-
- v[0] = xs(s1, t1); v[1] = ys(s1, t1); v[2] = zs(s1, t1);
- w[0] = xt(s1, t1); w[1] = yt(s1, t1); w[2] = zt(s1, t1);
- crossprod(v, w, n2);
- normalize(n2);
- if (flipnormals) scalarmult(-1.0, n2, n2);
-
- v[0] = xs(s, t1); v[1] = ys(s, t1); v[2] = zs(s, t1);
- w[0] = xt(s, t1); w[1] = yt(s, t1); w[2] = zt(s, t1);
- crossprod(v, w, n3);
- normalize(n3);
- if (flipnormals) scalarmult(-1.0, n3, n3);
-
- m_xformpt(p0, p0, n0, n0);
- m_xformpt(p1, p1, n1, n1);
- m_xformpt(p2, p2, n2, n2);
- m_xformpt(p3, p3, n3, n3);
-
- (*savefunc)(ADD_QUAD, n0, p0, n1, p1, n2, p2, n3, p3);
- }
- }
- }
-
-