ProtoTracer  1.0
Real-time 3D rendering and animation engine
Loading...
Searching...
No Matches
Clock.h
Go to the documentation of this file.
1/**
2 * @file Clock.h
3 * @brief A material class for rendering a real-time clock with date and time overlays.
4 *
5 * The `Clock` class is designed to display time and date using a combination of text and materials.
6 * It provides options for 24-hour or 12-hour time formats and allows customization of its size,
7 * position, rotation, and material.
8 *
9 * @date 22/12/2024
10 * @author Coela Can't
11 */
12
13#pragma once
14
15#include "../../Static/SimpleMaterial.h" // For rendering static materials.
16#include "../Overlays/Text/TextEngine.h" // For rendering text overlays.
17#include "../../Material.h" // Base class for all materials.
18
19/**
20 * @class Clock
21 * @brief Renders a real-time clock and date as a material.
22 *
23 * The `Clock` class uses a `TextEngine` to display formatted time and date, along with
24 * a customizable material for rendering.
25 */
26class Clock : public Material {
27private:
28 TextEngine<3, 12> tE = TextEngine<3, 12>(false); ///< Text engine for rendering time and date.
29 SimpleMaterial mat = SimpleMaterial(RGBColor(255, 255, 255)); ///< Default material for the clock.
30 uint8_t hour; ///< Current hour.
31 uint8_t minute; ///< Current minute.
32 uint8_t second; ///< Current second.
33 uint8_t day; ///< Current day.
34 uint8_t month; ///< Current month.
35 uint8_t year; ///< Current year (last two digits).
36 uint8_t wDay; ///< Current weekday.
37 bool hour24 = false; ///< Flag for 24-hour format (true) or 12-hour format (false).
38
39public:
40 /**
41 * @brief Constructs a Clock instance with a specified time format.
42 *
43 * @param hour24 If true, uses 24-hour format; otherwise, uses 12-hour format.
44 */
45 Clock(bool hour24);
46
47 /**
48 * @brief Sets the material to be used for rendering the clock.
49 *
50 * @param material Pointer to a custom material.
51 */
52 void SetMaterial(Material* material);
53
54 /**
55 * @brief Sets the current time for the clock.
56 *
57 * @param hour The hour value (0-23 for 24-hour format, 0-12 for 12-hour format).
58 * @param minute The minute value (0-59).
59 * @param second The second value (0-59).
60 */
61 void SetTime(uint8_t hour, uint8_t minute, uint8_t second);
62
63 /**
64 * @brief Sets the current date for the clock.
65 *
66 * @param day The day value (1-31).
67 * @param month The month value (1-12).
68 * @param year The last two digits of the year (e.g., 24 for 2024).
69 * @param wDay The weekday value (0-6, where 0 = Sunday).
70 */
71 void SetDate(uint8_t day, uint8_t month, uint8_t year, uint8_t wDay);
72
73 /**
74 * @brief Sets the size of the clock's rendered area.
75 *
76 * @param size A `Vector2D` representing the size (width and height).
77 */
78 void SetSize(Vector2D size);
79
80 /**
81 * @brief Sets the position of the clock in the rendered scene.
82 *
83 * @param position A `Vector2D` representing the position.
84 */
85 void SetPosition(Vector2D position);
86
87 /**
88 * @brief Sets the rotation of the clock in the rendered scene.
89 *
90 * @param rotation The rotation angle in degrees.
91 */
92 void SetRotation(float rotation);
93
94 /**
95 * @brief Updates the clock's time and date.
96 *
97 * This function is called to refresh the displayed time and date values.
98 */
99 void Update();
100
101 /**
102 * @brief Computes the color at a given position in the clock's material.
103 *
104 * This method is used for rendering the clock and applying effects.
105 *
106 * @param position The position in 3D space.
107 * @param normal The surface normal vector.
108 * @param uvw The texture coordinates.
109 * @return The computed color as an `RGBColor`.
110 */
111 RGBColor GetRGB(const Vector3D& position, const Vector3D& normal, const Vector3D& uvw) override;
112};
Renders a real-time clock and date as a material.
Definition Clock.h:26
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
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
A material that applies a single, solid RGB color to surfaces.
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