ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/hd/sm_geom.h
Revision: 3.13
Committed: Mon Jul 14 22:24:00 2003 UTC (20 years, 9 months ago) by schorsch
Content type: text/plain
Branch: MAIN
CVS Tags: rad3R6P1, rad3R6
Changes since 3.12: +11 -1 lines
Log Message:
Instrumented headers against multiple inclusion and for use from C++.
Moved includes in headers out of "C" scope.

File Contents

# User Rev Content
1 schorsch 3.13 /* RCSid: $Id: sm_geom.h,v 3.12 2003/02/22 02:07:25 greg Exp $ */
2 gwlarson 3.1 /*
3     * sm_geom.h
4     */
5    
6     /* Assumes included after standard.h */
7 schorsch 3.13 #ifndef _RAD_SM_GEOM_H_
8     #define _RAD_SM_GEOM_H_
9 gwlarson 3.1
10 gwlarson 3.4 #include <values.h>
11    
12 schorsch 3.13 #ifdef __cplusplus
13     extern "C" {
14     #endif
15    
16 greg 3.12 #ifdef SMLFLT
17     #define EQUALITY_EPS 1e-6
18     #else
19     #define EQUALITY_EPS 1e-10
20     #endif
21    
22 gwlarson 3.11 #define F_TINY 1e-10
23 gwlarson 3.6 #define FZERO(x) ((x) < F_TINY && (x) > -F_TINY)
24     #define FEQUAL(a,b) FZERO((a) - (b))
25    
26 gwlarson 3.1 #define ZERO(x) ((x) < FTINY && (x) > -FTINY)
27     #define EQUAL(a,b) ZERO((a) - (b))
28    
29     #ifndef TRUE
30     #define TRUE 1
31     #define FALSE 0
32     #endif
33 gwlarson 3.4
34 gwlarson 3.5 typedef struct _FPEQ {
35     FVECT n;
36     double d;
37     char x,y,z;
38     }FPEQ;
39    
40     #define FP_N(f) ((f).n)
41     #define FP_D(f) ((f).d)
42     #define FP_X(f) ((f).x)
43     #define FP_Y(f) ((f).y)
44     #define FP_Z(f) ((f).z)
45    
46 gwlarson 3.4 typedef long BCOORD;
47     typedef long BDIR;
48 gwlarson 3.7
49     #define BITS_BCOORD (BITS(long)-2)
50     #define SHIFT_MAXBCOORD (BITS_BCOORD-1)
51     #define MAXBCOORD ((1L << BITS_BCOORD)-1)
52 gwlarson 3.4 #define MAXBCOORD2 (MAXBCOORD>>1)
53 gwlarson 3.7 #define MAXBCOORD4 (MAXBCOORD2>>1)
54 gwlarson 3.1
55     #define M_2_3_PI PI*2/3
56    
57 gwlarson 3.5 #ifndef INVALID
58 gwlarson 3.3 #define INVALID -1
59 gwlarson 3.5 #endif
60 gwlarson 3.10 #define IADDV3(v,a) ((v)[0] += (a)[0],(v)[1] += (a)[1],(v)[2] += (a)[2])
61     #define ISUBV3(v,a) ((v)[0] -= (a)[0],(v)[1] -= (a)[1],(v)[2] -= (a)[2])
62     #define ISCALEV3(v,a) ((v)[0] *= (a),(v)[1] *= (a),(v)[2] *= (a))
63     #define IDIVV3(v,a) ((v)[0] /= (a),(v)[1] /= (a),(v)[2] /= (a))
64    
65    
66     #define ADDV3(v,a,b) ((v)[0] = (a)[0]+(b)[0],(v)[1] = (a)[1]+(b)[1],\
67     (v)[2] = (a)[2]+(b)[2])
68     #define SUBV3(v,a,b) ((v)[0] = (a)[0]-(b)[0],(v)[1] = (a)[1]-(b)[1],\
69     (v)[2] = (a)[2]-(b)[2])
70     #define SUMV3(v,a,b,s) ((v)[0] = (a)[0]+(s)*(b)[0],(v)[1]=(a)[1]+(s)*(b)[1],\
71     (v)[2] = (a)[2]+(s)*(b)[2])
72     #define SCALEV3(v,a,s) ((v)[0]=(a)[0]*(s),(v)[1]=(a)[1]*(s),(v)[2]=(a)[2]*(s))
73 gwlarson 3.1 #define ZERO_VEC3(v) (ZERO(v[0]) && ZERO(v[1]) && ZERO(v[2]) )
74 gwlarson 3.8 #define EQUAL_VEC3(a,b) (FEQUAL(a[0],b[0])&&FEQUAL(a[1],b[1])&&FEQUAL(a[2],b[2]))
75 gwlarson 3.7 #define OPP_EQUAL_VEC3(a,b) (EQUAL(a[0],-b[0])&&EQUAL(a[1],-b[1])&&EQUAL(a[2],-b[2]))
76 gwlarson 3.6 #define FZERO_VEC3(v) (FZERO(v[0]) && FZERO(v[1]) && FZERO(v[2]) )
77     #define FEQUAL_VEC3(a,b) (FEQUAL(a[0],b[0])&&FEQUAL(a[1],b[1])&&FEQUAL(a[2],b[2]))
78 gwlarson 3.1 #define NEGATE_VEC3(v) ((v)[0] *= -1.0,(v)[1] *= -1.0,(v)[2] *= -1.0)
79     #define COPY_VEC2(v1,v2) ((v1)[0]=(v2)[0],(v1)[1]=(v2)[1])
80     #define DIST(a,b) (sqrt(((a)[0]-(b)[0])*((a)[0]-(b)[0]) + \
81     ((a)[1]-(b)[1])*((a)[1]-(b)[1]) + \
82     ((a)[2]-(b)[2])*((a)[2]-(b)[2])))
83 gwlarson 3.3 #define DIST_SQ(a,b) (((a)[0]-(b)[0])*((a)[0]-(b)[0]) + \
84     ((a)[1]-(b)[1])*((a)[1]-(b)[1]) + \
85     ((a)[2]-(b)[2])*((a)[2]-(b)[2]))
86 gwlarson 3.1
87 gwlarson 3.7 #define SIGN(x) ((x<0)?-1:1)
88 gwlarson 3.1 #define CROSS_VEC2(v1,v2) (((v1)[0]*(v2)[1]) - ((v1)[1]*(v2)[0]))
89     #define DOT_VEC2(v1,v2) ((v1)[0]*(v2)[0] + (v1)[1]*(v2)[1])
90    
91 gwlarson 3.7 #define EDGE_MIDPOINT(a,v1,v2) ((a)[0]=((v1)[0]+(v2)[0])*0.5, \
92 gwlarson 3.1 (a)[1]=((v1)[1]+(v2)[1])*0.5,(a)[2] = ((v1)[2]+(v2)[2])*0.5)
93    
94     #define MIN_VEC3(v) ((v)[0]<(v)[1]?((v)[0]<(v)[2]?(v)[0]:v[2]): \
95     (v)[1]<(v)[2]?(v)[1]:(v)[2])
96 gwlarson 3.5 #define MAX3(a,b,c) (((b)>(a))?((b) > (c))?(b):(c):((a)>(c))?(a):(c))
97 greg 3.12 #define MIN3(a,b,c) (((b)<(a))?((b) < (c))?(b):(c):((a)<(c))?(a):(c))
98    
99 gwlarson 3.5 #define MAX(a,b) (((b)>(a))?(b):(a))
100     #define MIN(a,b) (((b)<(a))?(b):(a))
101 gwlarson 3.2
102 gwlarson 3.1 #define SUM_3VEC3(r,a,b,c) ((r)[0]=(a)[0]+(b)[0]+(c)[0], \
103     (r)[1]=(a)[1]+(b)[1]+(c)[1],(r)[2]=(a)[2]+(b)[2]+(c)[2])
104    
105     #define NTH_BIT(n,i) ((n) & (1<<(i)))
106     #define SET_NTH_BIT(n,i) ((n) |= (1<<(i)))
107    
108 greg 3.12 #define PT_ON_PLANE(p,peq) (DOT(FP_N(peq),p)+FP_D(peq))
109 gwlarson 3.1
110 greg 3.12 /* FUNCTIONS:
111     int point_in_cone(FVECT p,a,b,c)
112     void triangle_centroid(FVECT v0,v1,v2,c)
113     double tri_normal(FVECT v0,v1,v2,n,int norm)
114     void tri_plane_equation(FVECT v0,v1,v2,FPEQ *peqptr,int norm)
115     int intersect_ray_plane(FVECT orig,dir,FPEQ peq,double *pd,FVECT r)
116     double point_on_sphere(FVECT ps,p,c)
117     int point_in_stri(FVECT v0,v1,v2,p)
118     int ray_intersect_tri(FVECT orig,dir,v0,v1,v2,pt)
119     void calculate_view_frustum(FVECT vp,hv,vv,double horiz,vert,near,far,
120     FVECT fnear[4],ffar[4])
121     void bary2d(double x1,y1,x2,y2,x3,y3,px,py,coord)
122     */
123 gwlarson 3.1 double tri_normal();
124 gwlarson 3.7 double point_on_sphere();
125 gwlarson 3.1
126    
127 schorsch 3.13 #ifdef __cplusplus
128     }
129     #endif
130     #endif /* _RAD_SM_GEOM_H_ */
131 gwlarson 3.7