mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-11-20 17:39:46 +00:00
fix camera view rotation far from the world origin
Camera::getView built the view with lookAt(position, position + front): the direction came back as a difference of large floats. Far from the origin the view turned away from where the camera looks - at 16M blocks by up to 24 degrees, at 30M the camera looked straight up or down whatever its yaw (at pitch 0 the direction is a zero vector, the matrix is NaN). The rotation is built from front itself now, then translated by -position: the same matrix, without the subtraction.
This commit is contained in:
parent
348c058c9b
commit
e1f6daabb7
2 changed files with 35 additions and 9 deletions
|
|
@ -41,16 +41,11 @@ glm::mat4 Camera::getProjection() const {
|
|||
}
|
||||
|
||||
glm::mat4 Camera::getView(bool pos) const {
|
||||
glm::vec3 camera_pos = this->position;
|
||||
if (!pos) {
|
||||
camera_pos = glm::vec3(0.0f);
|
||||
}
|
||||
if (perspective) {
|
||||
return glm::lookAt(camera_pos, camera_pos + front, up);
|
||||
} else {
|
||||
return glm::lookAt(camera_pos, camera_pos + front, up);
|
||||
//return glm::translate(glm::mat4(1.0f), camera_pos);
|
||||
glm::mat4 view = glm::lookAt(glm::vec3(0.0f), front, up);
|
||||
if (pos) {
|
||||
view = glm::translate(view, -position);
|
||||
}
|
||||
return view;
|
||||
}
|
||||
|
||||
glm::mat4 Camera::getProjView(bool pos) const {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue