Kale
Loading...
Searching...
No Matches
PathNodeGL.hpp
Go to the documentation of this file.
1/*
2 Copyright 2022 Rishi Challa
3
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
15*/
16
17#pragma once
18
19#ifdef KALE_OPENGL
20
30
31#include <memory>
32#include <optional>
33#include <vector>
34#include <array>
35#include <utility>
36
37#include <nlohmann/json.hpp>
38
39namespace Kale {
40
45 using JSON = nlohmann::json;
46
50 class PathNode : public Node, public Transformable, public Collidable {
51 public:
52
57 enum class StrokeStyle {
58 Neither = 0, Both = 1, Inside = 2, Outside = 3
59 };
60
65
69 std::array<std::pair<int, float>, 4> startWeight;
70
74 std::array<std::pair<int, float>, 4> controlPoint1Weight;
75
79 std::array<std::pair<int, float>, 4> controlPoint2Weight;
80
84 std::array<std::pair<int, float>, 4> endWeight;
85 };
86
87 private:
88
92 std::unique_ptr<OpenGL::VertexArray<Vector2f, 2>> vertexArray;
93
98
102 static inline std::unique_ptr<const OpenGL::Shader> shader = nullptr;
103
109
113 inline static unsigned int posAttribute;
114
118 static void setup();
119
123 static void cleanup();
124
128 void updateBoundingBox();
129
130 friend class Application;
131
132 protected:
133
139 virtual void begin(const Scene& scene) override;
140
147 virtual void preUpdate(size_t threadNum, const Scene& scene, float deltaTime) override;
148
153 virtual void render(const Camera& camera, float deltaTime) const override;
154
158 virtual void end(const Scene& scene) override;
159
160 public:
161
166 std::optional<StateAnimatable<Path>> pathFSM;
167
171 std::shared_ptr<SkeletalAnimatable> skeletalAnimatable;
172
177 std::optional<std::vector<BezierWeights>> skeletalWeights;
178
183 std::optional<Path> basePath;
184
188 float zPosition = 1.0f;
189
194 bool fill = true;
195
200
204 float strokeRadius = 20.0f;
205
209 Color color = Color(0x333333);
210
215
219 PathNode();
220
225 PathNode(const JSON& json);
226
234
235 };
236}
237
238#endif
static unsigned int fillUniform
static void setup()
static unsigned int localUniform
static unsigned int numBeziersUniform
std::shared_ptr< SkeletalAnimatable > skeletalAnimatable
static unsigned int posAttribute
virtual void preUpdate(size_t threadNum, const Scene &scene, float deltaTime) override
static unsigned int cameraUniform
static unsigned int strokeUniform
virtual void render(const Camera &camera, float deltaTime) const override
static unsigned int zPositionUniform
void updateBoundingBox()
static void cleanup()
std::optional< std::vector< BezierWeights > > skeletalWeights
static std::unique_ptr< const OpenGL::Shader > shader
static unsigned int strokeRadiusUniform
std::optional< Path > basePath
std::unique_ptr< OpenGL::VertexArray< Vector2f, 2 > > vertexArray
std::optional< StateAnimatable< Path > > pathFSM
virtual void end(const Scene &scene) override
virtual void begin(const Scene &scene) override
static unsigned int vertexColorUniform
static unsigned int strokeColorUniform
StrokeStyle stroke
static unsigned int beziersUniform
nlohmann::json JSON
Definition Scene.hpp:39
Vector4f Color
Definition Vector.hpp:631
std::array< std::pair< int, float >, 4 > startWeight
std::array< std::pair< int, float >, 4 > endWeight
std::array< std::pair< int, float >, 4 > controlPoint1Weight
std::array< std::pair< int, float >, 4 > controlPoint2Weight