Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor camera code #474

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open

Refactor camera code #474

wants to merge 5 commits into from

Conversation

IAmNotHanni
Copy link
Member

@IAmNotHanni IAmNotHanni commented Jun 20, 2022

Closes #411
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
@@ -10,71 +10,71 @@
namespace inexor::vulkan_renderer {

namespace directions {
/// The default value of the camera's front vector.
Copy link
Member

Choose a reason for hiding this comment

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

Do we use or not the ending period?

Copy link
Member

Choose a reason for hiding this comment

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

OK found it, we use periods at the end of the sentences :D
Already "discussed" on Discord.

@@ -10,71 +10,71 @@
namespace inexor::vulkan_renderer {

namespace directions {
/// The default value of the camera's front vector.
Copy link
Member

Choose a reason for hiding this comment

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

OK found it, we use periods at the end of the sentences :D
Already "discussed" on Discord.

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.

src/vulkan-renderer/application.cpp Show resolved Hide resolved
constexpr glm::vec3 DEFAULT_RIGHT{0.0f, 1.0f, 0.0f};
/// The default value of the camera's up vector.
/// The default value of the camera's up vector
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 :)

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.

Resizing window causes camera position to reset
4 participants