-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathCNC_ClockApp.cpp
More file actions
101 lines (80 loc) · 4.17 KB
/
CNC_ClockApp.cpp
File metadata and controls
101 lines (80 loc) · 4.17 KB
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#include "CNC_ClockApp.h"
#include "CNC_PlatformServices.h"
#include "CNC_Math.h"
#include <time.h>
Application* LoadApplication( PlatformServices* services, void* renderer )
{
ClockApp* app = (ClockApp*)malloc( sizeof( ClockApp ) );
app->m_services = services;
app->m_renderer = renderer;
app->m_background = services->f_loadImage( "res/clock_bgr.png" );
app->m_hourHand = services->f_loadImage( "res/clock_hours.png" );
app->m_minuteHand = services->f_loadImage( "res/clock_minutes.png" );
app->m_knob = services->f_loadImage( "res/clock_knob.png" );
app->m_highlight = services->f_loadImage( "res/clock_highlight.png" );
ModelData bgrData = {0};
ModelData hourData = {0};
ModelData minData = {0};
ModelData knobData = {0};
ModelData highlight = {0};
f32 centerX = (f32)app->m_background->m_width / 2.0f;
f32 centerY = (f32)app->m_background->m_height / 2.0f;
f32 hourHeight = app->m_hourHand->m_height - 15.0f;
f32 hourWidth = app->m_hourHand->m_width;
f32 minHeight = app->m_minuteHand->m_height - 15.0f;
f32 minWidth = app->m_minuteHand->m_width;
f32 knobHeight = app->m_knob->m_height;
f32 knobWidth = app->m_knob->m_width;
f32 hightlightWidth = app->m_highlight->m_width;
bgrData.m_pivotMatrix = identityMatrix();
hourData.m_pivotMatrix = translationMatrix( -hourWidth / 2.0f, -hourHeight );
minData.m_pivotMatrix = translationMatrix( -minWidth / 2.0f, -minHeight );
knobData.m_pivotMatrix = identityMatrix();
highlight.m_pivotMatrix = translationMatrix( -hightlightWidth / 2.0f, -(minHeight + 52.0f ) );
bgrData.m_modelMatrix = identityMatrix();
hourData.m_modelMatrix = translationMatrix( centerX, centerY );
minData.m_modelMatrix = translationMatrix( centerX, centerY) ;
knobData.m_modelMatrix = translationMatrix( centerX - knobWidth / 2.0f, centerY - knobHeight / 2.0f );
highlight.m_modelMatrix = translationMatrix( centerX, centerY );
highlight.m_rotation = toRadians( -(180.0f / 6.0f) );
app->m_background->m_modelData = bgrData;
app->m_hourHand->m_modelData = hourData;
app->m_minuteHand->m_modelData = minData;
app->m_knob->m_modelData = knobData;
app->m_highlight->m_modelData = highlight;
app->m_background->m_textureId = services->f_uploadImage( app->m_renderer, app->m_background );
app->m_hourHand->m_textureId = services->f_uploadImage( app->m_renderer, app->m_hourHand );
app->m_minuteHand->m_textureId = services->f_uploadImage( app->m_renderer, app->m_minuteHand );
app->m_knob->m_textureId = services->f_uploadImage( app->m_renderer, app->m_knob );
app->m_highlight->m_textureId = services->f_uploadImage( app->m_renderer, app->m_highlight );
return app;
}
void UpdateApplication( Application* application )
{
ClockApp* app = (ClockApp*)application;
PlatformServices* services = app->m_services;
time_t rawTime;
tm* timeInfo;
time( &rawTime );
timeInfo = localtime( &rawTime );
f32 hours = (timeInfo->tm_hour) % 12;
f32 minutes = timeInfo->tm_min;
f32 hourAngle = (180.0f / 6.0f) * hours;
f32 minuteAngle = (180.0f / 30.0f) * minutes;
f32 minsPerHour = ((180.0f / 6.0) / 60.0f) * minutes;
app->m_hourHand->m_modelData.m_rotation = toRadians( -(hourAngle + minsPerHour) );
app->m_minuteHand->m_modelData.m_rotation = toRadians( -minuteAngle );
services->f_updateImage( app->m_renderer, app->m_hourHand );
services->f_updateImage( app->m_renderer, app->m_minuteHand );
app->m_hours = hours;
}
void RenderApplication( Application* application )
{
ClockApp* app = (ClockApp*)application;
PlatformServices* services = app->m_services;
services->f_renderImage( app->m_renderer, app->m_background->m_textureId, 1 );
services->f_renderImage( app->m_renderer, app->m_hourHand->m_textureId, 1 );
services->f_renderImage( app->m_renderer, app->m_minuteHand->m_textureId, 1 );
services->f_renderImage( app->m_renderer, app->m_knob->m_textureId, 1 );
services->f_renderImage( app->m_renderer, app->m_highlight->m_textureId, app->m_hours );
}