VEX Engine
Retro looking game engine made in vulkan mostly because i wanted to understand it better.
Loading...
Searching...
No Matches
BasicCamera.cpp
1#include "BasicCamera.hpp"
4
5namespace vex {
6
7 BasicCamera::BasicCamera(Engine& engine, const std::string& name) : GameObject(engine, name) {
8 AddComponent(TransformComponent{});
9 AddComponent(CameraComponent{});
10 }
11
13 // basic movement
14
15 InputComponent inputComp;
16 inputComp.addBinding(SDL_SCANCODE_W, InputActionState::Held, [this](float deltaTime) {
17 GetComponent<TransformComponent>().addLocalPosition(GetComponent<TransformComponent>().getForwardVector() * (deltaTime * 2));
18 });
19 inputComp.addBinding(SDL_SCANCODE_S, InputActionState::Held, [this](float deltaTime) {
20 GetComponent<TransformComponent>().addLocalPosition(GetComponent<TransformComponent>().getForwardVector() * -(deltaTime * 2));
21 });
22 inputComp.addBinding(SDL_SCANCODE_D, InputActionState::Held, [this](float deltaTime) {
23 GetComponent<TransformComponent>().addLocalPosition(GetComponent<TransformComponent>().getRightVector() * (deltaTime * 2));
24 });
25 inputComp.addBinding(SDL_SCANCODE_A, InputActionState::Held, [this](float deltaTime) {
26 GetComponent<TransformComponent>().addLocalPosition(GetComponent<TransformComponent>().getRightVector() * -(deltaTime * 2));
27 });
28
29 inputComp.addMouseAxisBinding(MouseAxis::X, [this](float axis) {
30 GetComponent<TransformComponent>().addYaw(-axis * 0.05);
31 });
32 inputComp.addMouseAxisBinding(MouseAxis::Y, [this](float axis) {
33 GetComponent<TransformComponent>().addPitch(-axis * 0.05);
34 });
35
36 AddComponent(inputComp);
37 }
38
39 void BasicCamera::Update(float deltaTime) {
40 // update
41 }
42
44}
Contains basic components like transform, camera, name components..
This file defines GameObjectFactory class used to auto register GameObjects.
#define REGISTER_GAME_OBJECT(ClassName)
Macro for automatic GameObject registration, you should call it at the bottom of your class implement...
void Update(float deltaTime) override
virtual void function you override to implement custom behavior when the game updates (eg....
void BeginPlay() override
virtual void function you override to implement custom behavior when the game starts.
Class for interaction with engine systems.
Definition Engine.hpp:47
Its base class for all game objects, eg. Player, Enemy, Weapon. Your Class needs to inherit from it.
T & GetComponent()
Function that returns reference to a requested component.
void AddComponent(const T &comp)
Function that adds a component to the GameObject.
Component you add to your GameObject to handle input, eg. add input bindings and mouse axis bindings.
void addBinding(SDL_Scancode scancode, InputActionState state, std::function< void(float)> action)
Adds input binding.
void addMouseAxisBinding(MouseAxis axis, std::function< void(float)> action)
Adds axis binding.