X-Git-Url: http://git.hungrycats.org/cgi-bin/gitweb.cgi?p=xscreensaver;a=blobdiff_plain;f=hacks%2Fglx%2Fmarching.c;h=ee5e81e245eb3b00d296d7854da7eee5dbce7349;hp=a4cafb4860c43745865865beee252205adc10476;hb=2d04c4f22466851aedb6ed0f2919d148f726b889;hpb=bc7b7a8eb122206d239ec0e693676bcce31be1aa diff --git a/hacks/glx/marching.c b/hacks/glx/marching.c index a4cafb48..ee5e81e2 100644 --- a/hacks/glx/marching.c +++ b/hacks/glx/marching.c @@ -17,17 +17,15 @@ #include #include #include +#include #include "marching.h" +#include "normals.h" extern char *progname; #undef ABS #define ABS(x) ((x)<0?(-(x)):(x)) -typedef struct { - double x,y,z; -} XYZ; - typedef struct { XYZ p[3]; } TRIANGLE; @@ -463,47 +461,6 @@ march_one_cube (GRIDCELL grid, double isolevel, TRIANGLE *triangles) /* Walking the grid. By jwz. */ -#include - -/* Normalise a vector */ -static void -normalize (XYZ *p) -{ - double length; - length = sqrt(p->x * p->x + p->y * p->y + p->z * p->z); - if (length != 0) { - p->x /= length; - p->y /= length; - p->z /= length; - } else { - p->x = 0; - p->y = 0; - p->z = 0; - } -} - - -/* Calculate the unit normal at p given two other points - p1,p2 on the surface. The normal points in the direction - of p1 crossproduct p2 - */ -static void -do_plane_normal (XYZ p, XYZ p1, XYZ p2) -{ - XYZ n, pa, pb; - pa.x = p1.x - p.x; - pa.y = p1.y - p.y; - pa.z = p1.z - p.z; - pb.x = p2.x - p.x; - pb.y = p2.y - p.y; - pb.z = p2.z - p.z; - n.x = pa.y * pb.z - pa.z * pb.y; - n.y = pa.z * pb.x - pa.x * pb.z; - n.z = pa.x * pb.y - pa.y * pb.x; - normalize (&n); - glNormal3f (n.x, n.y, n.z); -} - /* Computes the normal of the scalar field at the given point, for vertex normals (as opposed to face normals.) @@ -519,7 +476,7 @@ do_function_normal (double x, double y, double z, n.x = compute_fn (x-off, y, z, c) - compute_fn (x+off, y, z, c); n.y = compute_fn (x, y-off, z, c) - compute_fn (x, y+off, z, c); n.z = compute_fn (x, y, z-off, c) - compute_fn (x, y, z+off, c); - normalize (&n); + /* normalize (&n); */ glNormal3f (n.x, n.y, n.z); } @@ -642,7 +599,9 @@ marching_cubes (int grid_size, /* density of the mesh */ this triangle. */ if (!smooth_p) - do_plane_normal (tri[i].p[0], tri[i].p[1], tri[i].p[2]); + do_normal (tri[i].p[0].x, tri[i].p[0].y, tri[i].p[0].z, + tri[i].p[1].x, tri[i].p[1].y, tri[i].p[1].z, + tri[i].p[2].x, tri[i].p[2].y, tri[i].p[2].z); # define VERT(X,Y,Z) \ if (smooth_p) \