00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041 #include <stdio.h>
00042 #include <math.h>
00043 #include "memvirtu.h"
00044 #include "lowparam.h"
00045 #include "lowmacro.h"
00046 #include "lowsolid.h"
00047 #include "vectorop.h"
00048 #include "disdispl.h"
00049 #include "gphgraph.h"
00050
00051 void MSD_lowSetEdgeVisibility(char t, FPTYPE f1ptr, FPTYPE f2ptr, vector edir)
00052 {
00053 vector mid;
00054 DEDGTYPE *p0, *p1;
00055 int i;
00056
00057 divedptr = divedge;
00058 for (i = 0; i < divednum - 1; ++divedptr, ++i)
00059 {
00060 p1 = (p0 = divedptr) + 1;
00061 calc_p(p0->devtx, p1->devtx, 0.5, mid);
00062 if (t == 'i')
00063 {
00064 if (MSD_lowIntersectionCheck(mid, f1ptr, f2ptr))
00065 {
00066 if (divedptr->devis != TRUE)
00067 {
00068 continue;
00069 }
00070 }
00071 }
00072 divedptr->devis = MSD_lowPositionalVisibility(t, mid, f1ptr, f2ptr, edir);
00073 }
00074 divedptr->devis = FALSE;
00075 }
00076
00077 int MSD_lowIntersectionCheck(vector mid, FPTYPE f1ptr, FPTYPE f2ptr)
00078 {
00079 if (MSD_lowIntersectionCheckStep1(mid, f1ptr, f2ptr))
00080 {
00081 return(TRUE);
00082 }
00083 if (MSD_lowIntersectionCheckStep1(mid, f2ptr, f1ptr))
00084 {
00085 return(TRUE);
00086 }
00087 if ((FacFVisi(f1ptr) == DONTSHOW) || (FacFVisi(f2ptr) == DONTSHOW))
00088 {
00089 divedptr->devis = FALSE;
00090 return(TRUE);
00091 }
00092 return(FALSE);
00093 }
00094
00095 int MSD_lowIntersectionCheckStep1(vector mid, FPTYPE f1ptr, FPTYPE f2ptr)
00096 {
00097 vector edir1, edir2, v1, v2;
00098 HPTYPE xe;
00099
00100 switch (MSD_lowIsInsideFace(mid, f1ptr, &xe))
00101 {
00102 case DONTSHOW:
00103 divedptr->devis = -TRUE;
00104 return(TRUE);
00105
00106 case INVISIBLE:
00107 divedptr->devis = FALSE;
00108 veccopy(v1, VerVCoord(HalVtx(HalNxt(xe))));
00109 veccopy(v2, VerVCoord(HalVtx(xe)));
00110 vecminus(edir1, v1, v2);
00111 if (normalize(edir2))
00112 {
00113 if (LooLFace(HalWLoop(mate(xe))) == f1ptr)
00114 {
00115 cross(edir2, FacFeq(f1ptr), edir1);
00116 divedptr->devis = dot(edir2, FacFeq(f2ptr)) > releps;
00117 }
00118 else
00119 {
00120 cross(edir2, FacFeq(f2ptr), edir1);
00121 divedptr->devis = dot(edir2, FacFeq(f1ptr)) > releps;
00122 }
00123 }
00124 return(TRUE);
00125 }
00126 return(FALSE);
00127 }
00128
00129 int MSD_lowPositionalVisibility(char tp, vector v, FPTYPE f1, FPTYPE f2, vector edir)
00130 {
00131 SPTYPE xo;
00132 DPTYPE xd;
00133 FPTYPE xf;
00134 FPTYPE lf;
00135 FPTYPE rf;
00136 HPTYPE xe;
00137 BTYPE box;
00138 vector v1, pos, dir;
00139 real t;
00140 int i;
00141
00142 if (camptr->mode == 1)
00143 {
00144 veccopy(v1, camptr->eye);
00145 }
00146 else
00147 {
00148 for (i = 0; i < 3; ++i)
00149 {
00150 v1[i] = v[i] + camptr->cdis * camptr->eyedir[i];
00151 }
00152 }
00153 for (i = 0; i < 3; ++i)
00154 {
00155 box.min[i] = -abseps + ((v[i] < v1[i]) ? v[i] : v1[i]);
00156 box.max[i] = abseps + ((v[i] > v1[i]) ? v[i] : v1[i]);
00157 }
00158
00159 for (AllSolids(xo))
00160 {
00161 if (SolDsp(xo) != TRUE)
00162 {
00163 continue;
00164 }
00165 if (!MSD_lowBoxBoxIntersection(&box, &SolBox(xo)))
00166 {
00167 continue;
00168 }
00169 for (AllShellsSolid(xo, xd))
00170 {
00171 for (AllFacesShell(xd, xf))
00172 {
00173 if ((xf == f1) || (xf == f2) || !FacFVisi(xf))
00174 {
00175 continue;
00176 }
00177 if (!MSD_lowBoxBoxIntersection(&box, &FacBox(xf)))
00178 {
00179 continue;
00180 }
00181 if (!MSD_lowEdgePlaneIntersection(v, v1, xf, pos, &t))
00182 {
00183 continue;
00184 }
00185 if (t < -releps)
00186 {
00187 continue;
00188 }
00189
00190 switch (MSD_lowIsInsideFace(pos, xf, &xe))
00191 {
00192 case INVISIBLE:
00193 if (t > releps)
00194 {
00195 lf = LooLFace(HalWLoop(EdgHe1(HalEdg(xe))));
00196 rf = LooLFace(HalWLoop(EdgHe2(HalEdg(xe))));
00197 if (EdgEVis(HalEdg(xe)) == DONTSHOW)
00198 {
00199 if (lf == f1)
00200 {
00201 break;
00202 }
00203 if (rf == f1)
00204 {
00205 break;
00206 }
00207 if (lf == f2)
00208 {
00209 break;
00210 }
00211 if (rf == f2)
00212 {
00213 break;
00214 }
00215 }
00216 return(FALSE);
00217 }
00218 break;
00219
00220 case _VISIBLE:
00221 if (t > releps)
00222 {
00223 return(FALSE);
00224 }
00225 if (tp == 'e')
00226 {
00227 if (FacFVisi(f1) || FacFVisi(f2))
00228 {
00229 cross(dir, FacFeq(f1), edir);
00230 if (dot(dir, FacFeq(xf)) < -releps)
00231 {
00232 break;
00233 }
00234 cross(dir, FacFeq(f2), edir);
00235 if (dot(dir, FacFeq(xf)) > releps)
00236 {
00237 break;
00238 }
00239 }
00240 }
00241 return(FALSE);
00242 }
00243 }
00244 }
00245 }
00246 return(TRUE);
00247 }
00248
00249 int MSD_lowEdgePlaneIntersection(vector v1, vector v2, FPTYPE xf, real *pos, real *t)
00250 {
00251 real p1, p2;
00252
00253 p1 = dot(FacFeq(xf), v1) + FacFeq(xf)[3];
00254 p2 = dot(FacFeq(xf), v2) + FacFeq(xf)[3];
00255 if (!(fabs(p1 - p2) < abseps))
00256 {
00257 calc_p(v2, v1, *t = p1 / (p1 - p2), pos);
00258 return(TRUE);
00259 }
00260 return(FALSE);
00261 }