ProtoTracer  1.0
Real-time 3D rendering and animation engine
Loading...
Searching...
No Matches
Clock.cpp
Go to the documentation of this file.
1#include "Clock.h"
2
3Clock::Clock(bool hour24) {
4 this->hour24 = hour24;
5
7
8 tE.SetBlinkTime(200);
9}
10
12 tE.SetMaterial(material);
13}
14
15void Clock::SetTime(uint8_t hour, uint8_t minute, uint8_t second) {
16 this->hour = hour;
17 this->minute = minute;
18 this->second = second;
19}
20
21void Clock::SetDate(uint8_t day, uint8_t month, uint8_t year, uint8_t wDay) {
22 this->day = day;
23 this->month = month;
24 this->year = year;
25 this->wDay = wDay;
26}
27
29 tE.SetSize(size);
30}
31
33 tE.SetPositionOffset(position);
34}
35
36void Clock::SetRotation(float rotation) {
37 tE.SetRotationAngle(rotation);
38}
39
41 String secondString = second < 10 ? "0" + String(second) : String(second);
42 String minuteString = minute < 10 ? "0" + String(minute) : String(minute);
43 String hourMinSec = String(hour) + ":" + minuteString + ":" + secondString;
44 String date = String(month) + "/" + String(day) + "/" + String(year);
45
46 String dayOfWeek;
47
48 switch (wDay) {
49 case 0:
50 dayOfWeek = "SATURDAY";
51 break;
52 case 1:
53 dayOfWeek = "SUNDAY";
54 break;
55 case 2:
56 dayOfWeek = "MONDAY";
57 break;
58 case 3:
59 dayOfWeek = "TUESDAY";
60 break;
61 case 4:
62 dayOfWeek = "WEDNESDAY";
63 break;
64 case 5:
65 dayOfWeek = "THURSDAY";
66 break;
67 case 6:
68 dayOfWeek = "FRIDAY";
69 break;
70 default:
71 dayOfWeek = "BROKEN";
72 break;
73 }
74
75 tE.SetText(0, hourMinSec, false);
76 tE.SetText(1, date, false);
77 tE.SetText(2, dayOfWeek, false);
78}
79
80RGBColor Clock::GetRGB(const Vector3D& position, const Vector3D& normal, const Vector3D& uvw) {
81 return tE.GetRGB(position, normal, uvw);
82}
A material class for rendering a real-time clock with date and time overlays.
void SetRotation(float rotation)
Sets the rotation of the clock in the rendered scene.
Definition Clock.cpp:36
uint8_t month
Current month.
Definition Clock.h:34
uint8_t day
Current day.
Definition Clock.h:33
bool hour24
Flag for 24-hour format (true) or 12-hour format (false).
Definition Clock.h:37
uint8_t year
Current year (last two digits).
Definition Clock.h:35
uint8_t second
Current second.
Definition Clock.h:32
SimpleMaterial mat
Default material for the clock.
Definition Clock.h:29
uint8_t minute
Current minute.
Definition Clock.h:31
RGBColor GetRGB(const Vector3D &position, const Vector3D &normal, const Vector3D &uvw) override
Computes the color at a given position in the clock's material.
Definition Clock.cpp:80
void SetSize(Vector2D size)
Sets the size of the clock's rendered area.
Definition Clock.cpp:28
Clock(bool hour24)
Constructs a Clock instance with a specified time format.
Definition Clock.cpp:3
TextEngine< 3, 12 > tE
Text engine for rendering time and date.
Definition Clock.h:28
void SetMaterial(Material *material)
Sets the material to be used for rendering the clock.
Definition Clock.cpp:11
void SetTime(uint8_t hour, uint8_t minute, uint8_t second)
Sets the current time for the clock.
Definition Clock.cpp:15
void SetDate(uint8_t day, uint8_t month, uint8_t year, uint8_t wDay)
Sets the current date for the clock.
Definition Clock.cpp:21
uint8_t wDay
Current weekday.
Definition Clock.h:36
uint8_t hour
Current hour.
Definition Clock.h:30
void Update()
Updates the clock's time and date.
Definition Clock.cpp:40
void SetPosition(Vector2D position)
Sets the position of the clock in the rendered scene.
Definition Clock.cpp:32
Abstract base class for rendering materials.
Definition Material.h:27
Represents an RGB color and provides methods for manipulation.
Definition RGBColor.h:23
void SetPositionOffset(Vector2D positionOffset)
void SetRotationAngle(float rotationAngle)
RGBColor GetRGB(const Vector3D &position, const Vector3D &normal, const Vector3D &uvw) override
Pure virtual function to calculate color based on surface parameters.
void SetSize(Vector2D size)
void SetMaterial(Material *material)
void SetBlinkTime(uint16_t blinkTime)
void SetText(uint8_t line, String value, bool centerText=false)
Represents a 2D vector (X, Y) and provides methods for vector arithmetic.
Definition Vector2D.h:27
Represents a 3D vector (X, Y, Z) and provides methods for vector arithmetic.
Definition Vector3D.h:26