I recently learned how I can simplify/improve code by using structs and non-member functions so to test this new discovery I refactored my camera code and I have a feeling I misused it.
I took every member function that wasn't 100% necessary out and I'm left with:
struct Camera {
glm::vec3 position;
glm::vec3 forward;
glm::vec3 right;
glm::vec3 up;
float yaw;
float pitch;
float roll;
float fov;
float aspectRatio;
float nearPlane;
float farPlane;
std::unique_ptr<CameraBehavior> behavior;
void Update(float timestep, Input& input) {
if (behavior) {
behavior->Update(*this, timestep, input);
}
}
};and made those member functions into non-member functions:
void Move(Camera& camera, const glm::vec3& direction, float speed, float timestep);
void Pivot(Camera& camera, float mouseXChange, float mouseYChange, float sensitivity);
void UpdateDirectionVectors(Camera& camera);
glm::mat4 ComputeViewMatrix(const Camera& camera);
glm::mat4 ComputeProjectionMatrix(const Camera& camera);The first 3 functions probably won't ever be used by something that isn't a camera so I have a feeling those might be bad usages. The compute functions on the other hand the camera doesn't really need that it's just for the render and potentially other code so is this a better usage?