Skip to content

Conversation

@IAmNotHanni
Copy link
Member

@IAmNotHanni IAmNotHanni commented Jun 20, 2022

Blocked by #518

Overview

  • Do not reset camera position when window is resized
  • Change return type of camera methods to const reference so method calls can be chained
  • Chain method calls to camera wrapper methods
  • Make camera code thread-safe
  • Improve code documentation

@IAmNotHanni IAmNotHanni added the cat:refactor refactor/clean up/simplifications/etc. label Jun 20, 2022
@IAmNotHanni IAmNotHanni self-assigned this Jun 20, 2022
@IAmNotHanni IAmNotHanni changed the title Hanni/camera refactoring Refactor camera code Jun 20, 2022
Comment on lines +102 to +103
/// @note We will implement more camera types in the future
/// @param type The camera type
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// @note We will implement more camera types in the future
/// @param type The camera type
/// @param type The camera type
/// @note We will implement more camera types in the future

Param before notes.

constexpr glm::vec3 DEFAULT_UP{0.0f, 0.0f, 1.0f};
} // namespace directions

enum class CameraMovement { FORWARD, BACKWARD, LEFT, RIGHT };
Copy link
Member

@IceflowRE IceflowRE Jun 30, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Iam not a friend of using an enum for indicating a camera movement. I would allow direct manipulations via vectors.
In general i don't really like the current state of this camera class.
This camera class is already highly specified and implemented and thus limited in adding new camera types.
By handling inputs and the resulting camera movement.

I would suggest to make a more general camera class with the most important methods like direction, position, plane, etc.
Then inherit from this base camera and implement a PlayerCamera which has more traits like rotation speed, movement speed etc.

In my eyes is camera movement already part of the game (user) code and not the engine code. We should only provide callbacks or signals to inputs.

Copy link
Member

@yeetari yeetari left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work, though I'm not a huge fan of using ThisType &foo() { return *this; } everywhere (imo it's main use case is for builders). Also I agree with Iceflower that the camera code would be nicer if it ws inheritance based, something like:

struct Camera {
    virtual void update();
    
    virtual glm::vec3f forward() const;
    virtual glm::mat4f view_matrix() const;
};

class FreeCamera  : public Camera {};

Copy link
Member

@westernheld westernheld left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you resize the window just in one direction or with a different ratio in width and height you will cause the camera make squares out of the cubes. See Screenshot.
image

@IAmNotHanni IAmNotHanni added the prio:low This has low priority. label Sep 1, 2022
@IAmNotHanni
Copy link
Member Author

This has lower priority atm. I will work on other pull requests for now :)

@IAmNotHanni IAmNotHanni marked this pull request as draft October 7, 2025 20:04
@IAmNotHanni IAmNotHanni changed the title Refactor camera code [camera] Refactor camera code Oct 11, 2025
@IAmNotHanni
Copy link
Member Author

IAmNotHanni commented Oct 14, 2025

After some thinking, I came to the conclusion that it's not worth it to continue with this pull request. The reasons are the following:

  • I want to abstract the camera as an entiy in EnTT anyways, so the entire code will be changed later
  • The changes introduced in this pull request are minimal, and I would do many things differently now. For example, I would not have a builder pattern for setting the camera variables anymore, as this should be reserved for other code parts.
  • Thread safety can be implemented based on the entity component system.
  • The bug Resizing window causes camera position to reset #411 will be fixed by [*] Refactor rendergraph #533

Thanks anyways for the review guys, I will take notes on how to do it like this for future pull requests.

@IAmNotHanni IAmNotHanni deleted the hanni/camera_refactoring branch October 15, 2025 21:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cat:refactor refactor/clean up/simplifications/etc. prio:low This has low priority.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants