我正在尝试 OpenGL ES 2.0 的 hello 三角形示例。我正在使用 Qt,因此我创建了一个 QGraphicsScene 并将该代码添加为 QGraphicsItem。它绘制正确,但我无法正确获取边界矩形。三角形顶点是
GLfloat afVertices[] =
{-0.4f,-0.4f,0.0f,
0.4f ,-0.4f,0.0f,
0.0f ,0.4f ,0.0f};
,我的视口是 glViewport(0, 0, 800, 480);
正确的边界矩形坐标是什么?
我将视口设置为 QGLWidget。 QGraphicsItem 的问题是我必须重新实现该项目的边界矩形,如果我只是使用
QRectF myGraphicsItem::boundingRect() const
{
return QGraphicsItem::boundingRect();
}
它,就会显示 对 `QGraphicsItem::boundingRect() const' 的未定义引用
我最初使用过
QRectF myGraphicsItem::boundingRect() const
{
return QRectF(-0.4, -0.4, 0.8, 0.8);
}
,但是结果是一个非常小的边界框。当我通过反复试验使用像 QRectf(300, 200, 200, 200)
这样的值时创建了看似正确的值 - 这太“手动” - 所以我想知道也许有一些我不知道的一种坐标对应或变换。
I am trying the hello triangle example of OpenGL ES 2.0. I am using Qt, so I created a QGraphicsScene and added that code as a QGraphicsItem. It draws correctly, but I cannot get the bounding rectangle correctly. The triangle vertices are
GLfloat afVertices[] =
{-0.4f,-0.4f,0.0f,
0.4f ,-0.4f,0.0f,
0.0f ,0.4f ,0.0f};
and my viewport is glViewport(0, 0, 800, 480);
What would be the correct bounding rect coordinates?
I set the viewport to a QGLWidget. The thing with the QGraphicsItem is that I have to re-implement the bounding rectangle of the item and if I just use
QRectF myGraphicsItem::boundingRect() const
{
return QGraphicsItem::boundingRect();
}
it says undefined reference to `QGraphicsItem::boundingRect() const'
I had originally used
QRectF myGraphicsItem::boundingRect() const
{
return QRectF(-0.4, -0.4, 0.8, 0.8);
}
but the result is a very small bounding box. The seemingly correct one was created when I was used values like QRectf(300, 200, 200, 200)
by trial and error -which is too 'manual'-, so I was wondering maybe there is some kind of coordinate correspondence or transformation that I'm unaware of.
发布评论
评论(3)
QGraphicsItem::boundingRect()
是一个纯虚函数。因此,没有实施。您必须提供自己的实现。根据你的顶点,可能QGraphicsItem::boundingRect()
is a pure virtual function. Thus, there is no implementation. You must provide your own implementation. Based upon your vertices, probably我不确定我是否遵循,如果您使用 QGraphicsItem(带或不带 OpenGL 视口),您通常会使用 QGraphicsItem::boundingRect() 获取边界矩形?
I'm not sure I follow, if you're using a QGraphicsItem (with or without an OpenGL viewport), you would typically use QGraphicsItem::boundingRect() to get the bounding rectangle?
我会这样做(用Python):
I would do (in Python):