PDA

View Full Version : Analog Clock

03-10-2002, 09:26 PM
hi

i want to do analog clock.

how can i do it ?

anyone have the code?

thank u ,
shaul

mikael_aronsson
03-10-2002, 11:56 PM
Hi !

Not sure what to help you with, this is very simple so you possible need to read some book on 3D graphics/OpenGL first to get you started.

But, you use glBegin( GL_LINE_STRIP) to create the circle, then you use glBegin( GL_LINE) to draw the hands of the clock and use glRotate?() to rotate the hands to the correct position (30 degrees is 5 minutes/seconds), you must use glRotate?() before you draw the hands, and place the clock at the origin to make rotation easy though. Any OpenGL tutorial will explain how to to use glBegin() glEnd().

I hope that helps a bit, also have a look at the OpenGL FAQ on this website.

Mikael

nexusone
03-11-2002, 05:21 AM
There are few examples out there of doing a clock. I don't have the links handy, but if you go to this website you can find some links to other open gl sites some which have a example; http://nehe.gamedev.net
You also can go though a few of the examples program on this web site. After learning a little more opengl then doing a analog clock will be easy.

Originally posted by shaul:
hi

i want to do analog clock.

how can i do it ?

anyone have the code?

thank u ,
shaul

rIO
03-12-2002, 11:32 PM
this pseudo code should help a bit..

glPusMatrix();
glTranslatef(clockcenter);
//to draw the outline shape
glBegin(GL_LINE_STRIP);
cicle (i = 0 < TWOPI)
{
}
glEnd();

glBegin(GL_LINES);
//draw the hour line
glVertex3f(0,0,0);
glVertex3f(sin(getHour() * 30) * hourlinelenght,cos(getHour())* hourlinelenght,0);

//draw seconds line
glVertex3f(0,0,0);
glVertex3f(sin(getSeconds() * 6) * secslinelenght,cos(getSeconds())* secslinelenght,0);

//draw mins line
glVertex3f(0,0,0);
glVertex3f(sin(getMins() * 6) * secslinelenght,cos(getMins())* secslinelenght,0);
glEnd();

rIO.sK http://www.spinningkids.org/rio