summaryrefslogtreecommitdiff
path: root/themes/src
diff options
context:
space:
mode:
authorMatthew Kosarek <matthew@matthewkosarek.xyz>2023-09-27 07:42:11 -0400
committerMatthew Kosarek <matthew@matthewkosarek.xyz>2023-09-27 07:42:11 -0400
commitec0b1d450a0f6219b3b0d352cd6625ae05f62618 (patch)
treeef515bd14d5dbc229013e054e3ca3b7a8f8e2ad5 /themes/src
parent2dca902c183ece31bc0853e1e8b93d09359515e4 (diff)
Hills in the AutumnTheme
Diffstat (limited to 'themes/src')
-rw-r--r--themes/src/autumn/AutumnTheme.cpp41
-rw-r--r--themes/src/autumn/AutumnTheme.hpp4
-rw-r--r--themes/src/autumn/TreeShape.cpp2
-rw-r--r--themes/src/shapes_2d.cpp49
-rw-r--r--themes/src/shapes_2d.h19
5 files changed, 108 insertions, 7 deletions
diff --git a/themes/src/autumn/AutumnTheme.cpp b/themes/src/autumn/AutumnTheme.cpp
index 754a841..affcc00 100644
--- a/themes/src/autumn/AutumnTheme.cpp
+++ b/themes/src/autumn/AutumnTheme.cpp
@@ -3,16 +3,41 @@
#include "../shapes_2d.h"
#include <memory>
+namespace
+{
+ const int NUM_HILLS = 3;
+}
+
void AutumnTheme::load(Renderer2d* renderer) {
renderer->clearColor = Vector4(252, 210, 153, 255).toNormalizedColor();
auto lr = tree.load(renderer);
leafParticles.load(renderer, &lr);
- background = new RectangularGradient(*renderer,
- Vector4{135, 206, 235, 255}.toNormalizedColor(),
- Vector4(252, 210, 153, 255).toNormalizedColor(),
- renderer->get_width(),
- renderer->get_height(),
- {0, 0});
+ background = new RectangularGradient(
+ *renderer,
+ Vector4{135, 206, 235, 255}.toNormalizedColor(),
+ Vector4(252, 210, 153, 255).toNormalizedColor(),
+ renderer->get_width(),
+ renderer->get_height(),
+ {0, 0});
+
+
+ background_hill = new Circleish(
+ *renderer,
+ 1000,
+ Vector4(137, 129, 33, 255).toNormalizedColor(),
+ 100,
+ 0,
+ 50);
+ background_hill->mesh.model = background_hill->mesh.model.translateByVec2({1200, -700});
+
+ tree_hill = new Circleish(
+ *renderer,
+ 500,
+ Vector4{ 76, 75, 22, 255 }.toNormalizedColor(),
+ 100,
+ 0,
+ 50);
+ tree_hill->mesh.model = tree_hill->mesh.model.translateByVec2(Vector2(300, -290));
}
void AutumnTheme::update(f32 dtSeconds) {
@@ -22,7 +47,9 @@ void AutumnTheme::update(f32 dtSeconds) {
void AutumnTheme::render(Renderer2d* renderer) {
background->render();
+ background_hill->render();
tree.render(renderer);
+ tree_hill->render();
leafParticles.render(renderer);
}
@@ -30,4 +57,6 @@ void AutumnTheme::unload() {
tree.unload();
leafParticles.unload();
delete background;
+ delete background_hill;
+ delete tree_hill;
}
diff --git a/themes/src/autumn/AutumnTheme.hpp b/themes/src/autumn/AutumnTheme.hpp
index 7c1f4f2..2d9958c 100644
--- a/themes/src/autumn/AutumnTheme.hpp
+++ b/themes/src/autumn/AutumnTheme.hpp
@@ -5,14 +5,18 @@
#include "LeafParticleRender.h"
#include "../types.h"
#include <memory>
+#include <vector>
struct Renderer2d;
class RectangularGradient;
+class Circleish;
struct AutumnTheme {
TreeShape tree;
LeafParticleRender leafParticles;
RectangularGradient* background;
+ Circleish* tree_hill;
+ Circleish* background_hill;
void load(Renderer2d* renderer);
void update(f32 dtSeconds);
diff --git a/themes/src/autumn/TreeShape.cpp b/themes/src/autumn/TreeShape.cpp
index 9738fd5..7c80929 100644
--- a/themes/src/autumn/TreeShape.cpp
+++ b/themes/src/autumn/TreeShape.cpp
@@ -42,7 +42,7 @@ TreeShapeLoadResult TreeShape::load(Renderer2d* renderer) {
lr.updateData = updateData;
lr.numBranches = numBranches;
i32 branchIndex = 0;
- createBranch(&ld, generationData, numBranches, &branchIndex, 0, ld.trunkWidth, ld.trunkHeight, Vector2 { 300.f, 50.f }, 0, NULL, vertices, &lr);
+ createBranch(&ld, generationData, numBranches, &branchIndex, 0, ld.trunkWidth, ld.trunkHeight, Vector2 { 300.f, 200.f }, 0, NULL, vertices, &lr);
useShader(renderer->shader);
diff --git a/themes/src/shapes_2d.cpp b/themes/src/shapes_2d.cpp
index a85e0da..d5a29ed 100644
--- a/themes/src/shapes_2d.cpp
+++ b/themes/src/shapes_2d.cpp
@@ -1,6 +1,7 @@
#include "shapes_2d.h"
#include "Renderer2d.h"
#include "mathlib.h"
+#include "list.h"
RectangularGradient::RectangularGradient(Renderer2d& renderer,
Vector4 top,
@@ -37,3 +38,51 @@ void RectangularGradient::render()
{
mesh.render(&renderer);
}
+
+
+Circleish::Circleish(
+ Renderer2d& renderer,
+ f32 radius,
+ Vector4 color,
+ i32 segments,
+ i32 segment_start,
+ i32 segment_end)
+ : renderer{renderer}
+{
+ matte::List<Vertex2D> vertices;
+ matte::List<u32> indices;
+ vertices.add({ Vector2(0, 0), color, Mat4x4() });
+
+ if (segment_end == 0)
+ segment_end = segments;
+
+ f32 radiansPerSector = (2.f * PI) / segments;
+ for (i32 i = segment_start; i <= segment_end; i++) {
+ f32 radians = radiansPerSector * i;
+ f32 cosAngle = cosf(radians);
+ f32 sinAngle = sinf(radians);
+ Vector2 vertex = Vector2(radius * cosAngle, radius * sinAngle);
+ vertices.add({ vertex, color, Mat4x4() });
+
+ u32 first = i;
+ u32 second = 0;
+ u32 third = i + 1;
+ indices.add(first);
+ indices.add(second);
+ indices.add(third);
+ }
+
+ mesh.load(&vertices.data[0], vertices.numElements, &indices.data[0], indices.numElements, &renderer);
+ vertices.deallocate();
+ indices.deallocate();
+}
+
+Circleish::~Circleish()
+{
+ mesh.unload();
+}
+
+void Circleish::render()
+{
+ mesh.render(&renderer);
+}
diff --git a/themes/src/shapes_2d.h b/themes/src/shapes_2d.h
index acb8522..8e08504 100644
--- a/themes/src/shapes_2d.h
+++ b/themes/src/shapes_2d.h
@@ -26,4 +26,23 @@ class RectangularGradient
Mesh2D mesh;
};
+
+/// Supports full and partial circles
+class Circleish
+{
+public:
+ Circleish(
+ Renderer2d& renderer,
+ f32 radius,
+ Vector4 color,
+ i32 segments,
+ i32 segment_start = 0,
+ i32 segment_end = 0);
+ ~Circleish();
+ void render();
+
+ Renderer2d& renderer;
+ Mesh2D mesh;
+};
+
#endif