mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2025-03-15 07:29:15 +01:00
LP-29 simplify resize logic (also fixes some resizing issues)
This commit is contained in:
parent
1a5b4a157e
commit
d9a0a3e84a
@ -76,12 +76,7 @@ public:
|
|||||||
first = true;
|
first = true;
|
||||||
|
|
||||||
dirty = false;
|
dirty = false;
|
||||||
|
fovDirty = false;
|
||||||
sizeDirty = false;
|
|
||||||
x = 0;
|
|
||||||
y = 0;
|
|
||||||
width = 0;
|
|
||||||
height = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
~Hidden()
|
~Hidden()
|
||||||
@ -196,8 +191,9 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
dirty = true;
|
dirty = true;
|
||||||
sizeDirty = true;
|
fovDirty = true;
|
||||||
updateCamera();
|
updateCamera();
|
||||||
|
updateAspectRatio();
|
||||||
}
|
}
|
||||||
|
|
||||||
void detachCamera(osg::Camera *camera)
|
void detachCamera(osg::Camera *camera)
|
||||||
@ -220,9 +216,6 @@ public:
|
|||||||
delete logDepthBuffer;
|
delete logDepthBuffer;
|
||||||
logDepthBuffer = NULL;
|
logDepthBuffer = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
// reset viewport
|
|
||||||
x = y = width = height = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void attachManipulator(osgViewer::View *view)
|
void attachManipulator(osgViewer::View *view)
|
||||||
@ -311,31 +304,19 @@ public:
|
|||||||
|
|
||||||
void updateCamera()
|
void updateCamera()
|
||||||
{
|
{
|
||||||
if (first) {
|
|
||||||
first = false;
|
|
||||||
updateCameraFOV();
|
updateCameraFOV();
|
||||||
}
|
|
||||||
updateCameraSize();
|
|
||||||
if (manipulatorMode == User) {
|
if (manipulatorMode == User) {
|
||||||
updateCameraPosition();
|
updateCameraPosition();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void updateCameraSize()
|
|
||||||
{
|
|
||||||
if (!sizeDirty || !camera.valid()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
sizeDirty = false;
|
|
||||||
|
|
||||||
// qDebug() << "OSGCamera::updateCamera size" << x << y << width << height << fieldOfView;
|
|
||||||
camera->getGraphicsContext()->resized(x, y, width, height);
|
|
||||||
camera->setViewport(x, y, width, height);
|
|
||||||
updateAspectRatio();
|
|
||||||
}
|
|
||||||
|
|
||||||
void updateCameraFOV()
|
void updateCameraFOV()
|
||||||
{
|
{
|
||||||
|
if (!fovDirty || !camera.valid()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
fovDirty = false;
|
||||||
|
|
||||||
// qDebug() << "OSGCamera::updateCameraFOV";
|
// qDebug() << "OSGCamera::updateCameraFOV";
|
||||||
double fovy, ar, zn, zf;
|
double fovy, ar, zn, zf;
|
||||||
|
|
||||||
@ -351,7 +332,8 @@ public:
|
|||||||
|
|
||||||
camera->getProjectionMatrixAsPerspective(fovy, ar, zn, zf);
|
camera->getProjectionMatrixAsPerspective(fovy, ar, zn, zf);
|
||||||
|
|
||||||
ar = static_cast<double>(width) / static_cast<double>(height);
|
osg::Viewport *viewport = camera->getViewport();
|
||||||
|
ar = static_cast<double>(viewport->width()) / static_cast<double>(viewport->height());
|
||||||
camera->setProjectionMatrixAsPerspective(fovy, ar, zn, zf);
|
camera->setProjectionMatrixAsPerspective(fovy, ar, zn, zf);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -404,6 +386,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
qreal fieldOfView;
|
qreal fieldOfView;
|
||||||
|
bool fovDirty;
|
||||||
|
|
||||||
OSGNode *sceneData;
|
OSGNode *sceneData;
|
||||||
|
|
||||||
@ -430,12 +413,6 @@ public:
|
|||||||
QVector3D attitude;
|
QVector3D attitude;
|
||||||
QVector3D position;
|
QVector3D position;
|
||||||
|
|
||||||
bool sizeDirty;
|
|
||||||
int x;
|
|
||||||
int y;
|
|
||||||
int width;
|
|
||||||
int height;
|
|
||||||
|
|
||||||
osg::ref_ptr<osg::Camera> camera;
|
osg::ref_ptr<osg::Camera> camera;
|
||||||
osg::ref_ptr<CameraUpdateCallback> cameraUpdateCallback;
|
osg::ref_ptr<CameraUpdateCallback> cameraUpdateCallback;
|
||||||
|
|
||||||
@ -478,23 +455,13 @@ qreal OSGCamera::fieldOfView() const
|
|||||||
return h->fieldOfView;
|
return h->fieldOfView;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ! Camera vertical field of view in degrees
|
// Camera vertical field of view in degrees
|
||||||
void OSGCamera::setFieldOfView(qreal arg)
|
void OSGCamera::setFieldOfView(qreal arg)
|
||||||
{
|
{
|
||||||
if (h->fieldOfView != arg) {
|
if (h->fieldOfView != arg) {
|
||||||
h->fieldOfView = arg;
|
h->fieldOfView = arg;
|
||||||
h->sizeDirty = true;
|
h->fovDirty = true;
|
||||||
emit fieldOfViewChanged(fieldOfView());
|
emit fieldOfViewChanged(fieldOfView());
|
||||||
|
|
||||||
// it should be a queued call to OSGCameraRenderer instead
|
|
||||||
/*if (h->viewer.get()) {
|
|
||||||
h->viewer->getCamera()->setProjectionMatrixAsPerspective(
|
|
||||||
h->fieldOfView,
|
|
||||||
qreal(h->currentSize.width())/h->currentSize.height(),
|
|
||||||
1.0f, 10000.0f);
|
|
||||||
}*/
|
|
||||||
|
|
||||||
// updateFrame();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -619,23 +586,6 @@ void OSGCamera::setLogarithmicDepthBuffer(bool enabled)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void OSGCamera::setViewport(int x, int y, int width, int height)
|
|
||||||
{
|
|
||||||
// qDebug() << "OSGCamera::setViewport" << x << y << width << "x" << heigth;
|
|
||||||
if (width <= 0 || height <= 0) {
|
|
||||||
qWarning() << "OSGCamera::setViewport - invalid size" << width << "x" << height;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (h->x != x || h->y != y || h->width != width || h->height != height) {
|
|
||||||
qWarning() << "OSGCamera::setViewport" << width << "x" << height;
|
|
||||||
h->x = x;
|
|
||||||
h->y = y;
|
|
||||||
h->width = width;
|
|
||||||
h->height = height;
|
|
||||||
h->sizeDirty = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool OSGCamera::attach(osgViewer::View *view)
|
bool OSGCamera::attach(osgViewer::View *view)
|
||||||
{
|
{
|
||||||
return h->attach(view);
|
return h->attach(view);
|
||||||
|
@ -117,8 +117,6 @@ public:
|
|||||||
bool logarithmicDepthBuffer();
|
bool logarithmicDepthBuffer();
|
||||||
void setLogarithmicDepthBuffer(bool enabled);
|
void setLogarithmicDepthBuffer(bool enabled);
|
||||||
|
|
||||||
void setViewport(int x, int y, int width, int height);
|
|
||||||
|
|
||||||
virtual bool attach(osgViewer::View *view);
|
virtual bool attach(osgViewer::View *view);
|
||||||
virtual bool detach(osgViewer::View *view);
|
virtual bool detach(osgViewer::View *view);
|
||||||
|
|
||||||
|
@ -173,7 +173,6 @@ public:
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (camera) {
|
if (camera) {
|
||||||
camera->setViewport(0, 0, self->width(), self->height());
|
|
||||||
camera->attach(view);
|
camera->attach(view);
|
||||||
} else {
|
} else {
|
||||||
qWarning() << "OSGViewport::attach - no camera!";
|
qWarning() << "OSGViewport::attach - no camera!";
|
||||||
@ -384,7 +383,10 @@ public:
|
|||||||
// add the screen capture handler
|
// add the screen capture handler
|
||||||
// view->addEventHandler(new osgViewer::ScreenCaptureHandler);
|
// view->addEventHandler(new osgViewer::ScreenCaptureHandler);
|
||||||
|
|
||||||
view->getCamera()->setGraphicsContext(createGraphicsContext());
|
osg::GraphicsContext *gc = createGraphicsContext();
|
||||||
|
osg::Camera *camera = view->getCamera();
|
||||||
|
camera->setGraphicsContext(gc);
|
||||||
|
camera->setViewport(new osg::Viewport(0, 0, gc->getTraits()->width, gc->getTraits()->height));
|
||||||
|
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
@ -548,8 +550,9 @@ public:
|
|||||||
QOpenGLFramebufferObject *createFramebufferObject(const QSize &size)
|
QOpenGLFramebufferObject *createFramebufferObject(const QSize &size)
|
||||||
{
|
{
|
||||||
qDebug() << "ViewportRenderer::createFramebufferObject" << size;
|
qDebug() << "ViewportRenderer::createFramebufferObject" << size;
|
||||||
if (h->camera) {
|
if (h->view.valid()) {
|
||||||
h->camera->setViewport(0, 0, size.width(), size.height());
|
h->view->getCamera()->getGraphicsContext()->resized(0, 0, size.width(), size.height());
|
||||||
|
h->view->getEventQueue()->windowResize(0, 0, size.width(), size.height());
|
||||||
}
|
}
|
||||||
|
|
||||||
QOpenGLFramebufferObjectFormat format;
|
QOpenGLFramebufferObjectFormat format;
|
||||||
@ -583,7 +586,6 @@ QtKeyboardMap OSGViewport::Hidden::keyMap = QtKeyboardMap();
|
|||||||
|
|
||||||
/* class OSGViewport */
|
/* class OSGViewport */
|
||||||
|
|
||||||
|
|
||||||
OSGViewport::OSGViewport(QQuickItem *parent) : QQuickFramebufferObject(parent), h(new Hidden(this))
|
OSGViewport::OSGViewport(QQuickItem *parent) : QQuickFramebufferObject(parent), h(new Hidden(this))
|
||||||
{
|
{
|
||||||
qDebug() << "OSGViewport::OSGViewport";
|
qDebug() << "OSGViewport::OSGViewport";
|
||||||
@ -719,10 +721,10 @@ QSGNode *OSGViewport::updatePaintNode(QSGNode *node, QQuickItem::UpdatePaintNode
|
|||||||
|
|
||||||
QPointF OSGViewport::mousePoint(QMouseEvent *event)
|
QPointF OSGViewport::mousePoint(QMouseEvent *event)
|
||||||
{
|
{
|
||||||
// qreal x = 0.01 * (event->x() - self->width() / 2);
|
// qreal x = 2.0 * (event->x() - width() / 2) / width();
|
||||||
// qreal y = 0.01 * (event->y() - self->height() / 2);
|
// qreal y = 2.0 * (event->y() - height() / 2) / height();
|
||||||
qreal x = 2.0 * (event->x() - width() / 2) / width();
|
qreal x = event->x();
|
||||||
qreal y = 2.0 * (event->y() - height() / 2) / height();
|
qreal y = event->y();
|
||||||
|
|
||||||
return QPointF(x, y);
|
return QPointF(x, y);
|
||||||
}
|
}
|
||||||
|
@ -104,20 +104,7 @@ GraphicsWindowQt::GraphicsWindowQt(osg::GraphicsContext::Traits *traits) :
|
|||||||
{
|
{
|
||||||
qDebug() << "GraphicsWindowQt::GraphicsWindowQt";
|
qDebug() << "GraphicsWindowQt::GraphicsWindowQt";
|
||||||
_traits = traits;
|
_traits = traits;
|
||||||
|
|
||||||
init();
|
init();
|
||||||
|
|
||||||
if (valid()) {
|
|
||||||
setState(new osg::State);
|
|
||||||
getState()->setGraphicsContext(this);
|
|
||||||
|
|
||||||
if (_traits.valid() && _traits->sharedContext.valid()) {
|
|
||||||
getState()->setContextID(_traits->sharedContext->getState()->getContextID());
|
|
||||||
incrementContextIDUsageCount(getState()->getContextID());
|
|
||||||
} else {
|
|
||||||
getState()->setContextID(osg::GraphicsContext::createNewContextID());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
GraphicsWindowQt::~GraphicsWindowQt()
|
GraphicsWindowQt::~GraphicsWindowQt()
|
||||||
@ -140,6 +127,20 @@ void GraphicsWindowQt::init()
|
|||||||
// if ( !parent )
|
// if ( !parent )
|
||||||
// parent = windowData ? windowData->_parent : NULL;
|
// parent = windowData ? windowData->_parent : NULL;
|
||||||
|
|
||||||
|
|
||||||
|
setState(new osg::State);
|
||||||
|
getState()->setGraphicsContext(this);
|
||||||
|
|
||||||
|
if (_traits.valid() && _traits->sharedContext.valid()) {
|
||||||
|
getState()->setContextID(_traits->sharedContext->getState()->getContextID());
|
||||||
|
incrementContextIDUsageCount(getState()->getContextID());
|
||||||
|
} else {
|
||||||
|
getState()->setContextID(osg::GraphicsContext::createNewContextID());
|
||||||
|
}
|
||||||
|
|
||||||
|
// make sure the event queue has the correct window rectangle size and input range
|
||||||
|
getEventQueue()->syncWindowRectangleWithGraphicsContext();
|
||||||
|
|
||||||
_initialized = true;
|
_initialized = true;
|
||||||
|
|
||||||
_valid = _initialized;
|
_valid = _initialized;
|
||||||
@ -244,8 +245,8 @@ bool GraphicsWindowQt::realizeImplementation()
|
|||||||
|
|
||||||
_realized = true;
|
_realized = true;
|
||||||
|
|
||||||
//// make sure the event queue has the correct window rectangle size and input range
|
// make sure the event queue has the correct window rectangle size and input range
|
||||||
// getEventQueue()->syncWindowRectangleWithGraphcisContext();
|
getEventQueue()->syncWindowRectangleWithGraphicsContext();
|
||||||
|
|
||||||
// make this window's context not current
|
// make this window's context not current
|
||||||
// note: this must be done as we will probably make the context current from another thread
|
// note: this must be done as we will probably make the context current from another thread
|
||||||
|
Loading…
x
Reference in New Issue
Block a user