-
Notifications
You must be signed in to change notification settings - Fork 0
/
Clock.cpp
73 lines (54 loc) · 1.41 KB
/
Clock.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include "Clock.h"
#include "CGFappearance.h"
Clock::Clock() {
clockCyl = new Cylinder(12, 1, true);
HourHand = new ClockHand();
MinHand = new ClockHand();
SecHand = new ClockHand();
HourHand->setAngle(270);
MinHand->setAngle(180);
SecHand->setAngle(90);
_active=true;
}
void Clock::draw() {
// Coefficients for material B
float ambB[3] = {0.2, 0.2, 0.2};
float difB[3] = {0.6, 0.6, 0.6};
float specB[3] = {0.8, 0.8, 0.8};
float shininessB = 120.f;
clockAppearance = new CGFappearance(ambB,difB,specB,shininessB);
clockAppearance->setTexture("clock.png");
clockAppearance->setTextureWrap(GL_REPEAT, GL_REPEAT);
Cylinder* c1 = new Cylinder(12,1,true);
glPushMatrix();
glScaled(0.10,1,1);
glRotated(90,0,1,0);
clockAppearance->apply();
c1->draw();
glPopMatrix();
HourHand->setTimeType(kTimeTypeHours);
MinHand->setTimeType(kTimeTypeMinutes);
SecHand->setTimeType(kTimeTypeSeconds);
HourHand->draw();
MinHand->draw();
SecHand->draw();
}
void Clock::resetClock(){
HourHand->setAngle(0);
MinHand->setAngle(0);
SecHand->setAngle(0);
}
void Clock::update(unsigned long time)
{
if(_active){
float a = ((float)(time)/1000.0)*360.0/60.0;
HourHand->setAngle(HourHand->getAngle() - (a/(3600.0/5.0)));
MinHand->setAngle(MinHand->getAngle() - (a/60.0) );
SecHand->setAngle(SecHand->getAngle() - a);
HourHand->draw();
MinHand->draw();
SecHand->draw();
}
}
Clock::~Clock() {
}