-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Renderer: Added camera boundaries to CameraManager and clamping #1682. #1691
base: master
Are you sure you want to change the base?
Conversation
…e camera movement.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good so far!
I have a few comments regarding the current status.
// Calculate look at coordinates using same method as in look_at_scene(..) | ||
auto y_delta = this->scene_pos[1] - scene_pos[1]; | ||
auto xz_distance = y_delta * std::numbers::sqrt3; | ||
|
||
float side_length = xz_distance / std::numbers::sqrt2; | ||
scene_pos[0] += side_length; | ||
scene_pos[2] += side_length; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
move_to
should not do the look at calculations because it is intended to just move the camera to a position in the scene. Looking at a scene coordinate is already implemented in look_at_scene
. This might break existing code where move_to
is currently used.
The changes here might also break look_at_scene
's behavior, since the method calls move_to
but with the already computed camera position. Therefore, the look at calculations would be done a second time on the already translated camera position.
std::optional<std::pair<float, float>> x_bounds, | ||
std::optional<std::pair<float, float>> z_bounds) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of using two pairs for the bounds, it probably makes sense to make these parameters a struct and pass that.
std::pair<float, float> x_bounds, | ||
std::pair<float, float> z_bounds, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In move_to
you made them optional, but here they are non-optional. Is there a reason for this?
libopenage/renderer/camera/camera.h
Outdated
@@ -15,6 +15,7 @@ | |||
#include "renderer/camera/definitions.h" | |||
#include "renderer/camera/frustum_2d.h" | |||
#include "renderer/camera/frustum_3d.h" | |||
#include <optional> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Small nitpick, but imports of standard libraries should be placed before local includes in our code. See our (arguably a bit hidden) code style examples:
openage/doc/code_style/mom.cpp
Lines 17 to 32 in 66098ce
// The associated header file comes first! | |
#include "mom.h" | |
// C++ std library includes follow, sorted alphabetically | |
#include <cmath> | |
#include <cstdio> | |
#include <iostream> | |
// External libraries are next, sorted alphabetically | |
#include <eigen3/Eigen/Dense> | |
#include <epoxy/gl.h> | |
// Local includes come last, sorted alphabetically | |
#include "../valve.h" | |
#include "half_life.h" | |
#include "log/log.h" |
libopenage/renderer/camera/camera.h
Outdated
* @param scene_pos New 3D position of the camera in the scene. | ||
*/ | ||
void move_to(Eigen::Vector3f scene_pos); | ||
void move_to(Eigen::Vector3f scene_pos, std::optional<std::pair<float, float>> x_bounds = std::nullopt, | ||
std::optional<std::pair<float, float>> z_bounds = std::nullopt); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should document arguments you add to methods in the docstrings above.
libopenage/renderer/demo/demo_5.cpp
Outdated
@@ -38,6 +39,7 @@ void renderer_demo_5(const util::Path &path) { | |||
camera->resize(w, h); | |||
}); | |||
|
|||
camera::CameraManager camera_manager(camera); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The demos in this file should probably not use the camera manager because that introduces more unnecessary complexity to them. We try to show off specific features of the renderer in the code. As CameraManager
is an interface between the input system and the renderer, it is technically an additional layer that does a bunch of updates which are unnecessary for the demo.
libopenage/renderer/demo/demo_6.cpp
Outdated
@@ -438,6 +439,7 @@ void RenderManagerDemo6::create_camera() { | |||
1.0f / static_cast<float>(viewport_size[1])}; | |||
camera_unifs->update("inv_viewport_size", viewport_size_vec); | |||
this->camera->get_uniform_buffer()->update_uniforms(camera_unifs); | |||
this->camera_manager = std::make_shared<camera::CameraManager>(camera); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here, using the camera manager is a bit overkill for this demo.
x_bounds = std::make_pair(XMIN, XMAX); | ||
z_bounds = std::make_pair(ZMIN, ZMAX); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These members should be initialized in the initializer list in the constructor above.
/** | ||
* x and z bounds for the camera. | ||
*/ | ||
std::pair<float, float> x_bounds, z_bounds; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Small nitpick but the docstring should explain more about what these bounds are. Also, you should mention that the first value is the min bound and the second value is the max bound. However, if you follow up on the idea to make this a struct, it would probably not be necessary to document the latter.
/** | ||
* Constant values for the camera bounds. | ||
* TODO: Make boundaries dynamic based on map size. | ||
*/ | ||
const float XMIN = 12.25f, XMAX = 32.25f, ZMIN = -8.25f, ZMAX = 12.25f; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could move these to https://github.com/SFTtech/openage/blob/master/libopenage/renderer/camera/definitions.h but since they are meant only for testing, this doesn't really matter.
@EdvinLndh Are you planning to continue this one soon-ish? |
Sorry, I've been out of town for a few weeks, I'll look into it |
libopenage/renderer/camera/camera.h
Outdated
* the positional vector. | ||
* @param camera_boundaries X and Z boundaries for the camera in the scene. | ||
*/ | ||
void move_rel(Eigen::Vector3f direction, float delta, struct CameraBoundaries camera_boundaries); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
void move_rel(Eigen::Vector3f direction, float delta, struct CameraBoundaries camera_boundaries); | |
void move_rel(Eigen::Vector3f direction, float delta, CameraBoundaries camera_boundaries); |
struct
is only necessary in C, but you can omit it in C++
libopenage/renderer/camera/camera.h
Outdated
CameraBoundaries(float x_min, float x_max, float z_min, float z_max) | ||
: x_min(x_min), x_max(x_max), z_min(z_min), z_max(z_max) {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For structs, we usually don't declare a constructor and use a braced initializer list to create objects, especially for trivial structs like this one. Thus, you don't need to define it here.
libopenage/renderer/camera/camera.h
Outdated
* Defines constant boundaries for the camera's view in the X and Z axes. | ||
*/ | ||
struct CameraBoundaries { | ||
const float x_min, x_max, z_min, z_max; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure it makes sense to declare all members as const, since there's no reason why the camera boundaries should be immutable changed at all time. If we wanted a an immutable CameraBoundaries
struct, we could just declare that as const instead with const CameraBoundaries example{..};
I have converted this into a draft while you work on it. Once you are done, you can set it as ready with the "Ready for review" button above. |
Camera boundaries are set using constants for now, will probably look into setting the boundaries dynamically soon. #1682