Blender V2.61 - r43446
|
00001 /* 00002 * ***** BEGIN GPL LICENSE BLOCK ***** 00003 * 00004 * This program is free software; you can redistribute it and/or 00005 * modify it under the terms of the GNU General Public License 00006 * as published by the Free Software Foundation; either version 2 00007 * of the License, or (at your option) any later version. 00008 * 00009 * This program is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 * GNU General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU General Public License 00015 * along with this program; if not, write to the Free Software Foundation, 00016 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00017 * 00018 * Contributor(s): Tao Ju 00019 * 00020 * ***** END GPL LICENSE BLOCK ***** 00021 */ 00022 00023 #ifndef PROJECTIONS_H 00024 #define PROJECTIONS_H 00025 00026 #include <stdio.h> 00027 #include <stdlib.h> 00028 00029 #define CONTAINS_INDEX 00030 #define GRID_DIMENSION 20 00031 00032 #if defined(_WIN32) && !defined(__MINGW32__) 00033 #define LONG __int64 00034 #else 00035 #include <stdint.h> 00036 #define LONG int64_t 00037 #endif 00038 #define UCHAR unsigned char 00039 00048 extern const int vertmap[8][3]; 00049 extern const int centmap[3][3][3][2]; 00050 extern const int edgemap[12][2]; 00051 extern const int facemap[6][4]; 00052 00056 struct InheritableProjections 00057 { 00059 LONG trigProj[13][2] ; 00060 00062 LONG trigVertProj[13][3] ; 00063 00065 LONG trigEdgeProj[13][3][2] ; 00066 00068 double norm[3] ; 00069 double normA, normB ; 00070 00072 //int cubeEnds[13][2] ; 00073 00076 00077 #ifdef CONTAINS_INDEX 00078 00079 int index ; 00080 #endif 00081 }; 00082 00083 00087 class Projections 00088 { 00089 public: 00091 InheritableProjections* inherit ; 00092 00094 LONG cubeProj[13][6] ; 00095 00096 public: 00097 00098 Projections( ) 00099 { 00100 } 00101 00106 Projections( LONG cube[2][3], LONG trig[3][3], LONG error, int triind ) 00107 { 00108 int i, j ; 00109 inherit = new InheritableProjections ; 00110 #ifdef CONTAINS_INDEX 00111 inherit->index = triind ; 00112 #endif 00113 00114 LONG axes[13][3] ; 00115 00116 // Cube faces 00117 axes[0][0] = 1 ; 00118 axes[0][1] = 0 ; 00119 axes[0][2] = 0 ; 00120 00121 axes[1][0] = 0 ; 00122 axes[1][1] = 1 ; 00123 axes[1][2] = 0 ; 00124 00125 axes[2][0] = 0 ; 00126 axes[2][1] = 0 ; 00127 axes[2][2] = 1 ; 00128 00129 // Triangle face 00130 LONG trigedge[3][3] ; 00131 for ( i = 0 ; i < 3 ; i ++ ) 00132 { 00133 for ( j = 0 ; j < 3 ; j ++ ) 00134 { 00135 trigedge[i][j] = trig[(i+1)%3][j] - trig[i][j] ; 00136 } 00137 } 00138 crossProduct( trigedge[0], trigedge[1], axes[3] ) ; 00139 00141 double dedge1[] = { (double) trig[1][0] - (double) trig[0][0], 00142 (double) trig[1][1] - (double) trig[0][1], 00143 (double) trig[1][2] - (double) trig[0][2] } ; 00144 double dedge2[] = { (double) trig[2][0] - (double) trig[1][0], 00145 (double) trig[2][1] - (double) trig[1][1], 00146 (double) trig[2][2] - (double) trig[1][2] } ; 00147 crossProduct( dedge1, dedge2, inherit->norm ) ; 00148 normalize( inherit->norm ) ; 00149 // inherit->normA = norm[ 0 ] ; 00150 // inherit->normB = norm[ 2 ] > 0 ? norm[ 1 ] : 2 + norm[ 1 ] ; 00151 00152 // Face edges and triangle edges 00153 int ct = 4 ; 00154 for ( i = 0 ; i < 3 ; i ++ ) 00155 for ( j = 0 ; j < 3 ; j ++ ) 00156 { 00157 crossProduct( axes[j], trigedge[i], axes[ct] ) ; 00158 ct ++ ; 00159 } 00160 00162 LONG cubeedge[3][3] ; 00163 for ( i = 0 ; i < 3 ; i ++ ) 00164 { 00165 for ( j = 0 ; j < 3 ; j ++ ) 00166 { 00167 cubeedge[i][j] = 0 ; 00168 } 00169 cubeedge[i][i] = cube[1][i] - cube[0][i] ; 00170 } 00171 00172 for ( j = 0 ; j < 13 ; j ++ ) 00173 { 00174 // Origin 00175 cubeProj[j][0] = dotProduct( axes[j], cube[0] ) ; 00176 00177 // 3 direction vectors 00178 for ( i = 1 ; i < 4 ; i ++ ) 00179 { 00180 cubeProj[j][i] = dotProduct( axes[j], cubeedge[i-1] ) ; 00181 } 00182 00183 // Offsets of 2 ends of cube projection 00184 LONG max = 0 ; 00185 LONG min = 0 ; 00186 for ( i = 1 ; i < 8 ; i ++ ) 00187 { 00188 LONG proj = vertmap[i][0] * cubeProj[j][1] + vertmap[i][1] * cubeProj[j][2] + vertmap[i][2] * cubeProj[j][3] ; 00189 if ( proj > max ) 00190 { 00191 max = proj ; 00192 } 00193 if ( proj < min ) 00194 { 00195 min = proj ; 00196 } 00197 } 00198 cubeProj[j][4] = min ; 00199 cubeProj[j][5] = max ; 00200 00201 } 00202 00203 for ( j = 0 ; j < 13 ; j ++ ) 00204 { 00205 LONG vts[3] = { dotProduct( axes[j], trig[0] ), 00206 dotProduct( axes[j], trig[1] ), 00207 dotProduct( axes[j], trig[2] ) } ; 00208 00209 // Vertex 00210 inherit->trigVertProj[j][0] = vts[0] ; 00211 inherit->trigVertProj[j][1] = vts[1] ; 00212 inherit->trigVertProj[j][2] = vts[2] ; 00213 00214 // Edge 00215 for ( i = 0 ; i < 3 ; i ++ ) 00216 { 00217 if ( vts[i] < vts[(i+1) % 3] ) 00218 { 00219 inherit->trigEdgeProj[j][i][0] = vts[i] ; 00220 inherit->trigEdgeProj[j][i][1] = vts[(i+1) % 3] ; 00221 } 00222 else 00223 { 00224 inherit->trigEdgeProj[j][i][1] = vts[i] ; 00225 inherit->trigEdgeProj[j][i][0] = vts[(i+1) % 3] ; 00226 } 00227 } 00228 00229 // Triangle 00230 inherit->trigProj[j][0] = vts[0] ; 00231 inherit->trigProj[j][1] = vts[0] ; 00232 for ( i = 1 ; i < 3 ; i ++ ) 00233 { 00234 if ( vts[i] < inherit->trigProj[j][0] ) 00235 { 00236 inherit->trigProj[j][0] = vts[i] ; 00237 } 00238 if ( vts[i] > inherit->trigProj[j][1] ) 00239 { 00240 inherit->trigProj[j][1] = vts[i] ; 00241 } 00242 } 00243 } 00244 00245 } 00246 00251 Projections ( Projections* parent ) 00252 { 00253 // Copy inheritable projections 00254 this->inherit = parent->inherit ; 00255 00256 // Shrink cube projections 00257 for ( int i = 0 ; i < 13 ; i ++ ) 00258 { 00259 cubeProj[i][0] = parent->cubeProj[i][0] ; 00260 for ( int j = 1 ; j < 6 ; j ++ ) 00261 { 00262 cubeProj[i][j] = parent->cubeProj[i][j] >> 1 ; 00263 } 00264 } 00265 }; 00266 00267 Projections ( Projections* parent, int box[3], int depth ) 00268 { 00269 int mask = ( 1 << depth ) - 1 ; 00270 int nbox[3] = { box[0] & mask, box[1] & mask, box[2] & mask } ; 00271 00272 // Copy inheritable projections 00273 this->inherit = parent->inherit ; 00274 00275 // Shrink cube projections 00276 for ( int i = 0 ; i < 13 ; i ++ ) 00277 { 00278 for ( int j = 1 ; j < 6 ; j ++ ) 00279 { 00280 cubeProj[i][j] = parent->cubeProj[i][j] >> depth ; 00281 } 00282 00283 cubeProj[i][0] = parent->cubeProj[i][0] + nbox[0] * cubeProj[i][1] + nbox[1] * cubeProj[i][2] + nbox[2] * cubeProj[i][3] ; 00284 } 00285 }; 00286 00290 int getIntersectionMasks( UCHAR cedgemask, UCHAR& edgemask ) 00291 { 00292 int i, j ; 00293 edgemask = cedgemask ; 00294 00295 // Pre-processing 00296 /* 00297 if ( cvertmask & 1 ) 00298 { 00299 edgemask |= 5 ; 00300 } 00301 if ( cvertmask & 2 ) 00302 { 00303 edgemask |= 3 ; 00304 } 00305 if ( cvertmask & 4 ) 00306 { 00307 edgemask |= 6 ; 00308 } 00309 00310 */ 00311 00312 // Test axes for edge intersection 00313 UCHAR bit = 1 ; 00314 for ( j = 0 ; j < 3 ; j ++ ) 00315 { 00316 if ( edgemask & bit ) 00317 { 00318 for ( i = 0 ; i < 13 ; i ++ ) 00319 { 00320 LONG proj0 = cubeProj[i][0] + cubeProj[i][4] ; 00321 LONG proj1 = cubeProj[i][0] + cubeProj[i][5] ; 00322 00323 if ( proj0 > inherit->trigEdgeProj[i][j][1] || 00324 proj1 < inherit->trigEdgeProj[i][j][0] ) 00325 { 00326 edgemask &= ( ~ bit ) ; 00327 break ; 00328 } 00329 } 00330 } 00331 bit <<= 1 ; 00332 } 00333 00334 /* 00335 if ( edgemask != 0 ) 00336 { 00337 printf("%d %d\n", cedgemask, edgemask) ; 00338 } 00339 */ 00340 00341 // Test axes for triangle intersection 00342 if ( edgemask ) 00343 { 00344 return 1 ; 00345 } 00346 00347 for ( i = 3 ; i < 13 ; i ++ ) 00348 { 00349 LONG proj0 = cubeProj[i][0] + cubeProj[i][4] ; 00350 LONG proj1 = cubeProj[i][0] + cubeProj[i][5] ; 00351 00352 if ( proj0 > inherit->trigProj[i][1] || 00353 proj1 < inherit->trigProj[i][0] ) 00354 { 00355 return 0 ; 00356 } 00357 } 00358 00359 return 1 ; 00360 } 00361 00365 UCHAR getChildrenMasks( UCHAR cvertmask, UCHAR vertmask[8] ) 00366 { 00367 int i, j, k ; 00368 int bmask[3][2] = {{0,0},{0,0},{0,0}} ; 00369 int vmask[3][3][2] = {{{0,0},{0,0},{0,0}},{{0,0},{0,0},{0,0}},{{0,0},{0,0},{0,0}}} ; 00370 UCHAR boxmask = 0 ; 00371 LONG len = cubeProj[0][1] >> 1 ; 00372 00373 for ( i = 0 ; i < 3 ; i ++ ) 00374 { 00375 LONG mid = cubeProj[i][0] + len ; 00376 00377 // Check bounding box 00378 if ( mid >= inherit->trigProj[i][0] ) 00379 { 00380 bmask[i][0] = 1 ; 00381 } 00382 if ( mid <= inherit->trigProj[i][1] ) 00383 { 00384 bmask[i][1] = 1 ; 00385 } 00386 00387 // Check vertex mask 00388 if ( cvertmask ) 00389 { 00390 for ( j = 0 ; j < 3 ; j ++ ) 00391 { 00392 if ( cvertmask & ( 1 << j ) ) 00393 { 00394 // Only check if it's contained this node 00395 if ( mid >= inherit->trigVertProj[i][j] ) 00396 { 00397 vmask[i][j][0] = 1 ; 00398 } 00399 if ( mid <= inherit->trigVertProj[i][j] ) 00400 { 00401 vmask[i][j][1] = 1 ; 00402 } 00403 } 00404 } 00405 } 00406 00407 /* 00408 // Check edge mask 00409 if ( cedgemask ) 00410 { 00411 for ( j = 0 ; j < 3 ; j ++ ) 00412 { 00413 if ( cedgemask & ( 1 << j ) ) 00414 { 00415 // Only check if it's contained this node 00416 if ( mid >= inherit->trigEdgeProj[i][j][0] ) 00417 { 00418 emask[i][j][0] = 1 ; 00419 } 00420 if ( mid <= inherit->trigEdgeProj[i][j][1] ) 00421 { 00422 emask[i][j][1] = 1 ; 00423 } 00424 } 00425 } 00426 } 00427 */ 00428 00429 } 00430 00431 // Fill in masks 00432 int ct = 0 ; 00433 for ( i = 0 ; i < 2 ; i ++ ) 00434 for ( j = 0 ; j < 2 ; j ++ ) 00435 for ( k = 0 ; k < 2 ; k ++ ) 00436 { 00437 boxmask |= ( ( bmask[0][i] & bmask[1][j] & bmask[2][k] ) << ct ) ; 00438 vertmask[ct] = (( vmask[0][0][i] & vmask[1][0][j] & vmask[2][0][k] ) | 00439 (( vmask[0][1][i] & vmask[1][1][j] & vmask[2][1][k] ) << 1 ) | 00440 (( vmask[0][2][i] & vmask[1][2][j] & vmask[2][2][k] ) << 2 ) ) ; 00441 /* 00442 edgemask[ct] = (( emask[0][0][i] & emask[1][0][j] & emask[2][0][k] ) | 00443 (( emask[0][1][i] & emask[1][1][j] & emask[2][1][k] ) << 1 ) | 00444 (( emask[0][2][i] & emask[1][2][j] & emask[2][2][k] ) << 2 ) ) ; 00445 edgemask[ct] = cedgemask ; 00446 */ 00447 ct ++ ; 00448 } 00449 00450 // Return bounding box masks 00451 return boxmask ; 00452 } 00453 00454 UCHAR getBoxMask( ) 00455 { 00456 int i, j, k ; 00457 int bmask[3][2] = {{0,0},{0,0},{0,0}} ; 00458 UCHAR boxmask = 0 ; 00459 LONG len = cubeProj[0][1] >> 1 ; 00460 00461 for ( i = 0 ; i < 3 ; i ++ ) 00462 { 00463 LONG mid = cubeProj[i][0] + len ; 00464 00465 // Check bounding box 00466 if ( mid >= inherit->trigProj[i][0] ) 00467 { 00468 bmask[i][0] = 1 ; 00469 } 00470 if ( mid <= inherit->trigProj[i][1] ) 00471 { 00472 bmask[i][1] = 1 ; 00473 } 00474 00475 } 00476 00477 // Fill in masks 00478 int ct = 0 ; 00479 for ( i = 0 ; i < 2 ; i ++ ) 00480 for ( j = 0 ; j < 2 ; j ++ ) 00481 for ( k = 0 ; k < 2 ; k ++ ) 00482 { 00483 boxmask |= ( ( bmask[0][i] & bmask[1][j] & bmask[2][k] ) << ct ) ; 00484 ct ++ ; 00485 } 00486 00487 // Return bounding box masks 00488 return boxmask ; 00489 } 00490 00491 00495 void getSubProjectionsSimple( Projections* p[8] ) 00496 { 00497 // Process the axes cooresponding to the triangle's normal 00498 int ind = 3 ; 00499 LONG len = cubeProj[ 0 ][ 1 ] >> 1 ; 00500 LONG trigproj[3] = { cubeProj[ ind ][ 1 ] >> 1, cubeProj[ ind ][ 2 ] >> 1, cubeProj[ ind ][ 3 ] >> 1 } ; 00501 00502 int ct = 0 ; 00503 for ( int i = 0 ; i < 2 ; i ++ ) 00504 for ( int j = 0 ; j < 2 ; j ++ ) 00505 for ( int k = 0 ; k < 2 ; k ++ ) 00506 { 00507 p[ct] = new Projections( ) ; 00508 p[ct]->inherit = inherit ; 00509 00510 p[ct]->cubeProj[ 0 ][ 0 ] = cubeProj[ 0 ][ 0 ] + i * len ; 00511 p[ct]->cubeProj[ 1 ][ 0 ] = cubeProj[ 1 ][ 0 ] + j * len ; 00512 p[ct]->cubeProj[ 2 ][ 0 ] = cubeProj[ 2 ][ 0 ] + k * len ; 00513 p[ct]->cubeProj[ 0 ][ 1 ] = len ; 00514 00515 for ( int m = 1 ; m < 4 ; m ++ ) 00516 { 00517 p[ct]->cubeProj[ ind ][ m ] = trigproj[ m - 1 ] ; 00518 } 00519 p[ct]->cubeProj[ ind ][ 0 ] = cubeProj[ ind ][0] + i * trigproj[0] + j * trigproj[1] + k * trigproj[2] ; 00520 00521 ct ++ ; 00522 } 00523 } 00524 00528 void shift ( int off[3] ) 00529 { 00530 for ( int i = 0 ; i < 13 ; i ++ ) 00531 { 00532 cubeProj[i][0] += off[0] * cubeProj[i][1] + off[1] * cubeProj[i][2] + off[2] * cubeProj[i][3] ; 00533 } 00534 } 00535 00536 void shiftNoPrimary ( int off[3] ) 00537 { 00538 for ( int i = 3 ; i < 13 ; i ++ ) 00539 { 00540 cubeProj[i][0] += off[0] * cubeProj[i][1] + off[1] * cubeProj[i][2] + off[2] * cubeProj[i][3] ; 00541 } 00542 } 00543 00547 int isIntersecting ( ) 00548 { 00549 for ( int i = 0 ; i < 13 ; i ++ ) 00550 { 00551 /* 00552 LONG proj0 = cubeProj[i][0] + 00553 vertmap[inherit->cubeEnds[i][0]][0] * cubeProj[i][1] + 00554 vertmap[inherit->cubeEnds[i][0]][1] * cubeProj[i][2] + 00555 vertmap[inherit->cubeEnds[i][0]][2] * cubeProj[i][3] ; 00556 LONG proj1 = cubeProj[i][0] + 00557 vertmap[inherit->cubeEnds[i][1]][0] * cubeProj[i][1] + 00558 vertmap[inherit->cubeEnds[i][1]][1] * cubeProj[i][2] + 00559 vertmap[inherit->cubeEnds[i][1]][2] * cubeProj[i][3] ; 00560 */ 00561 00562 LONG proj0 = cubeProj[i][0] + cubeProj[i][4] ; 00563 LONG proj1 = cubeProj[i][0] + cubeProj[i][5] ; 00564 00565 if ( proj0 > inherit->trigProj[i][1] || 00566 proj1 < inherit->trigProj[i][0] ) 00567 { 00568 return 0 ; 00569 } 00570 } 00571 00572 return 1 ; 00573 }; 00574 00575 int isIntersectingNoPrimary ( ) 00576 { 00577 for ( int i = 3 ; i < 13 ; i ++ ) 00578 { 00579 /* 00580 LONG proj0 = cubeProj[i][0] + 00581 vertmap[inherit->cubeEnds[i][0]][0] * cubeProj[i][1] + 00582 vertmap[inherit->cubeEnds[i][0]][1] * cubeProj[i][2] + 00583 vertmap[inherit->cubeEnds[i][0]][2] * cubeProj[i][3] ; 00584 LONG proj1 = cubeProj[i][0] + 00585 vertmap[inherit->cubeEnds[i][1]][0] * cubeProj[i][1] + 00586 vertmap[inherit->cubeEnds[i][1]][1] * cubeProj[i][2] + 00587 vertmap[inherit->cubeEnds[i][1]][2] * cubeProj[i][3] ; 00588 */ 00589 00590 LONG proj0 = cubeProj[i][0] + cubeProj[i][4] ; 00591 LONG proj1 = cubeProj[i][0] + cubeProj[i][5] ; 00592 00593 if ( proj0 > inherit->trigProj[i][1] || 00594 proj1 < inherit->trigProj[i][0] ) 00595 { 00596 return 0 ; 00597 } 00598 } 00599 00600 return 1 ; 00601 }; 00602 00606 int isIntersecting ( int edgeInd ) 00607 { 00608 for ( int i = 0 ; i < 13 ; i ++ ) 00609 { 00610 00611 LONG proj0 = cubeProj[i][0] + 00612 vertmap[edgemap[edgeInd][0]][0] * cubeProj[i][1] + 00613 vertmap[edgemap[edgeInd][0]][1] * cubeProj[i][2] + 00614 vertmap[edgemap[edgeInd][0]][2] * cubeProj[i][3] ; 00615 LONG proj1 = cubeProj[i][0] + 00616 vertmap[edgemap[edgeInd][1]][0] * cubeProj[i][1] + 00617 vertmap[edgemap[edgeInd][1]][1] * cubeProj[i][2] + 00618 vertmap[edgemap[edgeInd][1]][2] * cubeProj[i][3] ; 00619 00620 00621 if ( proj0 < proj1 ) 00622 { 00623 if ( proj0 > inherit->trigProj[i][1] || 00624 proj1 < inherit->trigProj[i][0] ) 00625 { 00626 return 0 ; 00627 } 00628 } 00629 else 00630 { 00631 if ( proj1 > inherit->trigProj[i][1] || 00632 proj0 < inherit->trigProj[i][0] ) 00633 { 00634 return 0 ; 00635 } 00636 } 00637 } 00638 00639 // printf( "Intersecting: %d %d\n", edgemap[edgeInd][0], edgemap[edgeInd][1] ) ; 00640 return 1 ; 00641 }; 00642 00646 int isIntersecting ( int edgeInd, int faceInd ) 00647 { 00648 for ( int i = 0 ; i < 13 ; i ++ ) 00649 { 00650 LONG trigproj0 = inherit->trigVertProj[i][edgeInd] ; 00651 LONG trigproj1 = inherit->trigVertProj[i][(edgeInd+1)%3] ; 00652 00653 if ( trigproj0 < trigproj1 ) 00654 { 00655 int t1 = 1 , t2 = 1 ; 00656 for ( int j = 0 ; j < 4 ; j ++ ) 00657 { 00658 LONG proj = cubeProj[i][0] + 00659 vertmap[facemap[faceInd][j]][0] * cubeProj[i][1] + 00660 vertmap[facemap[faceInd][j]][1] * cubeProj[i][2] + 00661 vertmap[facemap[faceInd][j]][2] * cubeProj[i][3] ; 00662 if ( proj >= trigproj0 ) 00663 { 00664 t1 = 0 ; 00665 } 00666 if ( proj <= trigproj1 ) 00667 { 00668 t2 = 0 ; 00669 } 00670 } 00671 if ( t1 || t2 ) 00672 { 00673 return 0 ; 00674 } 00675 } 00676 else 00677 { 00678 int t1 = 1 , t2 = 1 ; 00679 for ( int j = 0 ; j < 4 ; j ++ ) 00680 { 00681 LONG proj = cubeProj[i][0] + 00682 vertmap[facemap[faceInd][j]][0] * cubeProj[i][1] + 00683 vertmap[facemap[faceInd][j]][1] * cubeProj[i][2] + 00684 vertmap[facemap[faceInd][j]][2] * cubeProj[i][3] ; 00685 if ( proj >= trigproj1 ) 00686 { 00687 t1 = 0 ; 00688 } 00689 if ( proj <= trigproj0 ) 00690 { 00691 t2 = 0 ; 00692 } 00693 } 00694 if ( t1 || t2 ) 00695 { 00696 return 0 ; 00697 } 00698 } 00699 } 00700 00701 return 1 ; 00702 }; 00703 00704 00705 int isIntersectingPrimary ( int edgeInd ) 00706 { 00707 for ( int i = 0 ; i < 13 ; i ++ ) 00708 { 00709 00710 LONG proj0 = cubeProj[i][0] ; 00711 LONG proj1 = cubeProj[i][0] + cubeProj[i][edgeInd + 1] ; 00712 00713 if ( proj0 < proj1 ) 00714 { 00715 if ( proj0 > inherit->trigProj[i][1] || 00716 proj1 < inherit->trigProj[i][0] ) 00717 { 00718 return 0 ; 00719 } 00720 } 00721 else 00722 { 00723 if ( proj1 > inherit->trigProj[i][1] || 00724 proj0 < inherit->trigProj[i][0] ) 00725 { 00726 return 0 ; 00727 } 00728 } 00729 00730 } 00731 00732 // printf( "Intersecting: %d %d\n", edgemap[edgeInd][0], edgemap[edgeInd][1] ) ; 00733 return 1 ; 00734 }; 00735 00736 double getIntersection ( int edgeInd ) 00737 { 00738 int i = 3 ; 00739 00740 LONG proj0 = cubeProj[i][0] + 00741 vertmap[edgemap[edgeInd][0]][0] * cubeProj[i][1] + 00742 vertmap[edgemap[edgeInd][0]][1] * cubeProj[i][2] + 00743 vertmap[edgemap[edgeInd][0]][2] * cubeProj[i][3] ; 00744 LONG proj1 = cubeProj[i][0] + 00745 vertmap[edgemap[edgeInd][1]][0] * cubeProj[i][1] + 00746 vertmap[edgemap[edgeInd][1]][1] * cubeProj[i][2] + 00747 vertmap[edgemap[edgeInd][1]][2] * cubeProj[i][3] ; 00748 LONG proj2 = inherit->trigProj[i][1] ; 00749 00750 /* 00751 if ( proj0 < proj1 ) 00752 { 00753 if ( proj2 < proj0 || proj2 > proj1 ) 00754 { 00755 return -1 ; 00756 } 00757 } 00758 else 00759 { 00760 if ( proj2 < proj1 || proj2 > proj0 ) 00761 { 00762 return -1 ; 00763 } 00764 } 00765 */ 00766 00767 double alpha = (double)( proj2 - proj0 ) / (double)( proj1 - proj0 ) ; 00768 /* 00769 if ( alpha < 0 ) 00770 { 00771 alpha = 0.5 ; 00772 } 00773 else if ( alpha > 1 ) 00774 { 00775 alpha = 0.5 ; 00776 } 00777 */ 00778 00779 return alpha ; 00780 }; 00781 00782 float getIntersectionPrimary ( int edgeInd ) 00783 { 00784 int i = 3 ; 00785 00786 00787 LONG proj0 = cubeProj[i][0] ; 00788 LONG proj1 = cubeProj[i][0] + cubeProj[i][edgeInd + 1] ; 00789 LONG proj2 = inherit->trigProj[i][1] ; 00790 00791 // double alpha = (double)( ( proj2 - proj0 ) * cubeProj[edgeInd][edgeInd + 1] ) / (double)( proj1 - proj0 ) ; 00792 double alpha = (double)( ( proj2 - proj0 ) ) / (double)( proj1 - proj0 ) ; 00793 00794 if ( alpha < 0 ) 00795 { 00796 alpha = 0.5 ; 00797 } 00798 else if ( alpha > 1 ) 00799 { 00800 alpha = 0.5 ; 00801 } 00802 00803 00804 return (float)alpha ; 00805 }; 00806 00810 void crossProduct ( LONG a[3], LONG b[3], LONG res[3] ) 00811 { 00812 res[0] = a[1] * b[2] - a[2] * b[1] ; 00813 res[1] = a[2] * b[0] - a[0] * b[2] ; 00814 res[2] = a[0] * b[1] - a[1] * b[0] ; 00815 } 00816 void crossProduct ( double a[3], double b[3], double res[3] ) 00817 { 00818 res[0] = a[1] * b[2] - a[2] * b[1] ; 00819 res[1] = a[2] * b[0] - a[0] * b[2] ; 00820 res[2] = a[0] * b[1] - a[1] * b[0] ; 00821 } 00822 00826 LONG dotProduct ( LONG a[3], LONG b[3] ) 00827 { 00828 return a[0] * b[0] + a[1] * b[1] + a[2] * b[2] ; 00829 } 00830 00831 void normalize( double a[3] ) 00832 { 00833 double mag = a[0] * a[0] + a[1] * a[1] + a[2] * a[2] ; 00834 if ( mag > 0 ) 00835 { 00836 mag = sqrt( mag ) ; 00837 a[0] /= mag ; 00838 a[1] /= mag ; 00839 a[2] /= mag ; 00840 } 00841 } 00842 00843 }; 00844 00845 #endif