server_clip.c revision e0e0c19eefceaf5d4ec40f9466b58a771f50e799
/* Copyright (c) 2001, Stanford University
* All rights reserved
*
* See the file LICENSE.txt for information on redistributing this software.
*/
/*
* This code contributed by Karl Rasche <rkarl@vr.clemson.edu>
*/
#include <math.h>
#include "cr_server.h"
#include "cr_mem.h"
#include "server.h"
static void
double *intr)
{
double A, B, T;
v1[0] = e[0] - s[0];
{
if (B)
T = A/B;
else
{
T = 0;
}
}
else
if (v1[1])
{
/* clp -> clp_next is vertical */
}
else
{
/* s -> e is horizontal */
}
}
static void
double *norm,
double **new_poly_in, int *new_npnts_in,
double **new_poly_out, int *new_npnts_out)
{
double *s, *e, intr[2];
*new_npnts_in = 0;
*new_npnts_out = 0;
s = poly;
for (a=0; a<npnts; a++)
{
ein = 0;
else
ein = 1;
sin = 0;
else
sin = 1;
{
/* case 1: */
(*new_npnts_in)++;
}
else
{
/* case 2: */
(*new_npnts_in)++;
(*new_npnts_out)++;
(*new_npnts_out)++;
}
else
{
/* case 4: */
(*new_npnts_in)++;
(*new_npnts_in)++;
(*new_npnts_out)++;
}
else
{
(*new_npnts_out)++;
}
s = e;
}
}
/*
* Sutherland/Hodgman clipping for interior & exterior regions.
* length_of((*new_vert_out)[a]) == nclip_to_vert
*/
static void
double **new_vert_in, int *nnew_vert_in,
double ***new_vert_out, int **nnew_vert_out)
{
double *clip_normals, *s, *e, *n, *new_vert_src;
double **out;
/*
* First, compute normals for the clip poly. This
* breaks for multiple (3+) adjacent colinear verticies
*/
for (a=0; a<nclip_to_vert; a++)
{
s = clip_to_poly+2*a;
/*
* if dot(norm, n-e) > 0), the normals are backwards,
* assuming the clip region is convex
*/
{
norm[0] *= -1;
}
}
{
*nnew_vert_in = 0;
nvert = *nnew_vert_in;
}
}
/*
* Given a bitmap and a group of 'base' polygons [the quads we are testing],
* perform the unions and differences specified by the map and return
* the resulting geometry
*/
static void
{
int a, b, got_intr;
got_intr = 0;
/* first, intersect the first 2 polys marked */
for (a=0; a<n; a++)
if (mask[a]) break;
for (b=a+1; b<n; b++)
if (mask[b]) break;
last = b;
if (out[a])
if (nin)
{
got_intr = 1;
}
while (1)
{
for (a=last+1; a<n; a++)
if (mask[a]) break;
if (a == n) break;
if (got_intr)
{
if (out[b])
if (nin)
{
}
else
{
got_intr = 0;
break;
}
}
else
{
{
if (out[b])
}
if (nin)
{
got_intr = 1;
}
}
last = a;
if (a == n) break;
}
/* can't subract something from nothing! */
if (got_intr)
else
return;
/* find the first item to subtract */
for (a=0; a<n; a++)
if (!mask[a]) break;
if (a == n) return;
last = a;
/* and subtract it */
{
if (!nout[a]) continue;
diff = p;
}
while (1)
{
for (a=last+1; a<n; a++)
if (!mask[a]) break;
if (a == n) return;
last = a;
/* subtract mask[a] from everything in intr and
* plop it into diff */
while (intr)
{
{
if (!nout[a]) continue;
diff = p;
}
}
}
}
/*
* Here we generate all valid bitmaps to represent union/difference
* conbinations. Each bitmap is N elements long, where N is the
* number of polys [quads] that we are testing for overlap
*/
static void
{
int a, b, c, d, e;
for (a=0; a<pow(2, n); a++)
/* compute combinations */
idx = 0;
{
for (a=0; a<n; a++)
{
for (b=a+1; b<n; b++)
{
add = 1;
for (c=0; c<isec_size; c++)
{
i = (b+c) % n;
if (i == a) add = 0;
}
/* dup check */
{
for (d=0; d<idx; d++)
{
add = 0;
for (e=0; e<n; e++)
{
add = 1;
}
if (!add)
break;
}
}
if (add)
idx++;
}
}
}
}
/*
* To compute the overlap between a series of quads (This should work
* for n-gons, but we'll only need quads..), first generate a series of
* bitmaps that represent which elements to union together, and which
* to difference. This goes into 'mask'. We then evaluate each bitmap with
* Sutherland-Hodgman clipping to find the interior (union) and exterior
* (difference) regions.
*
* In the map, 1 == union, 0 == difference
*
* (*res)[a] is the head of a poly list for all the polys that conver
* regions of overlap between a+1 polys ((*res)[0] == NULL)
*/
void
{
for (a=0; a<nquad; a++)
{
p->npoints = 4;
for (b=0; b<8; b++)
{
}
base[a] = p;
}
for (a=0; a<nquad; a++)
for (a=0; a<idx; a++)
{
isec_size = 0;
for (b=0; b<nquad; b++)
isec_size--;
while (p)
{
p = next;
}
}
for (a=0; a<nquad; a++)
{
}
}
/*
* This is similar to ComputeOverlapGeom above, but for "knockout"
* edge blending.
*
* my_quad_idx is an index of quads indicating which display tile
* we are computing geometry for. From this, we either generate
* geometry, or not, such that all geometry can be drawn in black
* and only one tile will show through the blend as non-black.
*
* To add a combination to our set of geom, we must test that:
* + mask[a][my_quad_idx] is set
* + mask[a][my_quad_idx] is not the first element set in
* mask[a].
* If these conditions hold, execute mask[a] and draw the resulting
* geometry in black
*
* Unlike ComputeOverlapGeom, res is just a list of polys to draw in black
*/
void
{
for (a=0; a<nquad; a++)
{
p->npoints = 4;
for (b=0; b<8; b++)
{
}
base[a] = p;
}
for (a=0; a<idx; a++)
{
/* test for above conditions */
if (!mask[a][my_quad_idx]) continue;
first = -1;
for (b=0; b<nquad; b++)
if (mask[a][b])
{
first = b;
break;
}
if (first == my_quad_idx) continue;
while (p)
{
*res = p;
p = next;
}
}
for (a=0; a<nquad; a++)
{
}
}