VEX Engine
Retro looking game engine made in vulkan mostly because i wanted to understand it better.
Loading...
Searching...
No Matches
EditorCamera.cpp
1#include "EditorCamera.hpp"
3#include <components/GameComponents/EngineUtility.hpp>
4
5
6EditorCameraObject::EditorCameraObject(vex::Engine& engine, const std::string& name, SDL_Window* window)
7 : CameraObject(engine, name), m_window(window) {
10
12}
13
14void EditorCameraObject::processEvent(const SDL_Event& event, float deltaTime) {
15 if (event.type == SDL_EVENT_KEY_DOWN || event.type == SDL_EVENT_KEY_UP) {
16 bool isPressed = (event.type == SDL_EVENT_KEY_DOWN);
17 const SDL_KeyboardEvent& keyEvent = event.key;
18 keyStates[keyEvent.scancode] = isPressed;
19 }
20
21 if (event.type == SDL_EVENT_MOUSE_WHEEL && m_isFlying) {
22 if (event.wheel.y > 0) {
23 m_movementSpeed *= 1.2f;
24 } else if (event.wheel.y < 0) {
25 m_movementSpeed *= 0.8f;
26 }
27 }
28
29 if (event.type == SDL_EVENT_MOUSE_BUTTON_DOWN) {
30 if (event.button.button == SDL_BUTTON_RIGHT && m_viewportHovered) {
31 m_isFlying = true;
32 SDL_SetWindowRelativeMouseMode(m_window, true);
33 }
34 }
35
36 if (event.type == SDL_EVENT_MOUSE_BUTTON_UP) {
37 if (event.button.button == SDL_BUTTON_RIGHT) {
38 m_isFlying = false;
39 SDL_SetWindowRelativeMouseMode(m_window, false);
40 }
41 }
42
43 if (event.type == SDL_EVENT_MOUSE_MOTION && m_isFlying) {
45
46 float deltaYaw = -event.motion.xrel * m_mouseSensitivity;
47 float deltaPitch = -event.motion.yrel * m_mouseSensitivity;
48
49 tc.addYaw(deltaYaw);
50 tc.addPitch(deltaPitch);
51 }
52}
53
54void EditorCameraObject::Update(float deltaTime) {
56 bool isShiftHeld = keyStates[SDL_SCANCODE_LSHIFT] || keyStates[SDL_SCANCODE_RSHIFT];
57
58 if(isShiftHeld){
59 return;
60 }
61
62 if (keyStates[SDL_SCANCODE_W] && (m_viewportHovered || m_isFlying)) {
63 tc.setLocalPosition(tc.getLocalPosition()+(tc.getForwardVector()*float(deltaTime*m_movementSpeed)));
64 }
65
66 if (keyStates[SDL_SCANCODE_S] && (m_viewportHovered || m_isFlying)) {
67 tc.setLocalPosition(tc.getLocalPosition()+(tc.getForwardVector()*float(deltaTime*-m_movementSpeed)));
68 }
69
70 if (keyStates[SDL_SCANCODE_D] && (m_viewportHovered || m_isFlying)) {
71 tc.setLocalPosition(tc.getLocalPosition()+(tc.getRightVector()*float(deltaTime*m_movementSpeed)));
72 }
73
74 if (keyStates[SDL_SCANCODE_A] && (m_viewportHovered || m_isFlying)) {
75 tc.setLocalPosition(tc.getLocalPosition()+(tc.getRightVector()*float(deltaTime*-m_movementSpeed)));
76 }
77
78 if (keyStates[SDL_SCANCODE_E] && (m_viewportHovered || m_isFlying)) {
79 tc.setLocalPosition(tc.getLocalPosition() + (tc.getUpVector() * (deltaTime * m_movementSpeed)));
80 }
81
82 if (keyStates[SDL_SCANCODE_Q] && (m_viewportHovered || m_isFlying)) {
83 tc.setLocalPosition(tc.getLocalPosition() + (tc.getUpVector() * (deltaTime * -m_movementSpeed)));
84 }
85}
Contains basic components like transform, camera, name components..
A specialized camera object for use within the editor, supporting free-fly movement and input process...
EditorCameraObject(vex::Engine &engine, const std::string &name, SDL_Window *window)
Constructs an EditorCameraObject.
void processEvent(const SDL_Event &event, float deltaTime)
Processes SDL events specific to the editor camera (e.g., mouse movement, key presses).
void Update(float deltaTime) override
Overrides the base GameObject Update for continuous camera movement and logic.
Class for interaction with engine systems.
Definition Engine.hpp:47
T & GetComponent()
Function that returns reference to a requested component.
void AddComponent(const T &comp)
Function that adds a component to the GameObject.
Tag for entities that should persist across scene changes. Like editor camera.