-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from KTStephano/v0.8
V0.8 -> Master
- Loading branch information
Showing
103 changed files
with
6,608 additions
and
3,737 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}; | ||
|
Oops, something went wrong.