Biomechanical Joint Model
 Author: Anderson Maciel

v_collide_test.cpp

Go to the documentation of this file.
00001 /************************************************************************\
00002 
00003   Copyright 1997 The University of North Carolina at Chapel Hill.
00004   All Rights Reserved.
00005 
00006   Permission to use, copy, modify and distribute this software
00007   and its documentation for educational, research and non-profit
00008   purposes, without fee, and without a written agreement is
00009   hereby granted, provided that the above copyright notice and
00010   the following three paragraphs appear in all copies.
00011 
00012   IN NO EVENT SHALL THE UNIVERSITY OF NORTH CAROLINA AT CHAPEL
00013   HILL BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL,
00014   INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS,
00015   ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION,
00016   EVEN IF THE UNIVERSITY OF NORTH CAROLINA HAVE BEEN ADVISED OF
00017   THE POSSIBILITY OF SUCH DAMAGES.
00018 
00019 
00020   Permission to use, copy, modify and distribute this software
00021   and its documentation for educational, research and non-profit
00022   purposes, without fee, and without a written agreement is
00023   hereby granted, provided that the above copyright notice and
00024   the following three paragraphs appear in all copies.
00025 
00026   THE UNIVERSITY OF NORTH CAROLINA SPECIFICALLY DISCLAIM ANY
00027   WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00028   WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00029   PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS"
00030   BASIS, AND THE UNIVERSITY OF NORTH CAROLINA HAS NO OBLIGATION
00031   TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR
00032   MODIFICATIONS.
00033 
00034 
00035    --------------------------------- 
00036   |Please send all BUG REPORTS to:  |
00037   |                                 |
00038   |   geom@cs.unc.edu               |
00039   |                                 |
00040    ---------------------------------
00041   
00042      
00043   The authors may be contacted via:
00044 
00045   US Mail:  A. Pattekar/J. Cohen/T. Hudson/S. Gottschalk/M. Lin/D. Manocha
00046             Department of Computer Science
00047             Sitterson Hall, CB #3175
00048             University of N. Carolina
00049             Chapel Hill, NC 27599-3175
00050             
00051   Phone:    (919)962-1749
00052             
00053   EMail:    geom@cs.unc.edu
00054 
00055 \************************************************************************/
00056 
00057 #include <iostream.h>
00058 #include <stdlib.h>
00059 #include "VCollide.H"
00060 
00061 main(int argc, char *argv[])
00062 {
00063   
00064   if (argc != 1)
00065     {
00066       cerr<<argv[0]<<": USAGE: "<<argv[0]<<"\n";
00067       exit(1);
00068     }
00069   
00070   VCollide vc;
00071   int id[2];
00072 
00073   int i;
00074   for (i=0; i<2; i++) //create both the objects.
00075     {
00076       vc.NewObject(&id[i]);
00077       
00078       //the geometry is a unit cube with one vertex at the origin.
00079       double v1[3], v2[3], v3[3];
00080       
00081       v1[0] = 0.0; v1[1] = 0.0; v1[2] = 0.0;
00082       v2[0] = 1.0; v2[1] = 0.0; v2[2] = 0.0;
00083       v3[0] = 1.0; v3[1] = 0.0; v3[2] = 1.0;
00084       vc.AddTri(v1, v2, v3);
00085       
00086       v1[0] = 0.0; v1[1] = 0.0; v1[2] = 0.0;
00087       v2[0] = 0.0; v2[1] = 0.0; v2[2] = 1.0;
00088       v3[0] = 1.0; v3[1] = 0.0; v3[2] = 1.0;
00089       vc.AddTri(v1, v2, v3);
00090       
00091       v1[0] = 0.0; v1[1] = 1.0; v1[2] = 0.0;
00092       v2[0] = 1.0; v2[1] = 1.0; v2[2] = 0.0;
00093       v3[0] = 1.0; v3[1] = 1.0; v3[2] = 1.0;
00094       vc.AddTri(v1, v2, v3);
00095       
00096       v1[0] = 0.0; v1[1] = 1.0; v1[2] = 0.0;
00097       v2[0] = 0.0; v2[1] = 1.0; v2[2] = 1.0;
00098       v3[0] = 1.0; v3[1] = 1.0; v3[2] = 1.0;
00099       vc.AddTri(v1, v2, v3);
00100       
00101       v1[0] = 1.0; v1[1] = 0.0; v1[2] = 0.0;
00102       v2[0] = 1.0; v2[1] = 1.0; v2[2] = 0.0;
00103       v3[0] = 1.0; v3[1] = 1.0; v3[2] = 1.0;
00104       vc.AddTri(v1, v2, v3);
00105 
00106       v1[0] = 1.0; v1[1] = 0.0; v1[2] = 0.0;
00107       v2[0] = 1.0; v2[1] = 0.0; v2[2] = 1.0;
00108       v3[0] = 1.0; v3[1] = 1.0; v3[2] = 1.0;
00109       vc.AddTri(v1, v2, v3);
00110       
00111       v1[0] = 0.0; v1[1] = 0.0; v1[2] = 0.0;
00112       v2[0] = 0.0; v2[1] = 1.0; v2[2] = 0.0;
00113       v3[0] = 0.0; v3[1] = 1.0; v3[2] = 1.0;
00114       vc.AddTri(v1, v2, v3);
00115       
00116       v1[0] = 0.0; v1[1] = 0.0; v1[2] = 0.0;
00117       v2[0] = 0.0; v2[1] = 0.0; v2[2] = 1.0;
00118       v3[0] = 0.0; v3[1] = 1.0; v3[2] = 1.0;
00119       vc.AddTri(v1, v2, v3);
00120 
00121       v1[0] = 1.0; v1[1] = 0.0; v1[2] = 1.0;
00122       v2[0] = 1.0; v2[1] = 1.0; v2[2] = 1.0;
00123       v3[0] = 0.0; v3[1] = 1.0; v3[2] = 1.0;
00124       vc.AddTri(v1, v2, v3);
00125 
00126       v1[0] = 1.0; v1[1] = 0.0; v1[2] = 1.0;
00127       v2[0] = 0.0; v2[1] = 0.0; v2[2] = 1.0;
00128       v3[0] = 0.0; v3[1] = 1.0; v3[2] = 1.0;
00129       vc.AddTri(v1, v2, v3);
00130 
00131       v1[0] = 1.0; v1[1] = 0.0; v1[2] = 0.0;
00132       v2[0] = 1.0; v2[1] = 1.0; v2[2] = 0.0;
00133       v3[0] = 0.0; v3[1] = 1.0; v3[2] = 0.0;
00134       vc.AddTri(v1, v2, v3);
00135 
00136       v1[0] = 1.0; v1[1] = 0.0; v1[2] = 0.0;
00137       v2[0] = 0.0; v2[1] = 0.0; v2[2] = 0.0;
00138       v3[0] = 0.0; v3[1] = 1.0; v3[2] = 0.0;
00139       vc.AddTri(v1, v2, v3);
00140       
00141       vc.EndObject();
00142     }
00143 
00144   double trans0[4][4], trans1[4][4]; //transformation matrices.
00145 
00146   //initialize the transformation matrices to identity.
00147   
00148   for (i=0; i<4; i++)
00149     {
00150       int j;
00151       for (j=0; j<4; j++)
00152         trans0[i][j] = trans1[i][j] = ( (i==j) ? 1.0 : 0.0 );
00153     }
00154   
00155   int simulation_step=1;
00156   for (i=-25; i<=25; i++) //perform 51 frames of the simulation
00157     {
00158       cout<<"Simulation step: "<<simulation_step++<<"\n";
00159       
00160       //in successive frames of the simulation, the two objects 
00161       //approach each other from far and finally collide and cross
00162       //each other.
00163       trans0[0][3] =  0.25*i;  //we translate both the objects
00164       trans1[0][3] = -0.25*i;  //along the X-axis only.
00165       
00166       vc.UpdateTrans(id[0], trans0);
00167       vc.UpdateTrans(id[1], trans1);
00168   
00169       vc.Collide();
00170       
00171       int VCReportSize=2; //note that in this case, there can be a max of 
00172                           //1 colliding pair.
00173       VCReportType *vcrep = new VCReportType[VCReportSize];
00174       
00175       int no_of_colliding_pairs = vc.Report(VCReportSize, vcrep);
00176       
00177       for (int j=0; j<no_of_colliding_pairs; j++)
00178         cout<<"Detected collision between objects "<<vcrep[j].id1<<" and "<<vcrep[j].id2<<"\n";
00179       
00180     }
00181 }

Generated on Thu Dec 1 10:13:40 2005 for COME - Biomechanical Joint Model by  doxygen 1.4.5