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 "shpshape.h"
00049 #include "disdispl.h"
00050
00051 void MSD_lowCameraDisplayIntersection(void)
00052 {
00053 CTYPE *cptr;
00054
00055 if (camptr->mode == 3)
00056 {
00057 cptr = camptr;
00058 camptr = &camera3;
00059 MSD_lowSetCamera3View(1, cptr);
00060 MSD_lowDisplayHidden(camptr);
00061 MSD_lowDisplayIntersection();
00062
00063 MSD_lowSetCamera3View(2, cptr);
00064 MSD_lowDisplayHidden(camptr);
00065 MSD_lowDisplayIntersection();
00066
00067 MSD_lowSetCamera3View(3, cptr);
00068 MSD_lowDisplayHidden(camptr);
00069 MSD_lowDisplayIntersection();
00070
00071 MSD_lowSetCamera3View(4, cptr);
00072 MSD_lowDisplayHidden(camptr);
00073 MSD_lowDisplayIntersection();
00074
00075 MSD_lowSetCamera3View(0, cptr);
00076 }
00077 else
00078 {
00079 MSD_lowDisplayHidden(camptr);
00080 MSD_lowDisplayIntersection();
00081 }
00082 }
00083
00084 void MSD_lowDisplayIntersection(void)
00085 {
00086 SPTYPE o1;
00087 SPTYPE o2;
00088 DPTYPE d1;
00089 DPTYPE d2;
00090 FPTYPE f1;
00091 FPTYPE f2;
00092
00093 for (AllSolids(o1))
00094 {
00095 if (SolDsp(o1) == FALSE)
00096 {
00097 continue;
00098 }
00099 for (o2 = SolNxt(o1); o2 != SNIL; o2 = SolNxt(o2))
00100 {
00101 if (SolDsp(o2) == FALSE)
00102 {
00103 continue;
00104 }
00105 if (!MSD_lowBoxBoxIntersection(&SolBox(o1), &SolBox(o2)))
00106 {
00107 continue;
00108 }
00109 g_pcolor(MSD_lowGetIntersectionColor(o1, o2));
00110 if (camptr->dash)
00111 {
00112 for (AllShellsSolid(o1, d1))
00113 {
00114 for (AllFacesShell(d1, f1))
00115 {
00116 for (AllShellsSolid(o2, d2))
00117 {
00118 for (AllFacesShell(d2, f2))
00119 {
00120 if (breakflg)
00121 {
00122 return;
00123 }
00124 if (MSD_lowBoxBoxIntersection(&FacBox(f1), &FacBox(f2)))
00125 {
00126 MSD_lowIntersectionFaceFace(o1, f1, o2, f2);
00127 }
00128 }
00129 }
00130 }
00131 }
00132 }
00133 else
00134 {
00135 for (AllShellsSolid(o1, d1))
00136 {
00137 for (AllFacesShell(d1, f1))
00138 {
00139 if (FacFVisi(f1))
00140 {
00141 for (AllShellsSolid(o2, d2))
00142 {
00143 for (AllFacesShell(d2, f2))
00144 {
00145 if (FacFVisi(f2))
00146 {
00147 if (breakflg)
00148 {
00149 return;
00150 }
00151 if (MSD_lowBoxBoxIntersection(&FacBox(f1), &FacBox(f2)))
00152 {
00153 MSD_lowIntersectionFaceFace(o1, f1, o2, f2);
00154 }
00155 }
00156 }
00157 }
00158 }
00159 }
00160 }
00161 }
00162 }
00163 }
00164 }
00165
00166
00167
00168
00169 void MSD_lowIntersectionFaceFace(SPTYPE o1ptr, FPTYPE f1ptr,
00170 SPTYPE o2ptr, FPTYPE f2ptr)
00171 {
00172 if (MSD_lowIntersectionParallelFaces(f1ptr, f2ptr) == FALSE)
00173 {
00174 divedptr = divedge = (DEDGTYPE *)workbuf;
00175 divednum = 0;
00176 MSD_lowIntersectionFaceEdge(f1ptr, f2ptr);
00177 MSD_lowIntersectionFaceEdge(f2ptr, f1ptr);
00178 if (divednum != 0)
00179 {
00180 if (MSD_lowIntersectionSeparateMinMax() == TRUE)
00181 {
00182 MSD_lowUpdateDEBox();
00183 MSD_lowEdgeEdgeIntersection(SNIL, ENIL, f1ptr, f2ptr);
00184 MSD_lowEdgeFaceIntersection(o1ptr, o2ptr, f1ptr, f2ptr);
00185 MSD_lowSortDividedEdge();
00186 MSD_lowSetEdgeVisibility('i', f1ptr, f2ptr, (real *)NIL);
00187 MSD_lowDisplayDividedEdge(camptr, ENIL);
00188 }
00189 }
00190 }
00191 }
00192
00193
00194
00195
00196 int MSD_lowIntersectionParallelFaces(FPTYPE f1ptr, FPTYPE f2ptr)
00197 {
00198 vector v, f1, f2;
00199
00200 veccopy(f1, FacFeq(f1ptr));
00201 veccopy(f2, FacFeq(f2ptr));
00202 vecminus(v, f1, f2);
00203 if (!(sqrt(dot(v, v)) < abseps))
00204 {
00205 vecplus(v, f1, f2);
00206 if (!(sqrt(dot(v, v)) < abseps))
00207 {
00208 return(FALSE);
00209 }
00210 }
00211 return(TRUE);
00212 }
00213
00214
00215
00216
00217
00218 void MSD_lowIntersectionFaceEdge(FPTYPE f1ptr, FPTYPE f2ptr)
00219 {
00220 HPTYPE e2ptr;
00221 HPTYPE efim;
00222 HPTYPE dummy;
00223 real ps, pe;
00224 vector pos, sv, ev;
00225
00226 e2ptr = efim = LooLEdg(FacFLOut(f2ptr));
00227 do
00228 {
00229 veccopy(sv, VerVCoord(HalVtx(e2ptr)));
00230 veccopy(ev, VerVCoord(HalVtx(HalNxt(e2ptr))));
00231 ps = dot(sv, FacFeq(f1ptr)) + FacFeq(f1ptr)[3];
00232 pe = dot(ev, FacFeq(f1ptr)) + FacFeq(f1ptr)[3];
00233 if (fabs(ps - pe) > abseps)
00234 {
00235 if (!((ps < -abseps) && (pe < -abseps)))
00236 {
00237 if (!((ps > abseps) && (pe > abseps)))
00238 {
00239 calc_p(ev, sv, ps / (ps - pe), pos);
00240 if (MSD_lowIsInsideFace(pos, f1ptr, &dummy))
00241 {
00242 MSD_lowAddEdgeDivision(pos);
00243 }
00244 }
00245 }
00246 }
00247 } while ((e2ptr = HalNxt(e2ptr)) != efim);
00248 }
00249
00250
00251
00252
00253
00254 int MSD_lowIntersectionSeparateMinMax(void)
00255 {
00256 real maxdis, max, min;
00257 DEDGTYPE *minptr, *maxptr, *minp, *maxp, *dptr;
00258 int idx, i, j;
00259
00260 maxdis = 0.0;
00261 for (i = 0; i < 3; ++i)
00262 {
00263 maxp = minp = dptr = divedge;
00264 max = min = dptr->devtx[i];
00265 for (j = 1; j < divednum; ++j)
00266 {
00267 ++dptr;
00268 if (max < dptr->devtx[i])
00269 {
00270 max = (maxp = dptr)->devtx[i];
00271 }
00272 if (min > dptr->devtx[i])
00273 {
00274 min = (minp = dptr)->devtx[i];
00275 }
00276 }
00277 if (max - min > maxdis)
00278 {
00279 maxdis = max - min;
00280 idx = i;
00281 minptr = minp;
00282 maxptr = maxp;
00283 }
00284 }
00285 if (maxdis > abseps)
00286 {
00287 if (MSD_lowClipDisplayTransformation(minptr->devtx, maxptr->devtx, desvtx, deevtx))
00288 {
00289 MSD_lowAddEdgeDivision(desvtx);
00290 MSD_lowAddEdgeDivision(deevtx);
00291 MSD_lowIntersectionClipDropCoord(idx);
00292 return(TRUE);
00293 }
00294 }
00295 return(FALSE);
00296 }
00297
00298
00299
00300
00301
00302 void MSD_lowIntersectionClipDropCoord(int idx)
00303 {
00304 DEDGTYPE *dptr;
00305 real max, min;
00306 int i;
00307
00308 if ((max = desvtx[idx]) < (min = deevtx[idx]))
00309 {
00310 max = min;
00311 min = desvtx[idx];
00312 }
00313 for (dptr = divedge, i = 0; i < divednum - 2; ++dptr, ++i)
00314 {
00315 if ((dptr->devtx[idx] < min) || (dptr->devtx[idx] > max))
00316 {
00317 veccopy(dptr->devtx, desvtx);
00318 }
00319 }
00320 }