#include #include #include #include // sepcify the ARLib namespaces that are to be used using namespace ARLib::Application; using namespace ARLib::Graphics; using namespace ARLib::Utility; // define OpenGL colour parameters const GLfloat ambientLight[] = { 0.3f, 0.3f, 0.3f, 1.0f }; const GLfloat diffuseLight[] = { 0.7f, 0.7f, 0.7f, 1.0f }; const GLfloat lightPos[] = { 10.0f, 10.0f, -10.0f, 1.0f }; // constants for loaded obj files #define OBJ_MINUTE_HAND 101 #define OBJ_HOUR_HAND 102 #define OBJ_SECOND_HAND 103 /* */ void Clock::OnGetApplicationTitle( ARString &title ) { // Set the title for the AR Application title = "Augmented Ticking Clock"; } /* */ void Clock::OnGetDetailHelp( ARString &help ) { // Set the detail help for the application help = "An augmented reality application that displays a ticking clock."; } /* */ void Clock::OnInit( int *argc, char *argv[] ) { // Call base implementation ARAppBase::OnInit( argc, argv ); // Load custom models that will be used ARModels::Add( "models/bighand.obj" , OBJ_MINUTE_HAND ); ARModels::Add( "models/smallhand.obj" , OBJ_HOUR_HAND ); ARModels::Add( "models/secondhand.obj" , OBJ_SECOND_HAND ); } /* */ void Clock::OnInitDisplayAR() { // Call base implementation ARAppBase::OnInitDisplayAR(); // Setup OpenGL lights glLightfv( GL_LIGHT0, GL_AMBIENT, ambientLight ); glLightfv( GL_LIGHT0, GL_DIFFUSE, diffuseLight ); glLightfv( GL_LIGHT0, GL_POSITION, lightPos ); glColorMaterial( GL_FRONT, GL_AMBIENT_AND_DIFFUSE ); glEnable( GL_LIGHTING ); glEnable( GL_LIGHT0 ); glEnable( GL_COLOR_MATERIAL ); } /* */ void Clock::OnDisplayAR( ARLib::Detection::ARBoundingBox *marker ) { ARAppBase::OnDisplayAR( marker ); // get the time time_t theTime; time( &theTime ); // break the time down into useful elements e.g. hours, minutes and seconds tm *fullTime = localtime( &theTime ); // Draw the Second hand glPushMatrix(); glRotatef(-(6 * fullTime->tm_sec),0,1,0); ARModels::glDrawList( OBJ_SECOND_HAND ); glPopMatrix(); // Draw the Hour hand glPushMatrix(); glRotatef(-((30*fullTime->tm_hour) + ((fullTime->tm_min/60.0)*5)*6),0,1,0); ARModels::glDrawList( OBJ_HOUR_HAND ); glPopMatrix(); // Draw the Minute hand glPushMatrix(); glRotatef(-(6*fullTime->tm_min),0,1,0); ARModels::glDrawList( OBJ_MINUTE_HAND ); glPopMatrix(); }