Skip to content

Commit

Permalink
Merge pull request #18 from KTStephano/v0.8
Browse files Browse the repository at this point in the history
V0.8 -> Master
  • Loading branch information
KTStephano authored Feb 15, 2023
2 parents 9344cc5 + 2f5e6b6 commit 3cca1c1
Show file tree
Hide file tree
Showing 103 changed files with 6,608 additions and 3,737 deletions.
3 changes: 3 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@
*.bin filter=lfs diff=lfs merge=lfs -text
*.gltf filter=lfs diff=lfs merge=lfs -text
*.jpeg filter=lfs diff=lfs merge=lfs -text
resources/textures/*.jpg filter=lfs diff=lfs merge=lfs -text
resources/textures/*.png filter=lfs diff=lfs merge=lfs -text
resources/textures/*.jpeg filter=lfs diff=lfs merge=lfs -text
6 changes: 4 additions & 2 deletions Examples/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
include_directories(${CMAKE_CURRENT_LIST_DIR}/Common)
file(GLOB COMMON_SOURCES ${CMAKE_CURRENT_LIST_DIR}/Common/*.cpp)

add_subdirectory(ExampleEnv00)
add_subdirectory(ExampleEnv01)
add_subdirectory(ExampleEnv02)
add_subdirectory(ExampleEnv03)
add_subdirectory(ExampleEnv04)
add_subdirectory(ExampleEnv03)
117 changes: 117 additions & 0 deletions Examples/Common/CameraController.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
#pragma once

#include "StratusCommon.h"
#include "glm/glm.hpp"
#include "StratusWindow.h"
#include "StratusRendererFrontend.h"
#include "StratusLog.h"
#include "StratusCamera.h"
#include "StratusLight.h"

struct CameraController : public stratus::InputHandler {
CameraController() {
_camera = stratus::CameraPtr(new stratus::Camera());
stratus::RendererFrontend::Instance()->SetCamera(_camera);

_cameraLight = stratus::LightPtr(new stratus::PointLight(/* staticLight = */ false));
_cameraLight->setCastsShadows(false);
_cameraLight->setIntensity(600.0f);

if (_cameraLightEnabled) {
stratus::RendererFrontend::Instance()->AddLight(_cameraLight);
}
}

// This class is deleted when the Window is deleted so the Renderer has likely already
// been taken offline. The check is for if the camera controller is removed while the engine
// is still running.
virtual ~CameraController() {
INSTANCE(RendererFrontend)->SetCamera(nullptr);

if (_cameraLightEnabled) {
INSTANCE(RendererFrontend)->RemoveLight(_cameraLight);
}
}

void HandleInput(const stratus::MouseState& mouse, const std::vector<SDL_Event>& input, const double deltaSeconds) {
const float camSpeed = 100.0f;

// Handle WASD movement
for (auto e : input) {
switch (e.type) {
case SDL_MOUSEMOTION:
_camera->modifyAngle(stratus::Degrees(0.0f), stratus::Degrees(-e.motion.xrel), stratus::Degrees(0.0f));
//STRATUS_LOG << camera.getRotation() << std::endl;
break;
case SDL_KEYDOWN:
case SDL_KEYUP: {
bool released = e.type == SDL_KEYUP;
SDL_Scancode key = e.key.keysym.scancode;
switch (key) {
case SDL_SCANCODE_SPACE:
if (!released) {
_camSpeedDivide = 1.0f;
}
else {
_camSpeedDivide = 0.25f;
}
break;
case SDL_SCANCODE_W:
case SDL_SCANCODE_S:
if (!released) {
_cameraSpeed.x = key == SDL_SCANCODE_W ? camSpeed : -camSpeed;
} else {
_cameraSpeed.x = 0.0f;
}
break;
case SDL_SCANCODE_A:
case SDL_SCANCODE_D:
if (!released) {
_cameraSpeed.y = key == SDL_SCANCODE_D ? camSpeed : -camSpeed;
} else {
_cameraSpeed.y = 0.0f;
}
break;
// Adds or removes the light following the camera
case SDL_SCANCODE_F:
if (released) {
_cameraLightEnabled = !_cameraLightEnabled;

if (_cameraLightEnabled) {
stratus::RendererFrontend::Instance()->AddLight(_cameraLight);
}
else {
stratus::RendererFrontend::Instance()->RemoveLight(_cameraLight);
}
}

break;
}
}
}
}

// Check mouse state for move up/down
uint32_t buttonState = mouse.mask;
_cameraSpeed.z = 0.0f;
if ((buttonState & SDL_BUTTON_LMASK) != 0) { // left mouse button
_cameraSpeed.z = -camSpeed;
}
else if ((buttonState & SDL_BUTTON_RMASK) != 0) { // right mouse button
_cameraSpeed.z = camSpeed;
}

// Final camera speed update
glm::vec3 tmpCamSpeed = _cameraSpeed * _camSpeedDivide;
_camera->setSpeed(tmpCamSpeed.y, tmpCamSpeed.z, tmpCamSpeed.x);

_cameraLight->SetPosition(_camera->getPosition());
}

private:
stratus::CameraPtr _camera;
stratus::LightPtr _cameraLight;
bool _cameraLightEnabled = true;
glm::vec3 _cameraSpeed = glm::vec3(0.0f);
float _camSpeedDivide = 0.25f; // For slowing camera down
};
46 changes: 46 additions & 0 deletions Examples/Common/LightComponents.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#pragma once

#include "StratusCommon.h"
#include "glm/glm.hpp"
#include "StratusWindow.h"
#include "StratusRendererFrontend.h"
#include "StratusLog.h"
#include "StratusCamera.h"
#include "StratusLight.h"
#include "StratusEngine.h"
#include "StratusResourceManager.h"
#include "StratusMaterial.h"
#include "StratusUtils.h"
#include "StratusEntityManager.h"
#include "StratusEntityCommon.h"
#include "StratusEntity.h"

ENTITY_COMPONENT_STRUCT(LightComponent)
stratus::LightPtr light;
LightComponent(stratus::LightPtr light)
: light(light) {}

LightComponent(const LightComponent& other) {
light = other.light->Copy();
}
};

ENTITY_COMPONENT_STRUCT(LightCubeComponent)
stratus::EntityPtr cube;
LightCubeComponent(stratus::EntityPtr cube)
: cube(cube) {}

LightCubeComponent(const LightCubeComponent& other) {
cube = other.cube->Copy();
}
};

ENTITY_COMPONENT_STRUCT(RandomLightMoverComponent)
glm::vec3 position = glm::vec3(0.0f);
glm::vec3 direction = glm::vec3(0.0f);
double elapsedSeconds = 0.0;

RandomLightMoverComponent() {}
RandomLightMoverComponent(const RandomLightMoverComponent&) = default;
};

Loading

0 comments on commit 3cca1c1

Please sign in to comment.