1 / 8

OpenGL Sample Code - A 3D Analog Clock

OpenGL Sample Code - A 3D Analog Clock. Luke Yulu Chen. How to Program a 3D Analog Clock. Get System Time Convert Time to Rotation Angle Draw Hands for Hour, Minute and Second Make Hands Rotate with Time. Get System Time. Commands time_t time ( time_t * timer );

Télécharger la présentation

OpenGL Sample Code - A 3D Analog Clock

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. OpenGL Sample Code- A 3D Analog Clock Luke Yulu Chen

  2. How to Program a 3D Analog Clock • Get System Time • Convert Time to Rotation Angle • Draw Hands for Hour, Minute and Second • Make Hands Rotate with Time

  3. Get System Time • Commands • time_t time ( time_t *timer ); • The time function returns the number of seconds elapsed since midnight (00:00:00), January 1, 1970, GMT, according to the system clock. • struct tm *localtime ( time_t *timer ); • Converts a time value and corrects for the local time zone. • Returns a pointer to the structure result.

  4. Get System Time • Structure tm struct tm { int tm_sec; // seconds after the minute [0,59] int tm_min; // minutes after the hour [0,59] int tm_hour; // hours since midnight [0,23] int tm_mday; int tm_mon; int tm_year; int tm_wday; int tm_yday; int tm_isdst; }

  5. rot_sec = - (float)curtime->tm_sec * (360.0/60.0); second degree per second Convert Time to Rotation Angle • Rotation Angle for a Second Hand • What is the angle for a hour hand?

  6. Draw Hands for Hour, Minute and Second • Composed by Sphere, Cylinder, Disk and Cone

  7. Draw Hands for Hour, Minute and Second • Rotate around X-Axis with -90 • Z-Axis points out of screen • PushMatrix ( ); • Rotatef (-90.0, 0.0, 0.0, 1.0); • glBegin ( … ); • … • glEnd ( … ); • PopMatrix ( );

  8. Make Hands Rotate with Time

More Related