Merge pull request #362 from SHADE-DP/SP3-141-Camera-System

Camera width resize with viewport. GetMainCamera exposed to scripts
This commit is contained in:
XiaoQiDigipen 2023-02-24 17:20:13 +08:00 committed by GitHub
commit d259e31638
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 35 additions and 3 deletions

View File

@ -113,8 +113,7 @@
Pitch: 0
Yaw: 0
Roll: 0
Width: 1319
Height: 622
Width: 1175
Near: 0.00999999978
Far: 10000
Perspective: true

View File

@ -145,6 +145,22 @@ namespace SHADE
//std::cout << EVENT_DATA->resizeHeight << std::endl;
screenAspectRatio = (float)EVENT_DATA->resizeWidth / (float)EVENT_DATA->resizeHeight;
#ifdef SHEDITOR
auto editor = SHSystemManager::GetSystem<SHEditor>();
if (editor->editorState != SHEditor::State::PLAY)
return eventPtr->handle;
#endif // SHEDITOR
for (auto& director : directorHandleList)
{
auto camera = SHComponentManager::GetComponent_s<SHCameraComponent>(director->mainCameraEID);
if (camera)
{
camera->SetWidth(EVENT_DATA->resizeWidth);
}
}
return eventPtr->handle;
}
@ -574,4 +590,9 @@ namespace SHADE
#endif
}
EntityID SHCameraSystem::GetMainCameraEID() const noexcept
{
return directorHandleList[0]->mainCameraEID;
}
}

View File

@ -65,6 +65,7 @@ namespace SHADE
void SetCameraViewMatrix(SHCameraComponent& camera, SHMatrix const& viewMatrix, bool takePos) noexcept;
void CameraLookAt(SHCameraComponent& camera, SHVec3 target) noexcept;
void UpdateEditorArm(double dt,bool active ,SHVec3 const& targetPos) noexcept;
EntityID GetMainCameraEID() const noexcept;
SHVec2 GetCameraWidthHeight(size_t index) noexcept;
};

View File

@ -13,7 +13,6 @@ namespace SHADE
}
float Camera::Pitch::get()
{
return (GetNativeComponent()->GetPitch());
@ -126,4 +125,10 @@ namespace SHADE
}
Camera^ Camera::GetMainCamera()
{
auto system = SHSystemManager::GetSystem<SHCameraSystem>();
return ECS::GetComponent<Camera^>(system->GetMainCameraEID());
}
}

View File

@ -15,6 +15,9 @@ namespace SHADE
Camera(Entity entity);
public:
property float Pitch
{
float get();
@ -65,5 +68,8 @@ namespace SHADE
Vector3 GetForward();
Vector3 GetRight();
static Camera^ GetMainCamera();
};
}