When changing camera listener is updated. Also fixed some crashes in RenderSystem when there were no cameras available.
This commit is contained in:
@@ -39,11 +39,17 @@ void RenderSystem::switchCamera(EntityID entity)
|
|||||||
if (m_World->HasComponent(m_CurrentCamera, "Model")) {
|
if (m_World->HasComponent(m_CurrentCamera, "Model")) {
|
||||||
m_World->GetComponent(m_CurrentCamera, "Model")["Visible"] = true;
|
m_World->GetComponent(m_CurrentCamera, "Model")["Visible"] = true;
|
||||||
}
|
}
|
||||||
|
if (m_World->HasComponent(m_CurrentCamera, "Listener")) {
|
||||||
|
m_World->DeleteComponent(m_CurrentCamera, "Listener");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_World->HasComponent(entity, "Model")) {
|
if (m_World->HasComponent(entity, "Model")) {
|
||||||
m_World->GetComponent(entity, "Model")["Visible"] = false;
|
m_World->GetComponent(entity, "Model")["Visible"] = false;
|
||||||
}
|
}
|
||||||
|
if (!m_World->HasComponent(entity, "Listener")) {
|
||||||
|
m_World->AttachComponent(entity, "Listener");
|
||||||
|
}
|
||||||
m_CurrentCamera = entity;
|
m_CurrentCamera = entity;
|
||||||
m_SwitchCamera = false;
|
m_SwitchCamera = false;
|
||||||
|
|
||||||
@@ -130,6 +136,9 @@ void RenderSystem::updateCamera(World* world, double dt)
|
|||||||
{
|
{
|
||||||
if (m_SwitchCamera) {
|
if (m_SwitchCamera) {
|
||||||
auto cameras = world->GetComponents("Camera");
|
auto cameras = world->GetComponents("Camera");
|
||||||
|
if (cameras == nullptr) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
for (auto it = cameras->begin(); it != cameras->end(); it++) {
|
for (auto it = cameras->begin(); it != cameras->end(); it++) {
|
||||||
if ((*it).EntityID == m_CurrentCamera) {
|
if ((*it).EntityID == m_CurrentCamera) {
|
||||||
it++;
|
it++;
|
||||||
@@ -141,11 +150,13 @@ void RenderSystem::updateCamera(World* world, double dt)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ComponentWrapper& cameraComponent = world->GetComponent(m_CurrentCamera, "Camera");
|
if (m_World->HasComponent(m_CurrentCamera, "Camera")) {
|
||||||
ComponentWrapper& cameraTransform = world->GetComponent(m_CurrentCamera, "Transform");
|
ComponentWrapper& cameraComponent = world->GetComponent(m_CurrentCamera, "Camera");
|
||||||
|
ComponentWrapper& cameraTransform = world->GetComponent(m_CurrentCamera, "Transform");
|
||||||
|
|
||||||
m_DebugCameraInputController->SetOrientation(glm::quat((glm::vec3)cameraTransform["Orientation"]));
|
m_DebugCameraInputController->SetOrientation(glm::quat((glm::vec3)cameraTransform["Orientation"]));
|
||||||
m_DebugCameraInputController->SetPosition(cameraTransform["Position"]);
|
m_DebugCameraInputController->SetPosition(cameraTransform["Position"]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_World->ValidEntity(m_CurrentCamera)) {
|
if (m_World->ValidEntity(m_CurrentCamera)) {
|
||||||
|
|||||||
@@ -135,6 +135,7 @@ void SoundSystem::updateEmitters()
|
|||||||
|
|
||||||
void SoundSystem::updateListener()
|
void SoundSystem::updateListener()
|
||||||
{
|
{
|
||||||
|
int testremove = 0;
|
||||||
// Should only be one listener.
|
// Should only be one listener.
|
||||||
auto listenerComponents = m_World->GetComponents("Listener");
|
auto listenerComponents = m_World->GetComponents("Listener");
|
||||||
if (listenerComponents == nullptr) {
|
if (listenerComponents == nullptr) {
|
||||||
@@ -147,8 +148,12 @@ void SoundSystem::updateListener()
|
|||||||
glm::vec3 nextPos = Transform::AbsolutePosition(m_World, listener); // Get next (current) pos
|
glm::vec3 nextPos = Transform::AbsolutePosition(m_World, listener); // Get next (current) pos
|
||||||
glm::vec3 velocity = nextPos - previousPos; // Calculate velocity
|
glm::vec3 velocity = nextPos - previousPos; // Calculate velocity
|
||||||
setListenerPos(nextPos);
|
setListenerPos(nextPos);
|
||||||
setListenerVel(velocity);
|
//setListenerVel(velocity);
|
||||||
setListenerOri(glm::eulerAngles(Transform::AbsoluteOrientation(m_World, listener)));
|
setListenerOri(glm::eulerAngles(Transform::AbsoluteOrientation(m_World, listener)));
|
||||||
|
testremove++;
|
||||||
|
}
|
||||||
|
if (testremove > 1) {
|
||||||
|
testremove = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user