1 |
< |
/* Copyright (c) 1998 Silicon Graphics, Inc. */ |
2 |
< |
|
3 |
< |
/* SCCSid "$SunId$ SGI" */ |
4 |
< |
|
1 |
> |
/* RCSid: $Id$ */ |
2 |
|
/* |
3 |
|
* sm_geom.h |
4 |
|
*/ |
7 |
|
|
8 |
|
#include <values.h> |
9 |
|
|
10 |
+ |
#ifdef SMLFLT |
11 |
+ |
#define EQUALITY_EPS 1e-6 |
12 |
+ |
#else |
13 |
+ |
#define EQUALITY_EPS 1e-10 |
14 |
+ |
#endif |
15 |
+ |
|
16 |
+ |
#define F_TINY 1e-10 |
17 |
+ |
#define FZERO(x) ((x) < F_TINY && (x) > -F_TINY) |
18 |
+ |
#define FEQUAL(a,b) FZERO((a) - (b)) |
19 |
+ |
|
20 |
|
#define ZERO(x) ((x) < FTINY && (x) > -FTINY) |
21 |
|
#define EQUAL(a,b) ZERO((a) - (b)) |
22 |
|
|
25 |
|
#define FALSE 0 |
26 |
|
#endif |
27 |
|
|
28 |
+ |
typedef struct _FPEQ { |
29 |
+ |
FVECT n; |
30 |
+ |
double d; |
31 |
+ |
char x,y,z; |
32 |
+ |
}FPEQ; |
33 |
+ |
|
34 |
+ |
#define FP_N(f) ((f).n) |
35 |
+ |
#define FP_D(f) ((f).d) |
36 |
+ |
#define FP_X(f) ((f).x) |
37 |
+ |
#define FP_Y(f) ((f).y) |
38 |
+ |
#define FP_Z(f) ((f).z) |
39 |
+ |
|
40 |
|
typedef long BCOORD; |
41 |
|
typedef long BDIR; |
42 |
< |
typedef long TINT; |
43 |
< |
#define BITS_BCOORD (BITS(long)>>1) |
44 |
< |
#define SHIFT_MAXBCOORD (BITS_BCOORD-2) |
45 |
< |
#define MAXBCOORD (1L << SHIFT_MAXBCOORD) |
42 |
> |
|
43 |
> |
#define BITS_BCOORD (BITS(long)-2) |
44 |
> |
#define SHIFT_MAXBCOORD (BITS_BCOORD-1) |
45 |
> |
#define MAXBCOORD ((1L << BITS_BCOORD)-1) |
46 |
|
#define MAXBCOORD2 (MAXBCOORD>>1) |
47 |
< |
#define MAXBDIR MAXBCOORD |
29 |
< |
#define MAXT MAXBCOORD |
30 |
< |
#define HUGET MAXLONG |
47 |
> |
#define MAXBCOORD4 (MAXBCOORD2>>1) |
48 |
|
|
49 |
|
#define M_2_3_PI PI*2/3 |
50 |
|
|
51 |
+ |
#ifndef INVALID |
52 |
|
#define INVALID -1 |
53 |
+ |
#endif |
54 |
+ |
#define IADDV3(v,a) ((v)[0] += (a)[0],(v)[1] += (a)[1],(v)[2] += (a)[2]) |
55 |
+ |
#define ISUBV3(v,a) ((v)[0] -= (a)[0],(v)[1] -= (a)[1],(v)[2] -= (a)[2]) |
56 |
+ |
#define ISCALEV3(v,a) ((v)[0] *= (a),(v)[1] *= (a),(v)[2] *= (a)) |
57 |
+ |
#define IDIVV3(v,a) ((v)[0] /= (a),(v)[1] /= (a),(v)[2] /= (a)) |
58 |
|
|
36 |
– |
#define GT_INVALID 0 |
37 |
– |
#define GT_VERTEX 1 |
38 |
– |
#define GT_EDGE 2 |
39 |
– |
#define GT_FACE 4 |
40 |
– |
#define GT_INTERIOR 8 |
41 |
– |
#define GT_INTERSECT 16 |
42 |
– |
#define GT_ADJACENT 32 |
43 |
– |
#define GT_OUT 64 |
59 |
|
|
60 |
+ |
#define ADDV3(v,a,b) ((v)[0] = (a)[0]+(b)[0],(v)[1] = (a)[1]+(b)[1],\ |
61 |
+ |
(v)[2] = (a)[2]+(b)[2]) |
62 |
+ |
#define SUBV3(v,a,b) ((v)[0] = (a)[0]-(b)[0],(v)[1] = (a)[1]-(b)[1],\ |
63 |
+ |
(v)[2] = (a)[2]-(b)[2]) |
64 |
+ |
#define SUMV3(v,a,b,s) ((v)[0] = (a)[0]+(s)*(b)[0],(v)[1]=(a)[1]+(s)*(b)[1],\ |
65 |
+ |
(v)[2] = (a)[2]+(s)*(b)[2]) |
66 |
+ |
#define SCALEV3(v,a,s) ((v)[0]=(a)[0]*(s),(v)[1]=(a)[1]*(s),(v)[2]=(a)[2]*(s)) |
67 |
|
#define ZERO_VEC3(v) (ZERO(v[0]) && ZERO(v[1]) && ZERO(v[2]) ) |
68 |
< |
#define EQUAL_VEC3(a,b) (EQUAL(a[0],b[0])&&EQUAL(a[1],b[1])&&EQUAL(a[2],b[2])) |
68 |
> |
#define EQUAL_VEC3(a,b) (FEQUAL(a[0],b[0])&&FEQUAL(a[1],b[1])&&FEQUAL(a[2],b[2])) |
69 |
> |
#define OPP_EQUAL_VEC3(a,b) (EQUAL(a[0],-b[0])&&EQUAL(a[1],-b[1])&&EQUAL(a[2],-b[2])) |
70 |
> |
#define FZERO_VEC3(v) (FZERO(v[0]) && FZERO(v[1]) && FZERO(v[2]) ) |
71 |
> |
#define FEQUAL_VEC3(a,b) (FEQUAL(a[0],b[0])&&FEQUAL(a[1],b[1])&&FEQUAL(a[2],b[2])) |
72 |
|
#define NEGATE_VEC3(v) ((v)[0] *= -1.0,(v)[1] *= -1.0,(v)[2] *= -1.0) |
73 |
|
#define COPY_VEC2(v1,v2) ((v1)[0]=(v2)[0],(v1)[1]=(v2)[1]) |
74 |
|
#define DIST(a,b) (sqrt(((a)[0]-(b)[0])*((a)[0]-(b)[0]) + \ |
78 |
|
((a)[1]-(b)[1])*((a)[1]-(b)[1]) + \ |
79 |
|
((a)[2]-(b)[2])*((a)[2]-(b)[2])) |
80 |
|
|
81 |
+ |
#define SIGN(x) ((x<0)?-1:1) |
82 |
|
#define CROSS_VEC2(v1,v2) (((v1)[0]*(v2)[1]) - ((v1)[1]*(v2)[0])) |
83 |
|
#define DOT_VEC2(v1,v2) ((v1)[0]*(v2)[0] + (v1)[1]*(v2)[1]) |
84 |
|
|
85 |
< |
#define EDGE_MIDPOINT_VEC3(a,v1,v2) ((a)[0]=((v1)[0]+(v2)[0])*0.5, \ |
85 |
> |
#define EDGE_MIDPOINT(a,v1,v2) ((a)[0]=((v1)[0]+(v2)[0])*0.5, \ |
86 |
|
(a)[1]=((v1)[1]+(v2)[1])*0.5,(a)[2] = ((v1)[2]+(v2)[2])*0.5) |
87 |
|
|
88 |
|
#define MIN_VEC3(v) ((v)[0]<(v)[1]?((v)[0]<(v)[2]?(v)[0]:v[2]): \ |
89 |
|
(v)[1]<(v)[2]?(v)[1]:(v)[2]) |
90 |
< |
|
90 |
> |
#define MAX3(a,b,c) (((b)>(a))?((b) > (c))?(b):(c):((a)>(c))?(a):(c)) |
91 |
> |
#define MIN3(a,b,c) (((b)<(a))?((b) < (c))?(b):(c):((a)<(c))?(a):(c)) |
92 |
|
|
93 |
+ |
#define MAX(a,b) (((b)>(a))?(b):(a)) |
94 |
+ |
#define MIN(a,b) (((b)<(a))?(b):(a)) |
95 |
+ |
|
96 |
|
#define SUM_3VEC3(r,a,b,c) ((r)[0]=(a)[0]+(b)[0]+(c)[0], \ |
97 |
|
(r)[1]=(a)[1]+(b)[1]+(c)[1],(r)[2]=(a)[2]+(b)[2]+(c)[2]) |
98 |
|
|
99 |
|
#define NTH_BIT(n,i) ((n) & (1<<(i))) |
100 |
|
#define SET_NTH_BIT(n,i) ((n) |= (1<<(i))) |
101 |
|
|
102 |
+ |
#define PT_ON_PLANE(p,peq) (DOT(FP_N(peq),p)+FP_D(peq)) |
103 |
|
|
104 |
< |
/* int convex_angle(FVECT v0,FVECT v1,FVECT v2) */ |
105 |
< |
/* void triangle_centroid(FVECT v0,FVECT v1,FVECT v2,FVECT c) */ |
106 |
< |
/* void triangle_plane_equation(FVECT v0,FVECT v1,FVECT v2,FVECT n,double *nd, |
107 |
< |
char norm) */ |
108 |
< |
/* int vec3_equal(FVECT v1,v2) */ |
109 |
< |
/* int point_relative_to_plane(FVECT p,FVECT n, double nd) */ |
110 |
< |
/* int point_in_circle(FVECT p,FVECT p0,FVECT p1) */ |
111 |
< |
/* int intersect_line_plane(FVECT r,FVECT p1,FVECT p2,float *plane) */ |
112 |
< |
/* int point_in_cone(FVECT p,FVECT p1,FVECT p2,FVECT p3,FVECT p4) */ |
113 |
< |
/* void point_on_sphere(FVECT ps,FVECT p,FVECT c) */ |
114 |
< |
/* int test_point_against_spherical_tri(FVECT v0,FVECT v1,FVECT v2,FVECT p, |
115 |
< |
FVECT n,char *nset,char *which,char sides[3]) */ |
116 |
< |
/* int test_single_point_against_spherical_tri(FVECT v0,FVECT v1,FVECT v2, |
86 |
< |
FVECT p,char *which )*/ |
87 |
< |
/* int test_vertices_for_tri_inclusion(FVECT tri[3],FVECT pts[3],char *nset, |
88 |
< |
FVECT n[3],FVECT avg,char pt_sides[3][3]); */ |
89 |
< |
/* void set_sidedness_tests(FVECT tri[3],FVECT pts[3],char test[3], |
90 |
< |
char sides[3][3],char nset,FVECT n[3]) |
91 |
< |
*/ |
92 |
< |
/* int cs_spherical_edge_edge_test(FVECT n[2][3],int i,int j,FVECT avg[2]) */ |
93 |
< |
/* int spherical_tri_tri_intersect(FVECT a1,FVECT a2,FVECT a3, |
94 |
< |
FVECT b1,FVECT b2,FVECT b3) */ |
95 |
< |
|
96 |
< |
/* void calculate_view_frustum(FVECT vp,hv,vv,double horiz,vert,near,far, |
97 |
< |
FVECT fnear[4],FVECT ffar[4]) |
98 |
< |
*/ |
99 |
< |
/* double triangle_normal_Newell(FVECT v0,FVECT v1,FVECT v2,FVECT n,char n)*/ |
104 |
> |
/* FUNCTIONS: |
105 |
> |
int point_in_cone(FVECT p,a,b,c) |
106 |
> |
void triangle_centroid(FVECT v0,v1,v2,c) |
107 |
> |
double tri_normal(FVECT v0,v1,v2,n,int norm) |
108 |
> |
void tri_plane_equation(FVECT v0,v1,v2,FPEQ *peqptr,int norm) |
109 |
> |
int intersect_ray_plane(FVECT orig,dir,FPEQ peq,double *pd,FVECT r) |
110 |
> |
double point_on_sphere(FVECT ps,p,c) |
111 |
> |
int point_in_stri(FVECT v0,v1,v2,p) |
112 |
> |
int ray_intersect_tri(FVECT orig,dir,v0,v1,v2,pt) |
113 |
> |
void calculate_view_frustum(FVECT vp,hv,vv,double horiz,vert,near,far, |
114 |
> |
FVECT fnear[4],ffar[4]) |
115 |
> |
void bary2d(double x1,y1,x2,y2,x3,y3,px,py,coord) |
116 |
> |
*/ |
117 |
|
double tri_normal(); |
118 |
< |
/* double spherical_edge_normal(FVECT v0,FVECT v1,FVECT n,char norm) */ |
119 |
< |
double spherical_edge_normal(); |
118 |
> |
double point_on_sphere(); |
119 |
> |
|
120 |
|
|
121 |
|
|