Praktikum 02

must be demonstrated by: Fri, 03.July at 12:00

must complete Praktikum 00 and Praktikum 01 prior to demonstrating this

Create a clock face, with hour and minute and second hands, using OpenGL.

Start with your OpenGL clock face from above. Add a hand to show seconds. When the left mouse button is clicked, your clock should start a continuous display of the actual time. It should be a valid clock (hours depend on minutes and seconds, and minutes depend on seconds). The clock should stop updating the time (“ticking”) when you click the right mouse button. You will need to use double buffering. You might find the comments and code at the bottom of this page useful.

When the buttons q or Q are pressed, the program should exit.

Your screen size and clocksize should be square, and adjustable at compile-time. Put a border around the clock. Represent the tick marks for minutes and hours as line segments. Your border, tick marks, and clock hands should all be different colors. Mark the center of the clock with a thick dot. Don’t hardcode lengths or positions. They should be relative to the size of the window.

Remember:
The (0,0) vertex in OpenGL is at the bottom left of the window.

You’ve already derived most of the math/trig for a clock when doing Praktikum 01.

Please answer the question below, by putting the answer in comments at the top of your code. The instructor will discuss it with you when you demonstrate the code.

1. Do you have problems with aliasing?"

 

/* Comments: note that tm is already defined in <ctime>

struct tm {
int tm_sec;      //seconds
int tm_min;      //minutes
int tm_hour;     //hours, 0-23
int tm_mday;     //day of month
int tm_mon;      //months since Jan
int tm_year;     //years from 1900
int tm_wday;     //days since Sunday
int tm_yday;     //days since Jan. 1
int tm_isdst;    //daylight saving time indicator
}

time() returns the current calendar time of the system, a variable of type time_t
it is called with either a NULL pointer or a pointer to a variable of type time_t

time_t time( time_t *time )

localtime() returns a pointer to the broken down form of time in the form of a tm structure
the input is a pointer to the time obtained from a call to the time function

struct tm *localtime( const time_t *time );

*/

 

// Code fragment
#include <ctime>

time_t *t1,t2;

t2=time(NULL);
t1=&t2;

tm *p1;

p1=localtime( t1 );
hours=p1->tm_hour;  // (*p1).tm_hour
minutes=p1->tm_min; // (*p1).tm_min
seconds=p1->tm_sec; // (*p1).tm_sec