Skip to content

Commit

Permalink
Change update function and take scene
Browse files Browse the repository at this point in the history
  • Loading branch information
bilalkah committed Aug 13, 2024
1 parent 3eb9505 commit 95ef69e
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/Camera/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,5 @@ target_link_libraries(
character
vector
map
scene
)
3 changes: 2 additions & 1 deletion src/Camera/include/Camera/camera.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#define CAMERA_CAMERA_H

#include "Camera/raycaster.h"
#include "Graphics/scene.h"
#include <Camera/ray.h>
#include <Characters/character.h>
#include <GameObjects/game_object.h>
Expand All @@ -35,7 +36,7 @@ class Camera2D
explicit Camera2D(const Camera2DConfig& config);
~Camera2D() = default;

void Update(const std::shared_ptr<Map>& map);
void Update(const std::shared_ptr<Scene>& scene);

std::shared_ptr<RayVector> GetRays() const;
std::shared_ptr<Ray> GetCrosshairRay() const;
Expand Down
6 changes: 4 additions & 2 deletions src/Camera/src/camera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@ Camera2D::Camera2D(const Camera2DConfig& config)
InitRays();
}

void Camera2D::Update(const std::shared_ptr<Map>& map_ptr) {
ray_cast_->Update(map_ptr, position_, rays_);
void Camera2D::Update(const std::shared_ptr<Scene>& scene) {
ray_cast_->Update(scene->GetMap(), position_, rays_);
crosshair_ray_ = std::make_shared<Ray>(rays_->at(config_.width / 4));

// Update object rays
}

std::shared_ptr<RayVector> Camera2D::GetRays() const {
Expand Down
2 changes: 1 addition & 1 deletion src/Core/src/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ void Game::Run() {
CheckEvent();
time_manager_->CalculateDeltaTime();
scene_->Update(time_manager_->GetDeltaTime());
camera_->Update(map_);
camera_->Update(scene_);
switch (render_type_) {
case RenderType::TEXTURE:
renderer_->RenderScene(scene_, camera_);
Expand Down
2 changes: 1 addition & 1 deletion src/Graphics/src/renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ void Renderer::RenderObjects(

SetDrawColor({00, 0xA5, 0, 1});
const auto rays = *camera_ptr->GetRays();
for (int i = 0; i < rays.size(); i++) {
for (unsigned int i = 0; i < rays.size(); i++) {
if (!rays[i].is_hit || i % 3 != 0) {
continue;
}
Expand Down

0 comments on commit 95ef69e

Please sign in to comment.