mirror of
https://github.com/Linloir/SceneEditor.git
synced 2025-12-17 07:28:12 +08:00
[UI][FIX] Fix thumbnail camera position
This commit is contained in:
parent
281c424b87
commit
c2c11c689f
@ -1,5 +1,6 @@
|
||||
#include <qfile.h>
|
||||
#include <qdir.h>
|
||||
#include <algorithm>
|
||||
|
||||
#include "modelthumbnailwidget.h"
|
||||
|
||||
@ -56,7 +57,18 @@ void ModelThumbnailWidget::initializeGL() {
|
||||
fragmentShader.dispose();
|
||||
|
||||
_object.setModel(_model->copyToCurrentContext());
|
||||
_camera.setPosition(glm::vec3(0.0f, 0.0f, 7.0f));
|
||||
_object.updateBoundary();
|
||||
|
||||
// Move the camera to the right position
|
||||
float viewportWidth = width();
|
||||
float viewportHeight = height();
|
||||
float fovy = _camera.fovy();
|
||||
float fovx = 2.0f * atanf(tanf(fovy / 2.0f) * viewportWidth / viewportHeight);
|
||||
float objectHeight = _object.boundary().topControlPoint().y - _object.boundary().bottomControlPoint().y;
|
||||
float objectWidth = _object.boundary().topControlPoint().x - _object.boundary().bottomControlPoint().x;
|
||||
float distance = std::max(objectHeight / (2 * tan(fovy / 2)), objectWidth / (2 * tan(fovx / 2)));
|
||||
glm::vec2 center = _object.boundary().centerPoint();
|
||||
_camera.setPosition(glm::vec3(center, _object.boundary().topControlPoint().z + distance + 3.0f));
|
||||
}
|
||||
|
||||
void ModelThumbnailWidget::paintGL() {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user