diff --git a/data/Scenes/Aiguelongue.scene b/data/Scenes/Aiguelongue.scene index 11c8fff40..326965ba6 100644 --- a/data/Scenes/Aiguelongue.scene +++ b/data/Scenes/Aiguelongue.scene @@ -19,14 +19,27 @@ - + - + + + + + + + + + + + + + + - + @@ -56,17 +69,17 @@ - + - + - + @@ -98,7 +111,7 @@ - + @@ -134,36 +147,36 @@ - - + + - + - + - + - + - + - + @@ -477,7 +490,7 @@ - + @@ -555,7 +568,7 @@ - + @@ -626,7 +639,7 @@ - + @@ -636,7 +649,7 @@ - + @@ -1121,27 +1134,6 @@ - - - - - - - - - - - - - - - - - - - - - @@ -1604,6 +1596,27 @@ + + + + + + + + + + + + + + + + + + + + + @@ -1960,7 +1973,7 @@ - + @@ -2268,7 +2281,7 @@ - + @@ -2278,7 +2291,7 @@ - + @@ -2689,7 +2702,7 @@ - + @@ -2798,7 +2811,7 @@ - + @@ -2825,7 +2838,17 @@ - + + + + + + + + + + + diff --git a/projects/game/src/Behaviour/Camera/GameCameraBehaviour.h b/projects/game/src/Behaviour/Camera/GameCameraBehaviour.h index 717ee1226..ecb65fb31 100644 --- a/projects/game/src/Behaviour/Camera/GameCameraBehaviour.h +++ b/projects/game/src/Behaviour/Camera/GameCameraBehaviour.h @@ -10,14 +10,16 @@ class GameCameraBehaviour : public vg::core::Behaviour GameCameraBehaviour(const vg::core::string & _name, vg::core::IObject * _parent); ~GameCameraBehaviour(); - void OnPlay () final override; + void OnEnable () final override; void Update (const Context & _context) override; + void setTarget (const vg::core::IGameObject * _target); + private: vg::core::ObjectHandle m_target; float m_delay = 0.1f; - vg::core::float3 m_offset = (vg::core::float3)0.0f; - vg::core::float3 m_targetPosition = (vg::core::float3)0.0f; + vg::core::float3 m_offset = vg::core::float3(0.0f, -9.0f, 14.0f); + vg::core::float3 m_targetPosition = (vg::core::float3)0.0f; vg::core::float3 m_targetVelocity = (vg::core::float3)0.0f; }; diff --git a/projects/game/src/Behaviour/Camera/GameCameraBehaviour.cpp b/projects/game/src/Behaviour/Camera/GameCameraBehaviour.hpp similarity index 77% rename from projects/game/src/Behaviour/Camera/GameCameraBehaviour.cpp rename to projects/game/src/Behaviour/Camera/GameCameraBehaviour.hpp index 42fa2f766..37abe4747 100644 --- a/projects/game/src/Behaviour/Camera/GameCameraBehaviour.cpp +++ b/projects/game/src/Behaviour/Camera/GameCameraBehaviour.hpp @@ -1,4 +1,3 @@ -#include "Precomp.h" #include "GameCameraBehaviour.h" #include "Game.h" #include "core/GameObject/GameObject.h" @@ -31,6 +30,9 @@ bool GameCameraBehaviour::registerProperties(IClassDesc & _desc) registerProperty(GameCameraBehaviour, m_target, "Target"); setPropertyDescription(GameCameraBehaviour, m_target, "Camera target"); + registerProperty(GameCameraBehaviour, m_offset, "Offset"); + setPropertyDescription(GameCameraBehaviour, m_offset, "Camera offset"); + registerProperty(GameCameraBehaviour, m_delay, "Delay"); setPropertyDescription(GameCameraBehaviour, m_delay, "Time to smooth camera position (s)"); @@ -38,17 +40,23 @@ bool GameCameraBehaviour::registerProperties(IClassDesc & _desc) } //-------------------------------------------------------------------------------------- -void GameCameraBehaviour::OnPlay() +void GameCameraBehaviour::setTarget(const IGameObject * _target) { - super::OnPlay(); - m_offset = getGameObject()->getGlobalMatrix()[3].xyz; + m_target.setUID(_target->GetUID()); +} - auto * target = m_target.get(); - if (target) - { - if (auto * player = target->GetComponentInChildrenT()) - m_offset -= player->getGameObject()->GetGlobalMatrix()[3].xyz; - } +//-------------------------------------------------------------------------------------- +void GameCameraBehaviour::OnEnable() +{ + super::OnEnable(); + //m_offset = getGameObject()->getGlobalMatrix()[3].xyz; + // + //auto * target = m_target.get(); + //if (target) + //{ + // if (auto * player = target->GetComponentInChildrenT()) + // m_offset -= player->getGameObject()->GetGlobalMatrix()[3].xyz; + //} } //-------------------------------------------------------------------------------------- diff --git a/projects/game/src/Behaviour/Camera/GameCameraManagerBehaviour.cpp b/projects/game/src/Behaviour/Camera/GameCameraManagerBehaviour.cpp new file mode 100644 index 000000000..e33b05ac8 --- /dev/null +++ b/projects/game/src/Behaviour/Camera/GameCameraManagerBehaviour.cpp @@ -0,0 +1,239 @@ +#include "Precomp.h" +#include "GameCameraManagerBehaviour.h" +#include "editor/Editor_Consts.h" +#include "engine/ICameraComponent.h" +#include "GameCameraBehaviour.hpp" + +using namespace vg::core; +using namespace vg::engine; + +VG_REGISTER_COMPONENT_CLASS(GameCameraManagerBehaviour, "Game Camera Manager", "Game", "Camera Manager for Game cameras", vg::editor::style::icon::Script, 0); + +//-------------------------------------------------------------------------------------- +GameCameraManagerBehaviour::GameCameraManagerBehaviour(const string & _name, IObject * _parent) : + super(_name, _parent) +{ + SetUpdateFlags(UpdateFlags::Update); +} + +//-------------------------------------------------------------------------------------- +GameCameraManagerBehaviour::~GameCameraManagerBehaviour() +{ + +} + +//-------------------------------------------------------------------------------------- +bool GameCameraManagerBehaviour::registerProperties(IClassDesc & _desc) +{ + super::registerProperties(_desc); + + registerProperty(GameCameraManagerBehaviour, m_player1Camera, "Camera 1"); + registerProperty(GameCameraManagerBehaviour, m_player2Camera, "Camera 2"); + registerProperty(GameCameraManagerBehaviour, m_player3Camera, "Camera 3"); + registerProperty(GameCameraManagerBehaviour, m_player4Camera, "Camera 4"); + + registerPropertyEx(GameCameraManagerBehaviour, m_players, "Players", vg::core::PropertyFlags::ReadOnly); + setPropertyRange(GameCameraManagerBehaviour, m_players, uint2(0, 4)); + + return true; +} + +//-------------------------------------------------------------------------------------- +void GameCameraManagerBehaviour::OnPropertyChanged(IObject * _object, const IProperty & _prop, bool _notifyParent) +{ + if (!strcmp(_prop.GetName(), "m_players")) + updateGameViewports(); + + super::OnPropertyChanged(_object, _prop, _notifyParent); +} + +//-------------------------------------------------------------------------------------- +void GameCameraManagerBehaviour::OnPlay() +{ + super::OnPlay(); +} + +//-------------------------------------------------------------------------------------- +void GameCameraManagerBehaviour::Update(const Context & _context) +{ + if (_context.m_playing && !_context.m_paused) + { + const uint playerCount = (uint)Game::get()->getActivePlayers().size(); + if (m_players != playerCount) + { + m_players = playerCount; + updateGameViewports(); + } + } +} + +//-------------------------------------------------------------------------------------- +void GameCameraManagerBehaviour::updateGameViewports() +{ + VG_INFO("[CameraManager] Update Game Viewports for %u players", m_players); + + vector activePlayersSorted = Game::get()->getActivePlayers(); + sort(activePlayersSorted.begin(), activePlayersSorted.end(), [](PlayerBehaviour * a, PlayerBehaviour * b) + { + return (a->getViewportIndex() < b->getViewportIndex()); + } + ); + + vector cameras(activePlayersSorted.size()); + + for (uint i = 0; i < activePlayersSorted.size(); ++i) + { + const PlayerBehaviour * player = activePlayersSorted[i]; + IGameObject * camGO = nullptr; + + const uint index = player->getViewportIndex() != -1 ? player->getViewportIndex() : i; + switch (index) + { + default: + VG_ASSERT_NOT_IMPLEMENTED(); + break; + + case 0: + camGO = m_player1Camera.get(); + break; + + case 1: + camGO = m_player2Camera.get(); + break; + + case 2: + camGO = m_player3Camera.get(); + break; + + case 3: + camGO = m_player4Camera.get(); + break; + } + + cameras[i] = camGO; + auto * playerGO = player->GetGameObject(); + camGO->SetName("Camera_" + playerGO->GetName()); + if (auto * gameCamBehaviour = camGO->GetComponentT()) + gameCamBehaviour->setTarget(playerGO); + } + + if (cameras.size() > 0) + { + if (m_players > 0) + { + cameras[0]->SetInstanceFlags(vg::core::InstanceFlags::Enabled, true); + + if (auto * cam0 = cameras[0]->GetComponentT()) + { + switch (m_players) + { + default: + VG_ASSERT_NOT_IMPLEMENTED(); + break; + + case 0: + case 1: // ■■ + cam0->SetViewportOffsetAndScale(float2(0.0f, 0.0f), float2(1.0f, 1.0f)); // ■■ + break; + + case 2: + cam0->SetViewportOffsetAndScale(float2(0.0f, 0.0f), float2(0.5f, 1.0f)); // ■□ + break; // ■□ + + case 3: + case 4: // ■□ + cam0->SetViewportOffsetAndScale(float2(0.0f, 0.0f), float2(0.5f, 0.5f)); // □□ + break; + } + } + } + else + { + cameras[0]->SetInstanceFlags(vg::core::InstanceFlags::Enabled, false); + } + } + + if (cameras.size() > 1) + { + if (m_players > 1) + { + cameras[1]->SetInstanceFlags(vg::core::InstanceFlags::Enabled, true); + if (auto * cam1 = cameras[1]->GetComponentT()) + { + switch (m_players) + { + default: + VG_ASSERT_NOT_IMPLEMENTED(); + break; + + case 2: + cam1->SetViewportOffsetAndScale(float2(0.5f, 0.0f), float2(0.5f, 1.0f)); // □■ + break; // □■ + + case 3: + case 4: // □■ + cam1->SetViewportOffsetAndScale(float2(0.5f, 0.0f), float2(0.5f, 0.5f)); // □□ + break; + } + } + } + else + { + cameras[1]->SetInstanceFlags(vg::core::InstanceFlags::Enabled, false); + } + } + + if (cameras.size() > 2) + { + if (m_players > 2) + { + cameras[2]->SetInstanceFlags(vg::core::InstanceFlags::Enabled, true); + if (auto * cam2 = cameras[2]->GetComponentT()) + { + switch (m_players) + { + default: + VG_ASSERT_NOT_IMPLEMENTED(); + break; + + case 3: // □□ + cam2->SetViewportOffsetAndScale(float2(0.0f, 0.5f), float2(1.0f, 0.5f)); // ■■ + break; + + case 4: // □□ + cam2->SetViewportOffsetAndScale(float2(0.0f, 0.5f), float2(0.5f, 0.5f)); // ■□ + break; + } + } + } + else + { + cameras[2]->SetInstanceFlags(vg::core::InstanceFlags::Enabled, false); + } + } + + if (cameras.size() > 3) + { + if (m_players > 3) + { + cameras[3]->SetInstanceFlags(vg::core::InstanceFlags::Enabled, true); + if (auto * cam3 = cameras[3]->GetComponentT()) + { + switch (m_players) + { + default: + VG_ASSERT_NOT_IMPLEMENTED(); + break; + + case 4: // □□ + cam3->SetViewportOffsetAndScale(float2(0.5f, 0.5f), float2(0.5f, 0.5f)); // □■ + break; + } + } + } + else + { + cameras[3]->SetInstanceFlags(vg::core::InstanceFlags::Enabled, false); + } + } +} \ No newline at end of file diff --git a/projects/game/src/Behaviour/Camera/GameCameraManagerBehaviour.h b/projects/game/src/Behaviour/Camera/GameCameraManagerBehaviour.h new file mode 100644 index 000000000..54abacedc --- /dev/null +++ b/projects/game/src/Behaviour/Camera/GameCameraManagerBehaviour.h @@ -0,0 +1,26 @@ +#include "core/Component/Behaviour/Behaviour.h" +#include "core/Object/ObjectHandle.h" + +class GameCameraManagerBehaviour final : public vg::core::Behaviour +{ +public: + VG_CLASS_DECL(GameCameraManagerBehaviour, vg::core::Behaviour); + + GameCameraManagerBehaviour(const vg::core::string & _name, vg::core::IObject * _parent); + ~GameCameraManagerBehaviour(); + + void OnPlay() final override; + void Update(const Context & _context) final override; + void OnPropertyChanged(vg::core::IObject * _object, const vg::core::IProperty & _prop, bool _notifyParent) final override; + +private: + void updateGameViewports(); + +private: + vg::core::uint m_players = 0; + + vg::core::ObjectHandle m_player1Camera; + vg::core::ObjectHandle m_player2Camera; + vg::core::ObjectHandle m_player3Camera; + vg::core::ObjectHandle m_player4Camera; +}; \ No newline at end of file diff --git a/projects/game/src/Behaviour/Character/Player/PlayerBehaviour.h b/projects/game/src/Behaviour/Character/Player/PlayerBehaviour.h index cc472fb46..a5015085c 100644 --- a/projects/game/src/Behaviour/Character/Player/PlayerBehaviour.h +++ b/projects/game/src/Behaviour/Character/Player/PlayerBehaviour.h @@ -7,21 +7,27 @@ class PlayerBehaviour final : public CharacterBehaviour public: VG_CLASS_DECL(PlayerBehaviour, CharacterBehaviour); - PlayerBehaviour (const vg::core::string & _name, vg::core::IObject * _parent); - ~PlayerBehaviour (); + PlayerBehaviour (const vg::core::string & _name, vg::core::IObject * _parent); + ~PlayerBehaviour (); - void OnPlay () final override; - void OnStop () final override; + void OnPlay () final override; + void OnStop () final override; - void FixedUpdate (const Context & _context) override; - void Update (const Context & _context) override; + void FixedUpdate (const Context & _context) override; + void Update (const Context & _context) override; - const vg::core::float4 & getCustomColor () const { return m_customColor; } + VG_INLINE const vg::core::float4 & getCustomColor () const; + VG_INLINE const vg::core::u8 getViewportIndex () const; private: - vg::core::InputType m_controllerType = vg::core::InputType::Joypad; - vg::core::u8 m_controllerIndex = 0; - vg::core::float4 m_customColor = vg::core::float4(1, 1, 1, 1); - vg::core::ObjectHandle m_UI; - ItemBehaviour * m_rightHandItem = nullptr; + vg::core::InputType m_controllerType = vg::core::InputType::Joypad; + vg::core::u8 m_controllerIndex = 0; + vg::core::float4 m_customColor = vg::core::float4(1, 1, 1, 1); + vg::core::ObjectHandle m_UI; + ItemBehaviour * m_rightHandItem = nullptr; + vg::core::u8 m_viewIndex = -1; }; + +#if VG_ENABLE_INLINE +#include "PlayerBehaviour.inl" +#endif \ No newline at end of file diff --git a/projects/game/src/Behaviour/Character/Player/PlayerBehaviour.hpp b/projects/game/src/Behaviour/Character/Player/PlayerBehaviour.hpp index 4218645f8..247f0c74a 100644 --- a/projects/game/src/Behaviour/Character/Player/PlayerBehaviour.hpp +++ b/projects/game/src/Behaviour/Character/Player/PlayerBehaviour.hpp @@ -8,12 +8,17 @@ #include "engine/IPhysicsBodyComponent.h" #include "engine/IPhysicsShapeComponent.h" #include "engine/ISoundComponent.h" +#include "engine/IUICanvasComponent.h" #include "editor/Editor_Consts.h" #include "core/GameObject/GameObject.h" #include "core/IWorld.h" #include "core/Math/Math.h" #include "core/string/string.h" +#if !VG_ENABLE_INLINE +#include "PlayerBehaviour.inl" +#endif + using namespace vg::core; using namespace vg::engine; @@ -54,6 +59,8 @@ bool PlayerBehaviour::registerProperties(IClassDesc & _desc) registerProperty(PlayerBehaviour, m_UI, "UI"); setPropertyDescription(PlayerBehaviour, m_UI, "Player UI Prefab instance linked"); + registerPropertyEx(PlayerBehaviour, m_viewIndex, "View", vg::core::PropertyFlags::NotSaved | vg::core::PropertyFlags::ReadOnly); + setPropertyDescription(PlayerBehaviour, m_viewIndex, "Index of the View used by this player"); } registerPropertyGroupEnd(PlayerBehaviour); @@ -68,11 +75,16 @@ void PlayerBehaviour::OnPlay() // Compute initial rotation around Z axis const auto global = GetGameObject()->GetGlobalMatrix(); m_currentRotation = -atan2(global[1].x, global[0].x) * 180.0f / PI; + + // Hide UI until the player is active + if (auto * uiGO = m_UI.get()) + uiGO->SetInstanceFlags(InstanceFlags::Enabled, false); } //-------------------------------------------------------------------------------------- void PlayerBehaviour::OnStop() { + m_isActive = false; super::OnStop(); } @@ -129,7 +141,18 @@ void PlayerBehaviour::FixedUpdate(const Context & _context) m_currentRotation = radiansToDegrees(atan2((float)leftJoyDir.x, (float)leftJoyDir.y)); if (!m_isActive) + { + m_viewIndex = (u8)Game::get()->getActivePlayers().size(); + + if (auto * uiGO = m_UI.get()) + { + uiGO->SetInstanceFlags(InstanceFlags::Enabled, true); + if (auto * uiCanvasComponent = uiGO->GetComponentInChildrenT()) + uiCanvasComponent->SetViewIndex(m_viewIndex); + } + m_isActive = true; + } } if (any(abs(translation.xy) > 0.0f)) diff --git a/projects/game/src/Behaviour/Character/Player/PlayerBehaviour.inl b/projects/game/src/Behaviour/Character/Player/PlayerBehaviour.inl new file mode 100644 index 000000000..3d5e8dc15 --- /dev/null +++ b/projects/game/src/Behaviour/Character/Player/PlayerBehaviour.inl @@ -0,0 +1,11 @@ +//-------------------------------------------------------------------------------------- +VG_INLINE const vg::core::float4 & PlayerBehaviour::getCustomColor() const +{ + return m_customColor; +} + +//-------------------------------------------------------------------------------------- +VG_INLINE const vg::core::u8 PlayerBehaviour::getViewportIndex() const +{ + return m_viewIndex; +} \ No newline at end of file diff --git a/projects/game/src/Game.cpp b/projects/game/src/Game.cpp index e719d17a7..0b6cb865e 100644 --- a/projects/game/src/Game.cpp +++ b/projects/game/src/Game.cpp @@ -3,8 +3,8 @@ #include "core/Kernel.h" #include "core/Object/AutoRegisterClass.h" #include "engine/IEngine.h" - #include "Behaviour/Character/Player/PlayerBehaviour.h" +#include "Behaviour/Item/ItemBehaviour.h" using namespace vg::core; @@ -118,6 +118,7 @@ void Game::addCharacter(CharacterType _type, CharacterBehaviour * _character) auto & characters = m_characters[vg::core::asInteger(_type)]; VG_ASSERT(!vector_helper::exists(characters, _character)); characters.push_back(_character); + VG_INFO("[Game] Add %s Character \"%s\"", asString(_type).c_str(), _character->GetName().c_str()); } //-------------------------------------------------------------------------------------- @@ -126,6 +127,7 @@ void Game::removeCharacter(CharacterType _type, CharacterBehaviour * _character) auto & characters = m_characters[vg::core::asInteger(_type)]; VG_ASSERT(vector_helper::exists(characters, _character)); vector_helper::remove(characters, _character); + VG_INFO("[Game] Remove %s Character \"%s\"", asString(_type).c_str(), _character->GetName().c_str()); } //-------------------------------------------------------------------------------------- @@ -134,6 +136,20 @@ const vg::core::vector & Game::getPlayers() const return reinterpret_cast &>(m_characters[vg::core::asInteger(CharacterType::Player)]); } +//-------------------------------------------------------------------------------------- +const vg::core::vector Game::getActivePlayers() const +{ + const auto players = m_characters[vg::core::asInteger(CharacterType::Player)]; + vector activePlayers; + activePlayers.reserve(players.size()); + for (auto * player : players) + { + if (player->isActive()) + activePlayers.push_back((PlayerBehaviour*)player); + } + return activePlayers; +} + //-------------------------------------------------------------------------------------- const vg::core::vector & Game::getEnemies() const { @@ -146,6 +162,7 @@ void Game::addItem(ItemType _type, ItemBehaviour * _item) auto & items = m_items[vg::core::asInteger(_type)]; VG_ASSERT(!vector_helper::exists(items, _item)); items.push_back(_item); + VG_INFO("[Game] Add %s Item \"%s\"", asString(_type).c_str(), _item->GetName().c_str()); } //-------------------------------------------------------------------------------------- @@ -154,6 +171,7 @@ void Game::removeItem(ItemType _type, ItemBehaviour * _item) auto & items = m_items[vg::core::asInteger(_type)]; VG_ASSERT(vector_helper::exists(items, _item)); vector_helper::remove(items, _item); + VG_INFO("[Game] Remove %s Item \"%s\"", asString(_type).c_str(), _item->GetName().c_str()); } //-------------------------------------------------------------------------------------- diff --git a/projects/game/src/Game.h b/projects/game/src/Game.h index 085194fea..96b21ddbd 100644 --- a/projects/game/src/Game.h +++ b/projects/game/src/Game.h @@ -46,6 +46,7 @@ class Game : public vg::IGame, public vg::core::Singleton const vg::core::vector & getCharacters (CharacterType _type) const { return m_characters[vg::core::asInteger(_type)];} const vg::core::vector & getPlayers () const; + const vg::core::vector getActivePlayers () const; const vg::core::vector & getEnemies () const; void addItem (ItemType _type, ItemBehaviour * _item); diff --git a/projects/game/src/Game.vcxproj.vcxproj b/projects/game/src/Game.vcxproj.vcxproj index 1c3709dba..74dd90262 100644 --- a/projects/game/src/Game.vcxproj.vcxproj +++ b/projects/game/src/Game.vcxproj.vcxproj @@ -27,9 +27,11 @@ - + + + @@ -59,6 +61,7 @@ + diff --git a/projects/game/src/Game.vcxproj.vcxproj.filters b/projects/game/src/Game.vcxproj.vcxproj.filters index f1dff8753..735351f07 100644 --- a/projects/game/src/Game.vcxproj.vcxproj.filters +++ b/projects/game/src/Game.vcxproj.vcxproj.filters @@ -9,12 +9,12 @@ Behaviour\Goal - - Behaviour\Camera - Behaviour\Item + + Behaviour\Camera + @@ -56,6 +56,12 @@ Behaviour\Item\Weapon + + Behaviour\Camera + + + Behaviour\Camera + @@ -88,5 +94,8 @@ + + Behaviour\Character\Player + \ No newline at end of file diff --git a/src/editor/ImGui/Window/ImGuiWindow.cpp b/src/editor/ImGui/Window/ImGuiWindow.cpp index 9eefced3a..93ac9c9ba 100644 --- a/src/editor/ImGui/Window/ImGuiWindow.cpp +++ b/src/editor/ImGui/Window/ImGuiWindow.cpp @@ -2918,12 +2918,10 @@ namespace vg::editor ImGui::PopItemWidth(); - ImGui::SameLine(); - if (ImGui::Button(style::icon::GameObject, style::button::SizeSmall)) - { - } ImGui::PushID(_prop); + ImGui::SameLine(); + ImGui::Button(style::icon::GameObject, style::button::SizeSmall); ImGuiObjectHandleMenu * pickObjectHandlemenu = Editor::get()->getMenu(); if (pickObjectHandlemenu->SelectUID(&temp, _propContext.m_gameobject, openPopup)) edited = true; diff --git a/src/engine/Component/Camera/CameraComponent.cpp b/src/engine/Component/Camera/CameraComponent.cpp index c1d968a4d..248ae7e10 100644 --- a/src/engine/Component/Camera/CameraComponent.cpp +++ b/src/engine/Component/Camera/CameraComponent.cpp @@ -59,7 +59,7 @@ namespace vg::engine //-------------------------------------------------------------------------------------- CameraComponent::CameraComponent(const core::string & _name, core::IObject * _parent) : - core::Component(_name, _parent), + super(_name, _parent), m_target(gfx::ViewportTarget::Game), m_viewportIndex((gfx::ViewportIndex)0), m_viewIndex((gfx::ViewIndex)0), @@ -146,4 +146,12 @@ namespace vg::engine view->SetupPerspectiveCamera(matrix, float2(m_near, m_far), m_fovY, m_viewportOffset, m_viewportScale); } } + + + //-------------------------------------------------------------------------------------- + void CameraComponent::SetViewportOffsetAndScale(core::float2 _offset, const core::float2 & _scale) + { + m_viewportOffset = _offset; + m_viewportScale = _scale; + } } \ No newline at end of file diff --git a/src/engine/Component/Camera/CameraComponent.h b/src/engine/Component/Camera/CameraComponent.h index fbaab94eb..21bba9fc5 100644 --- a/src/engine/Component/Camera/CameraComponent.h +++ b/src/engine/Component/Camera/CameraComponent.h @@ -1,6 +1,6 @@ #pragma once -#include "core/Component/Component.h" +#include "engine/ICameraComponent.h" #include "gfx/IView.h" namespace vg::core @@ -22,23 +22,25 @@ namespace vg::renderer namespace vg::engine { - class CameraComponent : public core::Component + class CameraComponent : public ICameraComponent { public: - VG_CLASS_DECL(CameraComponent, core::Component); + VG_CLASS_DECL(CameraComponent, ICameraComponent); - CameraComponent (const core::string & _name, core::IObject * _parent); - ~CameraComponent (); + CameraComponent (const core::string & _name, core::IObject * _parent); + ~CameraComponent (); - void Update (const Context & _context) override; + void Update (const Context & _context) override; - VG_INLINE void setViewportTarget (gfx::ViewportTarget _target); - VG_INLINE gfx::ViewportTarget getViewportTarget () const; - gfx::ViewID getViewID () const; + void SetViewportOffsetAndScale (core::float2 _offset, const core::float2 & _scale) final override; - VG_INLINE float getFovY () const; - VG_INLINE float getNear () const; - VG_INLINE float getFar () const; + VG_INLINE void setViewportTarget (gfx::ViewportTarget _target); + VG_INLINE gfx::ViewportTarget getViewportTarget () const; + gfx::ViewID getViewID () const; + + VG_INLINE float getFovY () const; + VG_INLINE float getNear () const; + VG_INLINE float getFar () const; protected: gfx::ViewportTarget m_target; diff --git a/src/engine/Component/UI/UICanvasComponent.h b/src/engine/Component/UI/UICanvasComponent.h index d7592e9c6..73283c4b3 100644 --- a/src/engine/Component/UI/UICanvasComponent.h +++ b/src/engine/Component/UI/UICanvasComponent.h @@ -1,19 +1,21 @@ #pragma once -#include "engine/Component/UI/UIComponent.h" +#include "engine/IUICanvasComponent.h" #include "engine/Resource/Texture/TextureResource.h" namespace vg::engine { - class UICanvasComponent : public UIComponent + class UICanvasComponent final : public IUICanvasComponent { public: - VG_CLASS_DECL(UICanvasComponent, UIComponent); + VG_CLASS_DECL(UICanvasComponent, IUICanvasComponent); + UICanvasComponent(const core::string & _name, core::IObject * _parent); ~UICanvasComponent(); - void Update(const Context & _context) final override; + void SetViewIndex (core::uint _viewIndex) final override; + void Update (const Context & _context) final override; - VG_INLINE const gfx::UICanvas & getGfxCanvas() const { return m_canvas; } + VG_INLINE const gfx::UICanvas & getGfxCanvas () const { return m_canvas; } private: gfx::UICanvas m_canvas; diff --git a/src/engine/Component/UI/UICanvasComponent.hpp b/src/engine/Component/UI/UICanvasComponent.hpp index b35ecd682..cd7bc42b4 100644 --- a/src/engine/Component/UI/UICanvasComponent.hpp +++ b/src/engine/Component/UI/UICanvasComponent.hpp @@ -45,6 +45,12 @@ namespace vg::engine } + //-------------------------------------------------------------------------------------- + void UICanvasComponent::SetViewIndex(core::uint _viewIndex) + { + m_canvas.m_viewIndex = _viewIndex; + } + //-------------------------------------------------------------------------------------- void UICanvasComponent::Update(const Context & _context) { diff --git a/src/engine/Engine.vcxproj.filters b/src/engine/Engine.vcxproj.filters index 2390d6cbd..55873c48a 100644 --- a/src/engine/Engine.vcxproj.filters +++ b/src/engine/Engine.vcxproj.filters @@ -347,6 +347,8 @@ Component\Audio\Sound + + diff --git a/src/engine/ICameraComponent.h b/src/engine/ICameraComponent.h new file mode 100644 index 000000000..297bdf55d --- /dev/null +++ b/src/engine/ICameraComponent.h @@ -0,0 +1,14 @@ +#pragma once + +#include "core/Component/Component.h" + +namespace vg::engine +{ + class ICameraComponent : public core::Component + { + public: + VG_CLASS_DECL_ABSTRACT(ICameraComponent, core::Component); + + virtual void SetViewportOffsetAndScale(core::float2 _offset, const core::float2 & _scale) = 0; + }; +} \ No newline at end of file diff --git a/src/engine/IUICanvasComponent.h b/src/engine/IUICanvasComponent.h new file mode 100644 index 000000000..fe4ba8def --- /dev/null +++ b/src/engine/IUICanvasComponent.h @@ -0,0 +1,13 @@ +#pragma once +#include "engine/Component/UI/UIComponent.h" + +namespace vg::engine +{ + class IUICanvasComponent : public UIComponent + { + public: + VG_CLASS_DECL_ABSTRACT(IUICanvasComponent, UIComponent); + + virtual void SetViewIndex(core::uint _viewIndex) = 0; + }; +} diff --git a/src/engine/engine.vcxproj b/src/engine/engine.vcxproj index 6d21c3c51..eec226891 100644 --- a/src/engine/engine.vcxproj +++ b/src/engine/engine.vcxproj @@ -76,9 +76,11 @@ + +