522 |
|
if(!SM_IS_NTH_T_NEW(sm,t_id) && !SM_IS_NTH_T_BASE(sm,t_id)) |
523 |
|
{ |
524 |
|
SM_SET_NTH_T_NEW(sm,t_id); |
525 |
+ |
smNew_tri_cnt--; |
526 |
|
continue; |
527 |
|
} |
528 |
|
t = SM_NTH_TRI(sm,t_id); |
779 |
|
} |
780 |
|
|
781 |
|
QUADTREE |
782 |
< |
smPointLocateCell(sm,pt,type,which,norm) |
782 |
> |
smPointLocateCell(sm,pt,norm,v0,v1,v2) |
783 |
|
SM *sm; |
784 |
|
FVECT pt; |
784 |
– |
char *type,*which; |
785 |
|
char norm; |
786 |
+ |
FVECT v0,v1,v2; |
787 |
|
{ |
788 |
|
STREE *st; |
789 |
< |
QUADTREE qt; |
789 |
> |
QUADTREE *qtptr; |
790 |
|
FVECT npt; |
791 |
|
|
792 |
|
st = SM_LOCATOR(sm); |
794 |
|
{ |
795 |
|
point_on_sphere(npt,pt,SM_VIEW_CENTER(sm)); |
796 |
|
|
797 |
< |
qt = stPoint_locate_cell(st,npt,type,which); |
797 |
> |
qtptr = stPoint_locate_cell(st,npt,v0,v1,v2); |
798 |
|
} |
799 |
|
else |
800 |
< |
qt = stPoint_locate_cell(st,pt,type,which); |
800 |
> |
qtptr = stPoint_locate_cell(st,pt,v0,v1,v2); |
801 |
|
|
802 |
< |
return(qt); |
802 |
> |
if(qtptr) |
803 |
> |
return(*qtptr); |
804 |
> |
else |
805 |
> |
return(EMPTY); |
806 |
|
} |
807 |
|
|
808 |
|
int |
1123 |
|
return(-1); |
1124 |
|
} |
1125 |
|
|
1122 |
– |
/* |
1123 |
– |
* int |
1124 |
– |
* smTraceRay(SM *sm,FVECT orig, FVECT dir,FVECT v0,FVECT v1,FVECT v2,FVECT r) |
1125 |
– |
* |
1126 |
– |
* Intersect the ray with triangle v0v1v2, return intersection point in r |
1127 |
– |
* |
1128 |
– |
* Assumes orig,v0,v1,v2 are in spherical coordinates, and orig is |
1129 |
– |
* unit |
1130 |
– |
*/ |
1131 |
– |
char |
1132 |
– |
smTraceRay(sm,orig,dir,v0,v1,v2,r) |
1133 |
– |
SM *sm; |
1134 |
– |
FVECT orig,dir; |
1135 |
– |
FVECT v0,v1,v2; |
1136 |
– |
FVECT r; |
1137 |
– |
{ |
1138 |
– |
FVECT n,p[3],d; |
1139 |
– |
double pt[3],r_eps; |
1140 |
– |
char i; |
1141 |
– |
int which; |
1126 |
|
|
1143 |
– |
/* Find the plane equation for the triangle defined by the edge v0v1 and |
1144 |
– |
the view center*/ |
1145 |
– |
VCROSS(n,v0,v1); |
1146 |
– |
/* Intersect the ray with this plane */ |
1147 |
– |
i = intersect_ray_plane(orig,dir,n,0.0,&(pt[0]),p[0]); |
1148 |
– |
if(i) |
1149 |
– |
which = 0; |
1150 |
– |
else |
1151 |
– |
which = -1; |
1152 |
– |
|
1153 |
– |
VCROSS(n,v1,v2); |
1154 |
– |
i = intersect_ray_plane(orig,dir,n,0.0,&(pt[1]),p[1]); |
1155 |
– |
if(i) |
1156 |
– |
if((which==-1) || pt[1] < pt[0]) |
1157 |
– |
which = 1; |
1158 |
– |
|
1159 |
– |
VCROSS(n,v2,v0); |
1160 |
– |
i = intersect_ray_plane(orig,dir,n,0.0,&(pt[2]),p[2]); |
1161 |
– |
if(i) |
1162 |
– |
if((which==-1) || pt[2] < pt[which]) |
1163 |
– |
which = 2; |
1164 |
– |
|
1165 |
– |
if(which != -1) |
1166 |
– |
{ |
1167 |
– |
/* Return point that is K*eps along projection of the ray on |
1168 |
– |
the sphere to push intersection point p[which] into next cell |
1169 |
– |
*/ |
1170 |
– |
normalize(p[which]); |
1171 |
– |
/* Calculate the ray perpendicular to the intersection point: approx |
1172 |
– |
the direction moved along the sphere a distance of K*epsilon*/ |
1173 |
– |
r_eps = -DOT(p[which],dir); |
1174 |
– |
VSUM(n,dir,p[which],r_eps); |
1175 |
– |
/* Calculate the length along ray p[which]-dir needed to move to |
1176 |
– |
cause a move along the sphere of k*epsilon |
1177 |
– |
*/ |
1178 |
– |
r_eps = DOT(n,dir); |
1179 |
– |
VSUM(r,p[which],dir,(20*FTINY)/r_eps); |
1180 |
– |
normalize(r); |
1181 |
– |
return(TRUE); |
1182 |
– |
} |
1183 |
– |
else |
1184 |
– |
{ |
1185 |
– |
/* Unable to find intersection: move along ray and try again */ |
1186 |
– |
r_eps = -DOT(orig,dir); |
1187 |
– |
VSUM(n,dir,orig,r_eps); |
1188 |
– |
r_eps = DOT(n,dir); |
1189 |
– |
VSUM(r,orig,dir,(20*FTINY)/r_eps); |
1190 |
– |
normalize(r); |
1191 |
– |
#ifdef DEBUG |
1192 |
– |
eputs("smTraceRay:Ray does not intersect triangle"); |
1193 |
– |
#endif |
1194 |
– |
return(FALSE); |
1195 |
– |
} |
1196 |
– |
} |
1197 |
– |
|
1198 |
– |
|
1127 |
|
/* |
1128 |
|
* int |
1129 |
|
* smFindSamp(FVECT orig, FVECT dir) |
1160 |
|
d = -DOT(b,dir); |
1161 |
|
if(EQUAL_VEC3(orig,SM_VIEW_CENTER(smMesh)) || EQUAL(fabs(d),1.0)) |
1162 |
|
{ |
1163 |
< |
qt = smPointLocateCell(smMesh,dir,NULL,NULL,FALSE); |
1163 |
> |
qt = smPointLocateCell(smMesh,dir,FALSE,NULL,NULL,NULL); |
1164 |
|
/* Test triangles in the set for intersection with Ray:returns |
1165 |
|
first found |
1166 |
|
*/ |
1175 |
|
{ |
1176 |
|
/* Starting with orig, Walk along projection of ray onto sphere */ |
1177 |
|
point_on_sphere(r,orig,SM_VIEW_CENTER(smMesh)); |
1178 |
< |
qt = smPointLocateCell(smMesh,r,NULL,NULL,FALSE); |
1178 |
> |
qt = smPointLocateCell(smMesh,r,FALSE,v0,v1,v2); |
1179 |
|
qtgetset(t_set,qt); |
1180 |
|
/* os will contain all triangles seen thus far */ |
1181 |
|
setcopy(os,t_set); |
1194 |
|
if(s_id != EMPTY) |
1195 |
|
return(s_id); |
1196 |
|
/* Find next cell that projection of ray intersects */ |
1197 |
< |
smTraceRay(smMesh,r,dir,v0,v1,v2,r); |
1198 |
< |
qt = smPointLocateCell(smMesh,r,NULL,NULL,FALSE); |
1197 |
> |
traceRay(r,dir,v0,v1,v2,r); |
1198 |
> |
qt = smPointLocateCell(smMesh,r,FALSE,v0,v1,v2); |
1199 |
|
qtgetset(t_set,qt); |
1200 |
|
/* Check triangles in set against those seen so far(os):only |
1201 |
|
check new triangles for intersection (t_set') |
1202 |
|
*/ |
1203 |
|
check_set(t_set,os); |
1204 |
< |
d = DOT(a,r); |
1204 |
> |
d = DOT(a,r); |
1205 |
|
} |
1206 |
|
} |
1207 |
|
#ifdef DEBUG |