667 |
|
double pd; |
668 |
|
int type; |
669 |
|
|
670 |
< |
point_on_sphere(p0,v0,orig); |
671 |
< |
point_on_sphere(p1,v1,orig); |
672 |
< |
point_on_sphere(p2,v2,orig); |
673 |
< |
|
670 |
> |
VSUB(p0,v0,orig); |
671 |
> |
VSUB(p1,v1,orig); |
672 |
> |
VSUB(p2,v2,orig); |
673 |
> |
|
674 |
|
if(point_in_stri(p0,p1,p2,dir)) |
675 |
|
{ |
676 |
|
/* Intersect the ray with the triangle plane */ |
1026 |
|
i = (a>=b)?((a>=c)?0:2):((b>=c)?1:2); |
1027 |
|
return(i); |
1028 |
|
} |
1029 |
– |
|
1030 |
– |
|
1031 |
– |
|
1032 |
– |
/* |
1033 |
– |
* int |
1034 |
– |
* traceRay(FVECT orig, FVECT dir,FVECT v0,FVECT v1,FVECT v2,FVECT r) |
1035 |
– |
* |
1036 |
– |
* Intersect the ray with triangle v0v1v2, return intersection point in r |
1037 |
– |
* |
1038 |
– |
* Assumes orig,v0,v1,v2 are in spherical coordinates, and orig is |
1039 |
– |
* unit |
1040 |
– |
*/ |
1041 |
– |
int |
1042 |
– |
traceRay(orig,dir,v0,v1,v2,r) |
1043 |
– |
FVECT orig,dir; |
1044 |
– |
FVECT v0,v1,v2; |
1045 |
– |
FVECT r; |
1046 |
– |
{ |
1047 |
– |
FVECT n,p[3],d; |
1048 |
– |
double pt[3],r_eps; |
1049 |
– |
int i; |
1050 |
– |
int which; |
1051 |
– |
|
1052 |
– |
/* Find the plane equation for the triangle defined by the edge v0v1 and |
1053 |
– |
the view center*/ |
1054 |
– |
VCROSS(n,v0,v1); |
1055 |
– |
/* Intersect the ray with this plane */ |
1056 |
– |
i = intersect_ray_plane(orig,dir,n,0.0,&(pt[0]),p[0]); |
1057 |
– |
if(i) |
1058 |
– |
which = 0; |
1059 |
– |
else |
1060 |
– |
which = -1; |
1061 |
– |
|
1062 |
– |
VCROSS(n,v1,v2); |
1063 |
– |
i = intersect_ray_plane(orig,dir,n,0.0,&(pt[1]),p[1]); |
1064 |
– |
if(i) |
1065 |
– |
if((which==-1) || pt[1] < pt[0]) |
1066 |
– |
which = 1; |
1067 |
– |
|
1068 |
– |
VCROSS(n,v2,v0); |
1069 |
– |
i = intersect_ray_plane(orig,dir,n,0.0,&(pt[2]),p[2]); |
1070 |
– |
if(i) |
1071 |
– |
if((which==-1) || pt[2] < pt[which]) |
1072 |
– |
which = 2; |
1073 |
– |
|
1074 |
– |
if(which != -1) |
1075 |
– |
{ |
1076 |
– |
/* Return point that is K*eps along projection of the ray on |
1077 |
– |
the sphere to push intersection point p[which] into next cell |
1078 |
– |
*/ |
1079 |
– |
normalize(p[which]); |
1080 |
– |
/* Calculate the ray perpendicular to the intersection point: approx |
1081 |
– |
the direction moved along the sphere a distance of K*epsilon*/ |
1082 |
– |
r_eps = -DOT(p[which],dir); |
1083 |
– |
VSUM(n,dir,p[which],r_eps); |
1084 |
– |
/* Calculate the length along ray p[which]-dir needed to move to |
1085 |
– |
cause a move along the sphere of k*epsilon |
1086 |
– |
*/ |
1087 |
– |
r_eps = DOT(n,dir); |
1088 |
– |
VSUM(r,p[which],dir,(20*FTINY)/r_eps); |
1089 |
– |
normalize(r); |
1090 |
– |
return(TRUE); |
1091 |
– |
} |
1092 |
– |
else |
1093 |
– |
{ |
1094 |
– |
/* Unable to find intersection: move along ray and try again */ |
1095 |
– |
r_eps = -DOT(orig,dir); |
1096 |
– |
VSUM(n,dir,orig,r_eps); |
1097 |
– |
r_eps = DOT(n,dir); |
1098 |
– |
VSUM(r,orig,dir,(20*FTINY)/r_eps); |
1099 |
– |
normalize(r); |
1100 |
– |
#ifdef DEBUG |
1101 |
– |
eputs("traceRay:Ray does not intersect triangle\n"); |
1102 |
– |
#endif |
1103 |
– |
return(FALSE); |
1104 |
– |
} |
1105 |
– |
} |
1106 |
– |
|
1029 |
|
|
1030 |
|
int |
1031 |
|
closest_point_in_tri(p0,p1,p2,p,p0id,p1id,p2id) |