/*************************************************************************\ Copyright 1995 The University of North Carolina at Chapel Hill. All Rights Reserved. Permission to use, copy, modify and distribute this software and its documentation for educational, research and non-profit purposes, without fee, and without a written agreement is hereby granted, provided that the above copyright notice and the following three paragraphs appear in all copies. IN NO EVENT SHALL THE UNIVERSITY OF NORTH CAROLINA AT CHAPEL HILL BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF NORTH CAROLINA HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. THE UNIVERSITY OF NORTH CAROLINA SPECIFICALLY DISCLAIM ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF NORTH CAROLINA HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. The authors may be contacted via: US Mail: S. Gottschalk Department of Computer Science Sitterson Hall, CB #3175 University of N. Carolina Chapel Hill, NC 27599-3175 Phone: (919)962-1749 \*************************************************************************/ #include "RAPID.H" #include #include #define LISTS 0 main() { // first, get a couple of boxes in which to put our models RAPID_model *b1 = new RAPID_model; RAPID_model *b2 = new RAPID_model; // then, load the boxes with triangles. The following loads each // with a torus of 2*n1*n2 triangles. fprintf(stderr, "loading tris into RAPID_model objects..."); fflush(stderr); double a = 1.0; // major radius of the tori double b = 0.2; // minor radius of the tori int n1 = 50; // tori will have n1*n2*2 triangles each int n2 = 50; int uc, vc; int count = 0; for(uc=0; ucAddTri(p1, p2, p3, count); b1->AddTri(p4, p2, p3, count+1); b2->AddTri(p1, p2, p3, count); b2->AddTri(p4, p2, p3, count+1); count += 2; } fprintf(stderr, "done\n"); fflush(stderr); fprintf(stderr, "Tori have %d triangles each.\n", count); fprintf(stderr, "building hierarchies..."); fflush(stderr); b1->EndModel(); b2->EndModel(); fprintf(stderr, "done.\n"); fflush(stderr); // now we are free to call the interference detect routine. // but first, construct the transformations which define the placement // of our two hierarchies in world space: // this placement causes them to overlap a large amount. double R1[3][3], R2[3][3], T1[3], T2[3]; R1[0][0] = R1[1][1] = R1[2][2] = 1.0; R1[0][1] = R1[1][0] = R1[2][0] = 0.0; R1[0][2] = R1[1][2] = R1[2][1] = 0.0; R2[0][0] = R2[1][1] = R2[2][2] = 1.0; R2[0][1] = R2[1][0] = R2[2][0] = 0.0; R2[0][2] = R2[1][2] = R2[2][1] = 0.0; T1[0] = 1.0; T1[1] = 0.0; T1[2] = 0.0; T2[0] = 0.0; T2[1] = 0.0; T2[2] = 0.0; // now we can perform a collision query: RAPID_Collide(R1, T1, b1, R2, T2, b2, RAPID_ALL_CONTACTS); // looking at the report, we can see where all the contacts were, and // also how many tests were necessary: printf("All contacts between overlapping tori:\n"); printf("Num box tests: %d\n", RAPID_num_box_tests); printf("Num contact pairs: %d\n", RAPID_num_contacts); #if LISTS int i; for(i=0; i