mirror of
https://github.com/antopilo/Nuake.git
synced 2026-02-25 14:32:55 +03:00
Fixed gizmo not working properly
This commit is contained in:
@@ -90,20 +90,20 @@ void ViewportWidget::Draw()
|
||||
{
|
||||
TransformComponent& tc = selection.Entity.GetComponent<TransformComponent>();
|
||||
Matrix4 transform = tc.GetGlobalTransform();
|
||||
const auto& editorCam = Engine::GetCurrentScene()->GetCurrentCamera();
|
||||
const auto& editorCam = editorContext.GetScene()->GetCurrentCamera();
|
||||
Matrix4 cameraView = editorCam->GetTransform();
|
||||
|
||||
// Since imguizmo doesnt support reverse-Z, we need to create a new projection matrix
|
||||
// With a normal near and far plane.
|
||||
Matrix4 normalZProjection = glm::perspectiveFov(glm::radians(editorCam->Fov), 9.0f * editorCam->AspectRatio, 9.0f, editorCam->Far, editorCam->Near);
|
||||
|
||||
static Vector3 camPreviousPos = Engine::GetCurrentScene()->m_EditorCamera->Translation;
|
||||
static Vector3 camPreviousPos = editorContext.GetScene()->m_EditorCamera->Translation;
|
||||
static Vector3 camNewPos = Vector3(0, 0, 0);
|
||||
Vector3 camDelta = camNewPos - camPreviousPos;
|
||||
Vector3 previousGlobalPos = transform[3];
|
||||
// Imguizmo calculates the delta from the gizmo,
|
||||
ImGuizmo::Manipulate(
|
||||
glm::value_ptr(Engine::GetCurrentScene()->GetCurrentCamera()->GetTransform()),
|
||||
glm::value_ptr(editorContext.GetScene()->GetCurrentCamera()->GetTransform()),
|
||||
glm::value_ptr(normalZProjection),
|
||||
CurrentOperation, CurrentMode,
|
||||
glm::value_ptr(transform), NULL,
|
||||
@@ -121,8 +121,8 @@ void ViewportWidget::Draw()
|
||||
if (ImGui::IsKeyDown(ImGuiKey_LeftShift))
|
||||
{
|
||||
Vector3 positionDelta = newGlobalPos - previousGlobalPos;
|
||||
Engine::GetCurrentScene()->m_EditorCamera->Translation += positionDelta;
|
||||
camNewPos = Engine::GetCurrentScene()->m_EditorCamera->Translation;
|
||||
editorContext.GetScene()->m_EditorCamera->Translation += positionDelta;
|
||||
camNewPos = editorContext.GetScene()->m_EditorCamera->Translation;
|
||||
}
|
||||
|
||||
ParentComponent& parent = selection.Entity.GetComponent<ParentComponent>();
|
||||
|
||||
17
Nuake/Source/Nuake/Modules/AudioModule/AudioModule.cpp
Normal file
17
Nuake/Source/Nuake/Modules/AudioModule/AudioModule.cpp
Normal file
@@ -0,0 +1,17 @@
|
||||
#include "AudioModule.h"
|
||||
|
||||
#include "Nuake/Scene/SceneSystems.h"
|
||||
|
||||
#include "AudioSceneSystem.h"
|
||||
|
||||
void AudioModule_Startup()
|
||||
{
|
||||
using namespace Nuake;
|
||||
|
||||
SceneSystemDB::Get().RegisterSceneSystem<AudioModule::AudioSystem>();
|
||||
}
|
||||
|
||||
void AudioModule_Shutdown()
|
||||
{
|
||||
|
||||
}
|
||||
4
Nuake/Source/Nuake/Modules/AudioModule/AudioModule.h
Normal file
4
Nuake/Source/Nuake/Modules/AudioModule/AudioModule.h
Normal file
@@ -0,0 +1,4 @@
|
||||
#pragma once
|
||||
|
||||
void AudioModule_Startup();
|
||||
void AudioModule_Shutdown();
|
||||
115
Nuake/Source/Nuake/Modules/AudioModule/AudioSceneSystem.cpp
Normal file
115
Nuake/Source/Nuake/Modules/AudioModule/AudioSceneSystem.cpp
Normal file
@@ -0,0 +1,115 @@
|
||||
#include "AudioSceneSystem.h"
|
||||
|
||||
#include "Engine.h"
|
||||
#include "Nuake/Scene/Scene.h"
|
||||
#include "Nuake/Scene/Entities/Entity.h"
|
||||
#include "Nuake/Scene/Components/AudioEmitterComponent.h"
|
||||
#include "Nuake/FileSystem/File.h"
|
||||
#include "Nuake/Audio/AudioManager.h"
|
||||
|
||||
#include <future>
|
||||
|
||||
namespace AudioModule
|
||||
{
|
||||
using namespace Nuake;
|
||||
|
||||
AudioSystem::AudioSystem(Scene* scene)
|
||||
{
|
||||
m_Scene = scene;
|
||||
}
|
||||
|
||||
bool AudioSystem::Init()
|
||||
{
|
||||
AudioManager::Get().StopAll();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void AudioSystem::Update(Timestep ts)
|
||||
{
|
||||
auto& audioManager = AudioManager::Get();
|
||||
|
||||
// Update 3D listener of the audio system
|
||||
auto currentCamera = m_Scene->GetCurrentCamera();
|
||||
|
||||
Vector3 direction = currentCamera->GetDirection();
|
||||
Vector3 position = currentCamera->GetTranslation();
|
||||
if (!Engine::IsPlayMode())
|
||||
{
|
||||
direction.x *= -1.0f;
|
||||
direction.z *= -1.0f;
|
||||
}
|
||||
|
||||
audioManager.SetListenerPosition(position, std::move(direction), currentCamera->GetUp());
|
||||
|
||||
auto view = m_Scene->m_Registry.view<TransformComponent, AudioEmitterComponent>();
|
||||
for (auto& e : view)
|
||||
{
|
||||
auto [transformComponent, audioEmitterComponent] = view.get<TransformComponent, AudioEmitterComponent>(e);
|
||||
|
||||
if (audioEmitterComponent.FilePath.file == nullptr || !audioEmitterComponent.FilePath.file->Exist())
|
||||
{
|
||||
// Doesn't have a file
|
||||
continue;
|
||||
}
|
||||
|
||||
const bool isPlaying = audioEmitterComponent.IsPlaying;
|
||||
const std::string absoluteFilePath = audioEmitterComponent.FilePath.file->GetAbsolutePath();
|
||||
const bool isVoiceActive = audioManager.IsVoiceActive(absoluteFilePath);
|
||||
|
||||
AudioRequest audioRequest;
|
||||
audioRequest.audioFile = absoluteFilePath;
|
||||
audioRequest.pan = audioEmitterComponent.Pan;
|
||||
audioRequest.volume = audioEmitterComponent.Volume;
|
||||
audioRequest.speed = audioEmitterComponent.PlaybackSpeed;
|
||||
audioRequest.spatialized = audioEmitterComponent.Spatialized;
|
||||
audioRequest.Loop = audioEmitterComponent.Loop;
|
||||
audioRequest.position = transformComponent.GetGlobalTransform()[3];
|
||||
audioRequest.MinDistance = audioEmitterComponent.MinDistance;
|
||||
audioRequest.MaxDistance = audioEmitterComponent.MaxDistance;
|
||||
audioRequest.AttenuationFactor = audioEmitterComponent.AttenuationFactor;
|
||||
|
||||
if (isVoiceActive)
|
||||
{
|
||||
if (!isPlaying && audioEmitterComponent.Loop)
|
||||
{
|
||||
audioManager.StopVoice(absoluteFilePath); // Stop audio
|
||||
}
|
||||
else
|
||||
{
|
||||
// Update the active voice with new params
|
||||
audioManager.UpdateVoice(audioRequest);
|
||||
}
|
||||
}
|
||||
|
||||
if (isPlaying)
|
||||
{
|
||||
// Reset the play status to false since the audio has been fired
|
||||
if (!audioEmitterComponent.Loop)
|
||||
{
|
||||
audioManager.QueueWavAudio(std::move(audioRequest));
|
||||
audioEmitterComponent.IsPlaying = false;
|
||||
}
|
||||
else if (!isVoiceActive)
|
||||
{
|
||||
audioManager.QueueWavAudio(std::move(audioRequest));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void AudioSystem::FixedUpdate(Timestep ts)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void AudioSystem::EditorUpdate()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void AudioSystem::Exit()
|
||||
{
|
||||
AudioManager::Get().StopAll();
|
||||
}
|
||||
}
|
||||
22
Nuake/Source/Nuake/Modules/AudioModule/AudioSceneSystem.h
Normal file
22
Nuake/Source/Nuake/Modules/AudioModule/AudioSceneSystem.h
Normal file
@@ -0,0 +1,22 @@
|
||||
#pragma once
|
||||
#include "Nuake/Scene/Systems/System.h"
|
||||
|
||||
namespace AudioModule
|
||||
{
|
||||
using namespace Nuake;
|
||||
|
||||
class AudioSystem : public System
|
||||
{
|
||||
private:
|
||||
std::unordered_map<uint32_t, bool> m_StatusCache;
|
||||
|
||||
public:
|
||||
AudioSystem(Scene* scene);
|
||||
bool Init() override;
|
||||
void Update(Timestep ts) override;
|
||||
void Draw() override {}
|
||||
void EditorUpdate() override;
|
||||
void FixedUpdate(Timestep ts) override;
|
||||
void Exit() override;
|
||||
};
|
||||
}
|
||||
9
Nuake/Source/Nuake/Modules/AudioModule/Module.lua
Normal file
9
Nuake/Source/Nuake/Modules/AudioModule/Module.lua
Normal file
@@ -0,0 +1,9 @@
|
||||
return {
|
||||
name = "Audio Module",
|
||||
description = "This the base audio module",
|
||||
module_header = "AudioModule.h",
|
||||
-- Place all your sources here
|
||||
sources = {
|
||||
"AudioModule.cpp"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user