| 
    World of Rigid Bodies (WoRB)
   
    
   
   | 
  
  
  
 
Data Structures | |
| class | Collision | 
| Encalpsulates a collision event between two bodies; contains contact details.  More... | |
| class | CollisionResolver | 
| Encapsulates collision response framework.  More... | |
| class | Const | 
| Physical and mathematical constants.  More... | |
| class | Geometry | 
| Represents a geometry used to detect collisions against.  More... | |
| class | HalfSpace | 
| Represents a half-space defined by a plane where the normal of the plane points out of the half-space.  More... | |
| class | TruePlane | 
| Represents a true plane.  More... | |
| class | Sphere | 
| Encapsulates a sphere.  More... | |
| class | Cuboid | 
| Encapsulates a cuboid (rectangular parallelepiped).  More... | |
| class | QTensor | 
| Encapsulates a quaternionic tensor (q-tensor) as a 4x4 row-major matrix.  More... | |
| class | Quaternion | 
| Encapsulates Hamilton real quaternions.  More... | |
| class | SpatialVector | 
| Encapsulates a spatial vector.  More... | |
| class | RigidBody | 
| Encapsulates a rigid body.  More... | |
| class | GLUT_Renderer | 
| Interface for a GLUT-rendered rigid body.  More... | |
| class | GLTransform | 
| Establishes temporarily a GL transform from body-fixed into world frame.  More... | |
| class | GLOrthoScreen | 
| Establishes temporarily orthogonal projection in screen coordinates.  More... | |
| class | Ball | 
| Encapsulates a rigid body with geometry of a sphere.  More... | |
| class | Box | 
| Encapsulates a rigid body with geometry of a rectangular parallelepiped.  More... | |
| class | GLUT_Framework | 
| GLUT wrapper around a single instance of a GlutApplication template class.  More... | |
| class | WorldOfRigidBodies | 
| Encapsulates a system of rigid bodies.  More... | |
Functions | |
| void | Printf (const char *format,...) | 
| User defined ANSI C printf-style output routine.   | |
| void | Pause (unsigned long ms) | 
| Pauses execution for the given amount of milliseconds.   | |
| void | glutForegroundWindow () | 
| Brings the current GLUT window to the foreground.   | |
| void | OnGlutError (const char *format, va_list args) | 
| void | OnGlutWarning (const char *format, va_list args) | 
| void | SevereError (const char *errorId, const char *format,...) | 
| Reports a severe error (with errorId compatible with MATLAB) and quits.   | |
| static Quaternion | operator+ (double scalar, const Quaternion &q) | 
| static Quaternion | operator- (double scalar, const Quaternion &q) | 
| static Quaternion | operator* (double scalar, const Quaternion &q) | 
| double | RandomReal () | 
| Gets a uniform real number in range [0,1).   | |
| Quaternion | RandomQuaternion (double length=1.0) | 
| Gets a quaternion of the given length having a random orientation.   | |
| Quaternion | RandomQuaternion (const Quaternion &min, const Quaternion &max) | 
| Gets a random quaternion uniformly distributed in a 4D box.   | |
| void | RenderText (double x, double y, double z, const char *text) | 
| Renders the given text to the given location in body-fixed space.   | |
| int | RenderPrintf (int x, int y, const char *format,...) | 
| Renders the given text to the given location in screen space on the window.   | |
| void | RenderStateVariables (const RigidBody &body, const Quaternion &extent) | 
| Draws the geometry axes, angular velocity and angular momentum.   | |
| void | RenderAxes (double length) | 
| Draws the world axes.   | |
| void WoRB::glutForegroundWindow | ( | ) | 
Brings the current GLUT window to the foreground.
Definition at line 55 of file Platform.cpp.
Referenced by WoRB_TestBed::SetupAnimation().
    {
        #ifdef _WIN32
        HWND hWnd = FindWindow( TEXT("FREEGLUT"), NULL );
        if ( hWnd ) {
            SetForegroundWindow( hWnd );
        }
        #endif
    }
| void WoRB::OnGlutError | ( | const char * | format, | 
| va_list | args | ||
| ) | 
Definition at line 69 of file Platform.cpp.
References Printf().
    {
        char buffer[ 2048 ];
        vsprintf( buffer, format, args );
        Printf( "WoRB: %s\n", buffer );
    }
| void WoRB::OnGlutWarning | ( | const char * | format, | 
| va_list | args | ||
| ) | 
Definition at line 79 of file Platform.cpp.
References Printf().
    {
        char buffer[ 2048 ];
        vsprintf( buffer, format, args );
        Printf( "WoRB: %s\n", buffer );
    }
| static Quaternion WoRB::operator* | ( | double | scalar, | 
| const Quaternion & | q | ||
| ) |  [inline, static] | 
        
Definition at line 373 of file Quaternion.h.
References WoRB::Quaternion::w, WoRB::Quaternion::x, WoRB::Quaternion::y, and WoRB::Quaternion::z.
    {
        return Quaternion( scalar * q.w, scalar * q.x, scalar * q.y, scalar * q.z );
    }
| static Quaternion WoRB::operator+ | ( | double | scalar, | 
| const Quaternion & | q | ||
| ) |  [inline, static] | 
        
Definition at line 363 of file Quaternion.h.
References WoRB::Quaternion::w, WoRB::Quaternion::x, WoRB::Quaternion::y, and WoRB::Quaternion::z.
    {
        return Quaternion( scalar + q.w, scalar + q.x, scalar + q.y, scalar + q.z );
    }
| static Quaternion WoRB::operator- | ( | double | scalar, | 
| const Quaternion & | q | ||
| ) |  [inline, static] | 
        
Definition at line 368 of file Quaternion.h.
References WoRB::Quaternion::w, WoRB::Quaternion::x, WoRB::Quaternion::y, and WoRB::Quaternion::z.
    {
        return Quaternion( scalar - q.w, scalar - q.x, scalar - q.y, scalar - q.z );
    }
| void WoRB::Pause | ( | unsigned long | ms | ) | 
Pauses execution for the given amount of milliseconds.
Definition at line 27 of file Platform.cpp.
Referenced by WoRB_TestBed::DisplayEventHandler(), and WoRB_TestBed::Simulate().
    {
        #ifdef _WIN32
            Sleep( ms );
        #else
            usleep( ms * 1000ul );
        #endif
    }
| void WoRB::Printf | ( | const char * | format, | 
| ... | |||
| ) | 
User defined ANSI C printf-style output routine.
Definition at line 36 of file Platform.cpp.
Referenced by WoRB::GLUT_Framework< GlutApplication >::Connect(), WoRB_MexFunction::CreateResultMatrix(), WoRB::GLUT_Framework< GlutApplication >::Disconnect(), WoRB_TestBed::Dump(), WoRB::Collision::Dump(), WoRB::Quaternion::Dump(), WoRB::GLUT_Framework< GlutApplication >::GLUT_Framework(), WoRB_TestBed::Initialize(), WoRB::GLUT_Framework< GlutApplication >::Initialize(), OnGlutError(), OnGlutWarning(), WoRB_MexFunction::Parse(), WoRB_TestBed::Run(), WoRB_TestBed::SetupAnimation(), WoRB::GLUT_Framework< GlutApplication >::Terminate(), and WoRB::GLUT_Framework< GlutApplication >::~GLUT_Framework().
    {
        va_list args;
        va_start( args, format );
        char buffer[ 2048 ];
        vsprintf( buffer, format, args );
        va_end( args );
        #ifdef MATLAB_MEX_FILE
            mexPrintf( "%s", buffer );
            // mexEvalString( "drawnow;" ); // = flush
        #else
            fputs( buffer, stdout );
            fflush( stdout );
        #endif
    }
| Quaternion WoRB::RandomQuaternion | ( | double | length = 1.0 | ) | 
Gets a quaternion of the given length having a random orientation.
Definition at line 31 of file Utilities.cpp.
References WoRB::Quaternion::Normalize(), and RandomReal().
Referenced by WoRB_TestBed::ReconfigureTestBed().
{
    return Quaternion( RandomReal (), RandomReal (), RandomReal (), RandomReal () )
           .Normalize( length );
}
| Quaternion WoRB::RandomQuaternion | ( | const Quaternion & | min, | 
| const Quaternion & | max | ||
| ) | 
Gets a random quaternion uniformly distributed in a 4D box.
Definition at line 39 of file Utilities.cpp.
References RandomReal(), WoRB::Quaternion::w, WoRB::Quaternion::x, WoRB::Quaternion::y, and WoRB::Quaternion::z.
{
    return Quaternion(
        min.w + ( max.w - min.w ) * RandomReal (),
        min.x + ( max.x - min.x ) * RandomReal (),
        min.y + ( max.y - min.y ) * RandomReal (),
        min.z + ( max.z - min.z ) * RandomReal ()
    );
}
| double WoRB::RandomReal | ( | ) | 
Gets a uniform real number in range [0,1).
Definition at line 24 of file Utilities.cpp.
Referenced by RandomQuaternion().
{ 
    return double( rand() ) / RAND_MAX;
};
| void WoRB::RenderAxes | ( | double | length | ) | 
Draws the world axes.
Definition at line 152 of file Utilities.cpp.
References RenderText().
Referenced by WoRB_TestBed::DisplayEventHandler().
{
    glLineWidth( 2 );
    /////////////////////////////////////////////////////////////////////////////////////
    // Display X-axis for the world
    glColor3d( 1, 0, 0 );
    glBegin( GL_LINES );
    glVertex3d( 0, 0, 0 );
    glVertex3d( length, 0, 0 );
    glEnd ();
    RenderText( length + 0.3, 0, 0, "X" );
    /////////////////////////////////////////////////////////////////////////////////////
    // Display Y-axis for the world
    glColor3d( 0, 0.8, 0 );
    glBegin( GL_LINES );
    glVertex3d( 0, 0, 0 );
    glVertex3d( 0, length, 0 );
    glEnd ();
    RenderText( 0, length + 0.3, 0, "Y" );
    /////////////////////////////////////////////////////////////////////////////////////
    // Display Z-axis for the world
    glColor3d( 0, 0, 1 );
    glBegin( GL_LINES );
    glVertex3d( 0, 0, 0 );
    glVertex3d( 0, 0, length );
    glEnd ();
    RenderText( 0, 0, length + 0.3, "Z" );
    glLineWidth( 1 );
}
| int WoRB::RenderPrintf | ( | int | x, | 
| int | y, | ||
| const char * | format, | ||
| ... | |||
| ) | 
Renders the given text to the given location in screen space on the window.
Definition at line 193 of file Utilities.cpp.
Referenced by WoRB_TestBed::RenderDebugInfo().
{
    char buffer[ 2048 ];
    va_list args;
    va_start( args, format );
    #ifdef _WIN32
    #pragma warning(disable:4996)
    #endif
    vsprintf( buffer, format, args );
    va_end( args );
    // Loop through characters displaying them.
    //
    void* font = GLUT_BITMAP_8_BY_13; // GLUT_BITMAP_HELVETICA_10
    glRasterPos2d( x, y );
    for( const char* ch = buffer; *ch; ++ch ) 
    {
        if ( *ch == '\n' ) {
            // Move down by the line-height on new-line
            y -= int( glutBitmapHeight( font ) * 1.2 );
            glRasterPos2d( x, y );
        } 
        else {
            glutBitmapCharacter( font, *ch );
        }
    }
    return y -= int( glutBitmapHeight( font ) * 1.2 );
}
| void WoRB::RenderStateVariables | ( | const RigidBody & | body, | 
| const Quaternion & | extent | ||
| ) | 
Draws the geometry axes, angular velocity and angular momentum.
Definition at line 75 of file Utilities.cpp.
References WoRB::RigidBody::AngularMomentum, WoRB::RigidBody::AngularVelocity, WoRB::Quaternion::ImSquaredNorm(), WoRB::Quaternion::Normalize(), WoRB::RigidBody::Position, RenderText(), WoRB::Quaternion::x, WoRB::Quaternion::y, and WoRB::Quaternion::z.
Referenced by WoRB::Ball::Render(), and WoRB::Box::Render().
{
    double maxExtent = std::max( extent.x, std::max( extent.y, extent.z ) ) * 1.2;
    Quaternion pos = body.Position;
    Quaternion w = body.AngularVelocity;
    Quaternion L = body.AngularMomentum;
    glLineWidth( 2 );
    /////////////////////////////////////////////////////////////////////////////////////
    // Display angular velocity
    if ( w.ImSquaredNorm () > 1e-3 ) {
        w.Normalize( maxExtent );
        glColor3d( 0, 0, 0 );
        glBegin( GL_LINES );
        glVertex3d( pos.x, pos.y, pos.z );
        glVertex3d( pos.x + w.x, pos.y + w.y, pos.z + w.z );
        glEnd ();
        RenderText( pos.x + w.x, pos.y + w.y * 1.08, pos.z + w.z, "w" );
    }
    /////////////////////////////////////////////////////////////////////////////////////
    // Display angular momentum
    if ( L.ImSquaredNorm () > 1e-3 ) {
        L.Normalize( maxExtent );
        glColor3d( 0.5, 0.5, 0.5 );
        glBegin( GL_LINES );
        glVertex3d( pos.x, pos.y, pos.z );
        glVertex3d( pos.x + L.x, pos.y + L.y, pos.z + L.z );
        glEnd ();
        RenderText( pos.x + L.x, pos.y + L.y * 1.08, pos.z + L.z, "L" );
    }
    glLineWidth( 1 );
    GLTransform bodySpace( body );
    /////////////////////////////////////////////////////////////////////////////////////
    // Display body's X-axis
    glColor3d( 0.8, 0, 0 );
    glBegin( GL_LINES );
    glVertex3d( 0, 0, 0 );
    glVertex3d( extent.x, 0, 0 );
    glEnd ();
    RenderText( extent.x * 1.07, 0, 0, "X" );
    /////////////////////////////////////////////////////////////////////////////////////
    // Display body's Y-axis
    glColor3d( 0, 0.6, 0 );
    glBegin( GL_LINES );
    glVertex3d( 0, 0, 0 );
    glVertex3d( 0, extent.y, 0 );
    glEnd ();
    RenderText( 0, extent.y * 1.07, 0, "Y" );
    /////////////////////////////////////////////////////////////////////////////////////
    // Display body's Z-axis
    glColor3d( 0, 0, 0.8 );
    glBegin( GL_LINES );
    glVertex3d( 0, 0, 0 );
    glVertex3d( 0, 0, extent.z );
    glEnd ();
    RenderText( 0, 0, extent.z * 1.07, "Z" );
}
| void WoRB::RenderText | ( | double | x, | 
| double | y, | ||
| double | z, | ||
| const char * | text | ||
| ) | 
Renders the given text to the given location in body-fixed space.
Definition at line 53 of file Utilities.cpp.
Referenced by RenderAxes(), and RenderStateVariables().
{
    void* font = GLUT_BITMAP_TIMES_ROMAN_10;
    // Loop through characters displaying them.
    //
    glRasterPos3d( x, y, z );
    for( const char* ch = text; *ch; ++ch ) 
    {
        if ( *ch == '\n' ) {
            // If we meet a newline, then move down by the line-height
            y -= glutBitmapHeight( font ) * 1.2;
            glRasterPos3d( x, y, z );
        }
        glutBitmapCharacter( font, *ch );
    }
}
| void WoRB::SevereError | ( | const char * | errorId, | 
| const char * | errorMsg, | ||
| ... | |||
| ) | 
Reports a severe error (with errorId compatible with MATLAB) and quits.
Definition at line 89 of file Platform.cpp.
Referenced by Mex::Matrix::Initialize(), Mex::Scalar::Initialize(), Mex::Logical::Initialize(), Mex::String::Initialize(), Mex::Matrix::operator()(), WoRB_MexFunction::Parse(), and Mex::Matrix::VerifyDims().
    {
        va_list args;
        va_start( args, errorMsg );
        char buffer[ 1024 ];
        vsprintf( buffer, errorMsg, args );
        va_end( args );
        #if MATLAB_MEX_FILE
            mexErrMsgIdAndTxt( errorId, "%s", buffer );
        #else
            fputs( errorId, stderr );
            fputs( "\n", stderr );
            fputs( buffer, stderr );
            fflush( stderr );
            exit(0);
        #endif
    }