-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathhello_layers.cpp
More file actions
110 lines (94 loc) · 3.16 KB
/
Copy pathhello_layers.cpp
File metadata and controls
110 lines (94 loc) · 3.16 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
102
103
104
105
106
107
108
109
110
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <nothofagus.h>
int main()
{
// Create a canvas for rendering
// - Size: 150x100
// - Title: "Set Layer"
// - Background color: light gray (RGB: 0.7, 0.7, 0.7)
// - Pixel Size: 6
Nothofagus::Canvas canvas({150, 100}, "Set Layer", {0.7, 0.7, 0.7}, 6);
Nothofagus::ColorPallete pallete{
{0.0, 0.0, 0.0, 1.0}, // Black
{1.0, 0.0, 0.0, 1.0}, // Red
{0.0, 1.0, 0.0, 1.0}, // Green
{0.0, 0.0, 1.0, 1.0}, // Blue
{1.0, 1.0, 0.0, 1.0} // Yellow
};
// Create a Texture with dimensions 4x4 and 5 layers
Nothofagus::IndirectTexture textureArray({4, 4}, glm::vec4(0,0,0,1), 5);
// Assign each color palette to a specific layer in the texture array
// Each layer is filled with the corresponding palette color
textureArray
.setPallete(pallete)
.setPixels({
0,0,0,0,
0,0,0,0,
0,0,0,0,
0,0,0,0
}, 0)
.setPixels({
1,1,1,1,
1,1,1,1,
1,1,1,1,
1,1,1,1
}, 1)
.setPixels({
2,2,2,2,
2,2,2,2,
2,2,2,2,
2,2,2,2
}, 2)
.setPixels({
3,3,3,3,
3,3,3,3,
3,3,3,3,
3,3,3,3
}, 3)
.setPixels({
4,4,4,4,
4,4,4,4,
4,4,4,4,
4,4,4,4
}, 4);
// Add the Texture to the canvas
Nothofagus::TextureId textureId = canvas.addTexture(textureArray);
// Create an Bellota using the Texture
// - Position: (75, 50)
// - Layer count: 5
Nothofagus::BellotaId animatedBellotaId = canvas.addBellota({{{75.0f, 50.0f}}, textureId, 5});
// Access the Bellota object to modify its properties
Nothofagus::Bellota& animatedbellota = canvas.bellota(animatedBellotaId);
// Scale the Bellota to 10x10 units
animatedbellota.transform().scale() = glm::vec2(10.0f, 10.0f);
// Timer for updating logic
float time = 0.0f;
// Define the update function for the canvas
auto update = [&](float dt)
{
time += dt;
// No specific update logic here, but time accumulates for potential future use
};
// Initialize layer index variable
int layer = 0;
// Create a controller for handling user inputs
Nothofagus::Controller controller;
// Register a keybinding for "W" to increment the current layer
controller.registerAction({Nothofagus::Key::W, Nothofagus::DiscreteTrigger::Press}, [&]()
{
layer = (layer + 1) % 5; // Cycle to the next layer (0-4)
animatedbellota.currentLayer() = layer; // Update the visible layer
});
// Register a keybinding for "S" to decrement the current layer
controller.registerAction({Nothofagus::Key::S, Nothofagus::DiscreteTrigger::Press}, [&]()
{
layer = (layer + 4) % 5; // Cycle to the previous layer (0-4)
animatedbellota.currentLayer() = layer; // Update the visible layer
});
// Run the canvas with the update function and controller logic
canvas.run(update, controller);
return 0;
}