Cogs.Core
OrbitingCameraController.h
1#pragma once
2
3#include "Components/Core/DynamicComponent.h"
4
5#include <glm/vec3.hpp>
6#include <glm/ext/scalar_constants.hpp>
7#include <glm/ext/vector_int2.hpp>
8
9namespace Cogs::Core
10{
11 class Context;
12 class ViewContext;
13
23 {
24 public:
26 static void registerType();
27
28 void initialize(Context* context);
29 void update();
30
32 void attachToView(ViewContext* viewContext) { view = viewContext; }
33
35 void setTarget(const glm::vec3 & target) { cameraTarget = target; setChanged(); }
36
37 // Fields
38 public:
40 glm::dvec3 cameraTarget = glm::dvec3(0, 0, 0);
41
43 glm::vec3 cameraLook = glm::vec3(0, 0, -1);
44
46 float verticalAngle = glm::pi<float>() * 0.25f;
47
49 float horizontalAngle = 0;
50
52 float distance = 20;
53
55 float minVerticalAngle = 0.0f;
56
58 float maxVerticalAngle = glm::pi<float>();
59
61 float minDistance = 0.01f;
62
64 float maxDistance = 50000.0f;
65
67 float minFOV = glm::radians(1.f);
68
70 float maxFOV = glm::radians(140.f);
71
73 bool enabled = true;
74
76 bool seek = false;
77
79 bool moveCamera = true;
80
83
84 private:
85 Context * context = nullptr;
86 ViewContext* view = nullptr;
87 float horizontalAngleStart = 0.f;
88 float verticalAngleStart = 0.f;
89 float distanceStart = 0.f;
90 float fovStart = 0.f;
91 glm::dvec3 cameraTargetStart;
92
93 bool prevDragWithShift = false;
94 int32_t dragStartCoordY = 0;
95
96 private:
97 void handleSeek(int32_t x, int32_t y);
98 void handleRotate(int32_t x0, int32_t y0, int32_t x1, int32_t y1, bool first);
99 void handleTranslate(int32_t x0, int32_t y0, int32_t x1, int32_t y1, bool first);
100 void handleDolly(float delta, bool first);
101 void handleZoom(float delta, bool first);
102 };
103}
104
105template<> inline Cogs::StringView getName<Cogs::Core::OrbitingCameraController>() { return "OrbitingCameraController"; }
void setChanged()
Sets the component to the ComponentFlags::Changed state with carry.
Definition: Component.h:202
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.
Component that calculates position and orientation of the entity TransformComponent.
float horizontalAngle
Current camera angle in horizontal direction [-TwoPI,+TwoPI] (glm::roll(transformComponent->rotation)...
float minDistance
Minimal distance from camera position to camera target (zoom).
float defaultPickingRadius
Default distance an object can be from a ray to be considered hit.
float maxDistance
Maximal distance from camera position to camera target (zoom).
bool enabled
Navigation is only active when this flag is set.
float maxVerticalAngle
Maximum camera angle in vertical direction [-PI,+PI].
float distance
Distance from camera target to camera.
glm::vec3 cameraLook
camera looking direction. Updated when navigating the camers.
bool seek
Deprecated Seeking flag - not used.
void attachToView(ViewContext *viewContext)
Attach to view - required for ray-picking.
glm::dvec3 cameraTarget
Camera target. Define centre of camera rotation.
bool moveCamera
Set to false to disable controller moving the camera and only apply rotate and zoom....
float minVerticalAngle
Minimum camera angle in vertical direction [-PI,+PI].
float verticalAngle
Current camera angle in vertical direction [-PI,+PI] (glm::pitch(transformComponent->rotation))
void setTarget(const glm::vec3 &target)
Set target position - deprecated. Update "cameraTarget" field instead.
Provides a weakly referenced view over the contents of a string.
Definition: StringView.h:24
Contains the Engine, Renderer, resource managers and other systems needed to run Cogs....