Cogs.Core
AxisCubeComponent.h
1#pragma once
2
3#include "../../../../Source/Components/Core/DynamicComponent.h"
4#include "../../../../Source/Resources/Resources.h"
5#include "EntityPtr.h"
6
7#include "Foundation/ComponentModel/Entity.h"
8#include "Components/Core/RenderComponent.h"
9
10#include <glm/vec3.hpp>
11#include <glm/vec4.hpp>
12#include <glm/mat4x4.hpp>
13
14#include <string>
15
16namespace Cogs
17{
18 namespace Core
19 {
60 {
61 AxisCubeComponent() = default;
62
63 Context* context = nullptr;
64 glm::vec3 minCorner = glm::vec3(-1.f);
65 glm::vec3 maxCorner = glm::vec3(1.f);
66 float zScale = 1.f;
67 int maxAxisValues = 10;
68 std::vector<std::string> axisTitles;
69 std::vector<std::string> unitNames;
70 glm::vec3 unitScales = glm::vec3(1.f);
71 bool useAxisAnnotations = true;
73 float tickSizeOffset = 0.05f;
74 glm::vec4 textColor = glm::vec4(1.f);
75 float annotationGap = 100.0f;
76
77 std::vector<WeakEntityPtr> autoNodes;
78 glm::vec3 autoAdjustMargin = glm::vec3(0.1f);
79
80 EntityPtr topQuadMaterial;
81 EntityPtr bottomQuadMaterial;
82 EntityPtr frontQuadMaterial;
83 EntityPtr backQuadMaterial;
84 EntityPtr rightQuadMaterial;
85 EntityPtr leftQuadMaterial;
86
89
90 glm::bvec3 markerFaces;
91 glm::mat4 worldToLocal;
92
93 static void registerType();
94
95 void initialize(Context * context);
96 void update();
97
98 private:
99 bool initialUpdate = true;
100
101 glm::vec3 corners[8];
102 glm::vec3 tickSizes;
103 float tickProtrusion = 0.0f;
104
105 MaterialInstanceHandle gridMatInstH;
106 MaterialInstanceHandle edgeMatInstH;
107 std::vector<EntityPtr> unprocessedAutoNodes;
108
110 {
111 bool visible = false;
112 EntityPtr solid;
113 EntityPtr grid;
114 glm::vec4 equation;
115 };
116 PerFaceData faces[6];
117
118 EntityPtr axisTitlesRightEntity; // Right-adjusted titles
119 EntityPtr axisTitlesLeftEntity; // Left-adjusted titles
120
122 {
123 bool visible = false;
124 EntityPtr annotationEntity;
125 };
126 PerEdgeData edges[12];
127
128 RenderLayers renderLayer = RenderLayers::Annotations;
129
130 void updateQuadGeometry(int face, EntityPtr material);
131
132 void updateCorners();
133
134 void updateAdjustedMinAndMax(const glm::vec3& minCorner, const glm::vec3& maxCorner);
135
136 void updateTickSizes();
137
138 void updateFaceVisibilites(bool forceUpdate);
139
140 void updateEdgeVisibilites(bool forceUpdate);
141
142 void updateAxisLabels(bool forceUpdate);
143
144 void updateGridGeometry(int face);
145
146 void updateAnnotationAxes();
147 };
148 }
149}
150
151template<> inline Cogs::StringView getName<Cogs::Core::AxisCubeComponent>() { return "AxisCubeComponent"; }
A Context instance contains all the services, systems and runtime components needed to use Cogs.
Definition: Context.h:83
Base class for components implementing dynamic behavior.
Provides a weakly referenced view over the contents of a string.
Definition: StringView.h:24
std::shared_ptr< ComponentModel::Entity > EntityPtr
Smart pointer for Entity access.
Definition: EntityPtr.h:12
RenderLayers
Contains common render layers.
Contains all Cogs related functionality.
Definition: FieldSetter.h:23
A cube with grids on the side faces.
glm::mat4 worldToLocal
Cached inverted local to world matrix.
glm::vec3 adjustedMinCorner
Minimum corner of the cube.
glm::vec3 autoAdjustMargin
A margin applied to the bounding box of the encased Entity, this property only works alongside autoNo...
glm::vec3 corners[8]
Local-space positions of the eight corners.
float tickProtrusion
Distance the grid lines protrude through the edge.
glm::vec3 unitScales
Size of unit coordinate axis in unitname-units.
glm::vec3 minCorner
Minimum corner of the cube.
float annotationGap
Distance between axis annotations.
std::vector< std::string > unitNames
Name of the x,y,z-axis units.
glm::vec3 maxCorner
Maximum corner of the cube.
int maxAxisValues
The maximum number of axis annotation values to use.
bool useAxisAnnotations
If the axis cube should create axis annotation text.
std::vector< WeakEntityPtr > autoNodes
Entities(Nodes) that are to be encased by this AxisCube.
glm::vec4 textColor
Color of text, to be forwarded to children.
glm::vec3 adjustedMaxCorner
Maximum corner of the cube.
glm::bvec3 markerFaces
False if wall-marker should lie on min-face, true if max-face.
glm::vec3 tickSizes
Size of axis ticks (in unit-units):
bool autoAdjustToLargestDimension
If the auto adjustment should make the box equal in size along all axes.
float zScale
Amount to scale the z-axis.
std::vector< std::string > axisTitles
Titles for the x,y,z-axises.