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
9#include <glm/vec3.hpp>
10#include <glm/vec4.hpp>
11#include <glm/mat4x4.hpp>
12
13#include <string>
14
15namespace Cogs
16{
17 namespace Core
18 {
59 {
60 AxisCubeComponent() = default;
61
62 Context* context = nullptr;
63 glm::vec3 minCorner = glm::vec3(-1.f);
64 glm::vec3 maxCorner = glm::vec3(1.f);
65 float zScale = 1.f;
66 int maxAxisValues = 10;
67 std::vector<std::string> axisTitles;
68 std::vector<std::string> unitNames;
69 glm::vec3 unitScales = glm::vec3(1.f);
70 bool useAxisAnnotations = true;
72 float tickSizeOffset = 0.05f;
73 glm::vec4 textColor = glm::vec4(1.f);
74 float annotationGap = 100.0f;
75
76 std::vector<WeakEntityPtr> autoNodes;
77 glm::vec3 autoAdjustMargin = glm::vec3(0.1f);
78
79 EntityPtr topQuadMaterial;
80 EntityPtr bottomQuadMaterial;
81 EntityPtr frontQuadMaterial;
82 EntityPtr backQuadMaterial;
83 EntityPtr rightQuadMaterial;
84 EntityPtr leftQuadMaterial;
85
88
89 glm::bvec3 markerFaces;
90 glm::mat4 worldToLocal;
91
92 static void registerType();
93
94 void initialize(Context * context);
95 void update();
96
97 private:
98 bool initialUpdate = true;
99
100 glm::vec3 corners[8];
101 glm::vec3 tickSizes;
102 float tickProtrusion = 0.0f;
103
104 MaterialInstanceHandle gridMatInstH;
105 MaterialInstanceHandle edgeMatInstH;
106 std::vector<EntityPtr> unprocessedAutoNodes;
107
109 {
110 bool visible = false;
111 EntityPtr solid;
112 EntityPtr grid;
113 glm::vec4 equation;
114 };
115 PerFaceData faces[6];
116
117 EntityPtr axisTitlesRightEntity; // Right-adjusted titles
118 EntityPtr axisTitlesLeftEntity; // Left-adjusted titles
119
121 {
122 bool visible = false;
123 EntityPtr annotationEntity;
124 };
125 PerEdgeData edges[12];
126
127 void updateQuadGeometry(int face, EntityPtr material);
128
129 void updateCorners();
130
131 void updateAdjustedMinAndMax(const glm::vec3& minCorner, const glm::vec3& maxCorner);
132
133 void updateTickSizes();
134
135 void updateFaceVisibilites(bool forceUpdate);
136
137 void updateEdgeVisibilites(bool forceUpdate);
138
139 void updateAxisLabels(bool forceUpdate);
140
141 void updateGridGeometry(int face);
142
143 void updateAnnotationAxes();
144 };
145 }
146}
147
148template<> 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
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.