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
@ -73,15 +73,10 @@ public:
|
||||
{
|
||||
fieldOfView = 90.0;
|
||||
|
||||
first = true;
|
||||
first = true;
|
||||
|
||||
dirty = false;
|
||||
|
||||
sizeDirty = false;
|
||||
x = 0;
|
||||
y = 0;
|
||||
width = 0;
|
||||
height = 0;
|
||||
dirty = false;
|
||||
fovDirty = false;
|
||||
}
|
||||
|
||||
~Hidden()
|
||||
@ -195,9 +190,10 @@ public:
|
||||
logDepthBuffer->install(camera);
|
||||
}
|
||||
|
||||
dirty = true;
|
||||
sizeDirty = true;
|
||||
dirty = true;
|
||||
fovDirty = true;
|
||||
updateCamera();
|
||||
updateAspectRatio();
|
||||
}
|
||||
|
||||
void detachCamera(osg::Camera *camera)
|
||||
@ -220,9 +216,6 @@ public:
|
||||
delete logDepthBuffer;
|
||||
logDepthBuffer = NULL;
|
||||
}
|
||||
|
||||
// reset viewport
|
||||
x = y = width = height = 0;
|
||||
}
|
||||
|
||||
void attachManipulator(osgViewer::View *view)
|
||||
@ -311,31 +304,19 @@ public:
|
||||
|
||||
void updateCamera()
|
||||
{
|
||||
if (first) {
|
||||
first = false;
|
||||
updateCameraFOV();
|
||||
}
|
||||
updateCameraSize();
|
||||
updateCameraFOV();
|
||||
if (manipulatorMode == User) {
|
||||
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()
|
||||
{
|
||||
if (!fovDirty || !camera.valid()) {
|
||||
return;
|
||||
}
|
||||
fovDirty = false;
|
||||
|
||||
// qDebug() << "OSGCamera::updateCameraFOV";
|
||||
double fovy, ar, zn, zf;
|
||||
|
||||
@ -351,7 +332,8 @@ public:
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
@ -404,6 +386,7 @@ public:
|
||||
}
|
||||
|
||||
qreal fieldOfView;
|
||||
bool fovDirty;
|
||||
|
||||
OSGNode *sceneData;
|
||||
|
||||
@ -430,12 +413,6 @@ public:
|
||||
QVector3D attitude;
|
||||
QVector3D position;
|
||||
|
||||
bool sizeDirty;
|
||||
int x;
|
||||
int y;
|
||||
int width;
|
||||
int height;
|
||||
|
||||
osg::ref_ptr<osg::Camera> camera;
|
||||
osg::ref_ptr<CameraUpdateCallback> cameraUpdateCallback;
|
||||
|
||||
@ -478,23 +455,13 @@ qreal OSGCamera::fieldOfView() const
|
||||
return h->fieldOfView;
|
||||
}
|
||||
|
||||
// ! Camera vertical field of view in degrees
|
||||
// Camera vertical field of view in degrees
|
||||
void OSGCamera::setFieldOfView(qreal arg)
|
||||
{
|
||||
if (h->fieldOfView != arg) {
|
||||
h->fieldOfView = arg;
|
||||
h->sizeDirty = true;
|
||||
h->fovDirty = true;
|
||||
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)
|
||||
{
|
||||
return h->attach(view);
|
||||
|
@ -117,8 +117,6 @@ public:
|
||||
bool logarithmicDepthBuffer();
|
||||
void setLogarithmicDepthBuffer(bool enabled);
|
||||
|
||||
void setViewport(int x, int y, int width, int height);
|
||||
|
||||
virtual bool attach(osgViewer::View *view);
|
||||
virtual bool detach(osgViewer::View *view);
|
||||
|
||||
|
@ -173,7 +173,6 @@ public:
|
||||
return false;
|
||||
}
|
||||
if (camera) {
|
||||
camera->setViewport(0, 0, self->width(), self->height());
|
||||
camera->attach(view);
|
||||
} else {
|
||||
qWarning() << "OSGViewport::attach - no camera!";
|
||||
@ -384,7 +383,10 @@ public:
|
||||
// add the screen capture handler
|
||||
// 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;
|
||||
}
|
||||
@ -548,8 +550,9 @@ public:
|
||||
QOpenGLFramebufferObject *createFramebufferObject(const QSize &size)
|
||||
{
|
||||
qDebug() << "ViewportRenderer::createFramebufferObject" << size;
|
||||
if (h->camera) {
|
||||
h->camera->setViewport(0, 0, size.width(), size.height());
|
||||
if (h->view.valid()) {
|
||||
h->view->getCamera()->getGraphicsContext()->resized(0, 0, size.width(), size.height());
|
||||
h->view->getEventQueue()->windowResize(0, 0, size.width(), size.height());
|
||||
}
|
||||
|
||||
QOpenGLFramebufferObjectFormat format;
|
||||
@ -583,7 +586,6 @@ QtKeyboardMap OSGViewport::Hidden::keyMap = QtKeyboardMap();
|
||||
|
||||
/* class OSGViewport */
|
||||
|
||||
|
||||
OSGViewport::OSGViewport(QQuickItem *parent) : QQuickFramebufferObject(parent), h(new Hidden(this))
|
||||
{
|
||||
qDebug() << "OSGViewport::OSGViewport";
|
||||
@ -719,10 +721,10 @@ QSGNode *OSGViewport::updatePaintNode(QSGNode *node, QQuickItem::UpdatePaintNode
|
||||
|
||||
QPointF OSGViewport::mousePoint(QMouseEvent *event)
|
||||
{
|
||||
// qreal x = 0.01 * (event->x() - self->width() / 2);
|
||||
// qreal y = 0.01 * (event->y() - self->height() / 2);
|
||||
qreal x = 2.0 * (event->x() - width() / 2) / width();
|
||||
qreal y = 2.0 * (event->y() - height() / 2) / height();
|
||||
// qreal x = 2.0 * (event->x() - width() / 2) / width();
|
||||
// qreal y = 2.0 * (event->y() - height() / 2) / height();
|
||||
qreal x = event->x();
|
||||
qreal y = event->y();
|
||||
|
||||
return QPointF(x, y);
|
||||
}
|
||||
|
@ -104,20 +104,7 @@ GraphicsWindowQt::GraphicsWindowQt(osg::GraphicsContext::Traits *traits) :
|
||||
{
|
||||
qDebug() << "GraphicsWindowQt::GraphicsWindowQt";
|
||||
_traits = traits;
|
||||
|
||||
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()
|
||||
@ -140,6 +127,20 @@ void GraphicsWindowQt::init()
|
||||
// if ( !parent )
|
||||
// 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;
|
||||
|
||||
_valid = _initialized;
|
||||
@ -244,8 +245,8 @@ bool GraphicsWindowQt::realizeImplementation()
|
||||
|
||||
_realized = true;
|
||||
|
||||
//// make sure the event queue has the correct window rectangle size and input range
|
||||
// getEventQueue()->syncWindowRectangleWithGraphcisContext();
|
||||
// make sure the event queue has the correct window rectangle size and input range
|
||||
getEventQueue()->syncWindowRectangleWithGraphicsContext();
|
||||
|
||||
// make this window's context not current
|
||||
// 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