Skip to content
sglab edited this page Jun 7, 2015 · 6 revisions

Contents of the Distribution

The archive contains all the libraries (except for opengl and glut) and include files needed to build applications using OpenCCD. The following is a description of what each folder contains:

  1. Src: source code for the OpenCCD library
  2. Doc: documentation for the OpenCCD library
  3. Demo1: one example demonstrating usage of the OpenCCD library
  4. include: header files that should be included to an application

Basic APIs are explained in below. Please see the full CCD_API documentation for details. [ Click Here ]

How to build OpenCCD

  • Supported compiler: MS Visual Studio 2005 or later version
  • Visual studio project files for VS2005 and VS2008 are included in the distribution.
  • For other compilers, add all source files into a project and try to compile it.

Building and application

Setting up the library for use in your application is simple.

  1. Build the OpenCCD library
  2. Make sure you link to OpennCCD.lib
  3. The include folder included with the distribution should be in your include path
  4. Once the above two things have been done, all you need to do is "#include <OpenCCD.h>" in your application

OpenCCD API

Create an Object

obj1.beginObject( # of frames , # of vertices, # of triangles, object type ); 
    // set vertices' info. of each frame
    obj.setVtx( 0, 0, Vec3f( 0, 0, 0 ) );
    ...
    // set triangles' info. of each frame
    obj.setTri( 0, 0, 1, 2 );
obj.endObject( );

Set and Perform CCD

CCD ccd;
CCD_Output output;
CCD_Object obj1, obj2;

ccd.setOutput( &output );
...
// Set Info. of objects
...
obj1.setID( ccd.addObject( &obj1 ) );
obj2.setID( ccd.addObject( &obj2 ) );

ccd.readyCCD( 0, 10, 0 );

while( ) {
    ccd.performCCD( );
    // move to next frame or update model Info.
}

Code example 1

CCD ccd;
CCD_Output output;
CCD_Object obj1, obj2;

// Assign output instance to CCD
ccd.setOutput( &output );

// set object 1
obj1.beginObject( 2, 3, 1, CCD_OBJECT_TYPE_STATIC );

    // frame 1
    obj1.setVtx( 0, 0, Vec3f( 0, 0, 0 ) );
    obj1.setVtx( 0, 1, Vec3f( 0, 0, 1 ) );
    obj1.setVtx( 0, 2, Vec3f( 0, 1, 1 ) );

    // frame 2
    obj1.setVtx( 1, 0, Vec3f( 0, 0, -1 ) );
    obj1.setVtx( 1, 1, Vec3f( 0, 0, 0  ) );
    obj1.setVtx( 1, 2, Vec3f( 0, 1, 0  ) );

    obj1.setTri( 0, 0, 1, 2 );

obj1.endObject();

// set object 2
obj2.beginObject( 2, 3, 1, CCD_OBJECT_TYPE_STATIC );

    // frame 1
    obj2.setVtx( 0, 0, Vec3f( -10, 0, -0.5 ) );
    obj2.setVtx( 0, 1, Vec3f( 0, 10, -0.5 ) );
    obj2.setVtx( 0, 2, Vec3f( 10, 0, -0.5 ) );

    // frame 2
    obj2.setVtx( 1, 0, Vec3f( -10, 0, -0.5 ) );
    obj2.setVtx( 1, 1, Vec3f( 0, 10, -0.5 ) );
    obj2.setVtx( 1, 2, Vec3f( 10, 0, -0.5 ) );

    obj2.setTri( 0, 0, 1, 2 );

obj2.endObject( );

 
// Add objects to CCD
obj1.setID ( ccd.addObject( &obj1 ) );
obj2.setID ( ccd.addObject( &obj2 ) );

// Ready to perform CCD
ccd.readyCCD( 0, 2, 0 );

// Perform CCD
for ( int i = 0 ; i < 3 ; i++ ) {
    ccd.performCCD( );
    ccd.nextFrame( );
}

// Print results
output.printSummary();

Code example 2

CCD ccd;
CCD_Output output;
CCD_Object obj1, obj2;

// Assign output instance to CCD
ccd.setOutput( &output ) ;

// set object 1
obj1.beginObject( 1, 3, 1, CCD_OBJECT_TYPE_STATIC );

    obj1.setVtx( 0, 0, Vec3f( 0, 0, 0 ) );
    obj1.setVtx( 0, 1, Vec3f( 0, 0, 1 ) );
    obj1.setVtx( 0, 2, Vec3f( 0, 1, 1 ) );

    obj1.setTri( 0, 0, 1, 2 );

obj1.endObject( );

// set object 2
obj2.beginObject( 1, 3, 1, CCD_OBJECT_TYPE_STATIC );

    obj2.setVtx( 0, 0, Vec3f( -10, 0, -0.5 ) );
    obj2.setVtx( 0, 1, Vec3f( 0, 10, -0.5 ) );
    obj2.setVtx( 0, 2, Vec3f( 10, 0, -0.5 ) );

    obj2.setTri( 0, 0, 1, 2 ) ;

obj2.endObject( );

// Add objects to CCD
obj1.setID( ccd.addObject( &obj1 ) );
obj2.setID( ccd.addObject( &obj2 ) );

// Ready to perform CCD
ccd.readyCCD( 0, 1, 0 );

// Apply model changes
obj1.swapVtxs_Cur_Prev( );
    obj1.setCurVtx( 0, Vec3f( 0, 0, -1 ) );
    obj1.setCurVtx( 1, Vec3f( 0, 0, 0  ) );
    obj1.setCurVtx( 2, Vec3f( 0, 1, 0  ) );

obj2.swapVtxs_Cur_Prev( );
    obj2.setCurVtx( 0, Vec3f( -10, 0, -0.5 ) );
    obj2.setCurVtx( 1, Vec3f( 0, 10, -0.5 ) );
    obj2.setCurVtx( 2, Vec3f( 10, 0, -0.5 ) );

// perform CCD
ccd.performCCD( );

// Print results
output.printSummary( );