Commit 71a6dbb9 authored by Dario Seyb's avatar Dario Seyb

rendering something to the console

parent c3c61b2d
......@@ -23,6 +23,7 @@ public:
void stop();
void pause();
void play();
void setVolume(float vol);
PlaybackState getState() { return m_state; }
......@@ -30,4 +31,5 @@ private:
PlaybackState m_state;
std::shared_ptr<Sound> m_sound;
FMOD::Channel *m_channel;
float m_volume = 1;
};
\ No newline at end of file
......@@ -3,12 +3,16 @@
#include <engine/scene/OrbitalSimulationSystem.hpp>
#include <engine/scene/PlayerSystem.hpp>
#include <engine/audio/SoundSource.hpp>
#include <engine/scene/scenes/Console.hpp>
class AtmosphereTestScene : public Scene {
private:
OrbitalSimulationSystem* m_orbitals;
PlayerSystem* m_player;
Console m_console;
Light::Handle sunLight;
Entity sun;
Entity skybox;
......@@ -19,6 +23,7 @@ private:
Light::Handle cockpitSunLight;
Entity consoleCamera;
SoundSource::Handle consoleSoundSource;
Material cockpitMaterial, sunMaterial, skyboxMaterial;
Geometry cockpitGeometry, sunGeometry, skyboxGeometry;
......
#include <engine/scene/Scene.hpp>
class Console {
private:
Entity cube;
public:
EventSystem* m_events;
RendererSystem* m_renderer;
SceneGraphSystem* m_sceneGraph;
AudioSystem* m_audio;
void startup();
void update(const SimulateEvent& e);
void pause();
void play();
};
\ No newline at end of file
......@@ -24,5 +24,13 @@ void SoundSource::play() {
} else if(!m_channel) {
m_channel = m_sound->play();
}
m_channel->setVolume(m_volume);
m_state = PlaybackState::PLAYING;
}
void SoundSource::setVolume(float vol) {
m_volume = vol;
if (m_channel) {
m_channel->setVolume(vol);
}
}
\ No newline at end of file
......@@ -44,9 +44,17 @@ bool AtmosphereTestScene::startup() {
m_renderer->addRenderPass(consoleCamera, "Console"_sh);
m_renderer->setRenderPassOnlyTexture("Console"_sh, true);
m_console.m_events = m_events;
m_console.m_renderer = m_renderer;
m_console.m_sceneGraph = m_sceneGraph;
m_console.m_audio = m_audio;
m_console.startup();
loadMainSceneResources();
switchToMainScene();
mainSceneRunning = true;
SDL_SetRelativeMouseMode(SDL_TRUE);
m_player->setHasControl(false);
......@@ -54,11 +62,11 @@ bool AtmosphereTestScene::startup() {
m_player->setRotation(CAM_CONSOLE_ROT);
m_events->subscribe<SimulateEvent>([this](const SimulateEvent &e) {
if (mainSceneRunning) {
sunLight->dir = -glm::normalize(m_player->getWorldPosition());
cockpitSunLight->dir =
glm::vec3(glm::dvec4(sunLight->dir, 0) * m_player->getRotation());
}
sunLight->dir = -glm::normalize(m_player->getWorldPosition());
cockpitSunLight->dir =
glm::vec3(glm::dvec4(sunLight->dir, 0) * m_player->getRotation());
m_console.update(e);
if (isInterpolatingCamera) {
double interpolationPercent = 1.0 - glm::pow(1 - interpolationTime / totalInterpolationTime, 2);
......@@ -66,6 +74,8 @@ bool AtmosphereTestScene::startup() {
interpolationPercent = 1.0 - glm::pow(1 - interpolationTime / totalInterpolationTime, 5);
consoleSoundSource->setVolume(1.0f - interpolationTime / totalInterpolationTime);
glm::quat rot = glm::slerp(camStartRot, camTargetRot, (float)interpolationPercent);
m_player->setRotation(glm::mat4_cast(rot));
interpolationTime += e.dt;
......@@ -74,6 +84,7 @@ bool AtmosphereTestScene::startup() {
m_player->setRotation(glm::mat4_cast(camTargetRot));
isInterpolatingCamera = false;
m_player->setHasControl(true);
consoleSoundSource->setVolume(0);
}
}
});
......@@ -98,11 +109,15 @@ bool AtmosphereTestScene::startup() {
camTargetPos = { 0, 0 , 0 };
camStartRot = glm::quat_cast(m_player->getRotation());
camTargetRot = glm::quat();
m_console.pause();
} else {
// TODO: Fix returning to console!
break;
camStartPos = m_player->getCockpitPosition();
camTargetPos = CAM_CONSOLE_POS;
camStartRot = glm::quat_cast(m_player->getRotation());
camTargetRot = glm::quat_cast(CAM_CONSOLE_ROT);
m_console.play();
}
isFocusedOnConsole = !isFocusedOnConsole;
......@@ -119,9 +134,6 @@ bool AtmosphereTestScene::startup() {
// Subscribe to the UI drawing event.
// This is called once per frame
m_events->subscribe<"DrawUI"_sh>([this]() {
if (!mainSceneRunning) {
return;
}
ImGui::Begin("Camera Control", 0,
ImGuiWindowFlags_::ImGuiWindowFlags_AlwaysAutoResize);
......@@ -226,6 +238,10 @@ void AtmosphereTestScene::switchToMainScene() {
skyboxMaterial.prog, false, RenderQueue::OPAQUE, GL_BACK},
0, cockpitPassId);
console.assign<Transform>();
auto soundTrack = m_audio->createSound("chipzel - Spectra - 01 Spectra.mp3", SoundMode::MODE_2D);
consoleSoundSource = console.assign<SoundSource>(soundTrack);
consoleSoundSource->play();
}
}
......
#include <engine/scene/scenes/Console.hpp>
#include <ACGL/ACGL.hh>
#include <ACGL/OpenGL/Objects.hh>
#include <ACGL/Base/Settings.hh>
#include <ACGL/Math/Math.hh>
#include <ACGL/OpenGL/Data/TextureLoadStore.hh>
#include <ACGL/OpenGL/Managers.hh>
#include <ACGL/OpenGL/Creator/ShaderProgramCreator.hh>
#include <ACGL/OpenGL/Creator/VertexArrayObjectCreator.hh>
#include <ACGL/OpenGL/Creator/Texture2DCreator.hh>
#include <engine/scene/Transform.hpp>
#include <engine/scene/Drawable.hpp>
#include <engine/scene/Planet.hpp>
#include <engine/events/MouseEvent.hpp>
#include <engine/events/KeyboardEvent.hpp>
#include <engine/graphics/BloomPostFX.hpp>
void Console::startup() {
auto consolePassId = m_renderer->getRenderPassId("Console"_sh);
auto cubeTexture =
Texture2DFileManager::the()->get(Texture2DCreator("checkerboard.png"));
auto cubeGeom = Geometry{ VertexArrayObjectCreator("cube.obj").create() };
cubeGeom.vao->setMode(GL_PATCHES);
auto cubeShader =
ShaderProgramCreator("PBR")
.attributeLocations(cubeGeom.vao->getAttributeLocations())
.fragmentDataLocations(m_renderer->getGBufferLocations())
.create();
auto cube = m_sceneGraph->create();
cube.assign<Drawable>(cubeGeom,
Material{glm::vec4{1, 1, 1, 1}, glm::vec4{1, 1, 1, 1},
cubeTexture, nullptr, nullptr, cubeShader,
false, RenderQueue::OPAQUE, GL_BACK},
0, consolePassId);
cube.assign<Transform>()->position = { 0, 0, -5 };
cube.assign<Light>(glm::vec4(0, 0.2, 1.0, 5), glm::vec3(1, 0, 0),
false, LightType::POINT, consolePassId);
}
void Console::update(const SimulateEvent &e) {
}
void Console::pause() {}
void Console::play() {}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment