PDA

View Full Version : How to Implement Hittest with QGLWidget ???



rajji_saini
7th September 2010, 21:40
Hi,

I am trying to implement an OpenGL(QGLWidget) widget and need to implement hittest for the features that need to be included.

I am little confused where to start ... I have the QGLWidget and need help with implementation of hittest as I am not very familiar with it.

I would really appreciate any help related to this or any guidance on how to start it ??

Regards,
Raj

wysota
7th September 2010, 22:43
I would start with reimplementing mousePressEvent :) As for the hittest itself, take a look at NeHe lessons, as far as I remember it's described there how to project the cursor into 3D space.

rajji_saini
7th September 2010, 23:10
Heheheh ... Thanks Wysota.
I actually need a head start on hittest logic.
I was hoping if Qt by default provided something similar.

Regards,
Raj

wysota
7th September 2010, 23:15
Qt3D might (seems that QGLCamera might be what you're after), the basic flavour of Qt doesn't as it doesn't have any control (or awareness) over your projection matrix.

rajji_saini
7th September 2010, 23:23
OK. How about, if I was using a regular QGraphicsView and Scene to add items.
Is there something available for that ??

Thanks & Regards,
Raj

SixDegrees
7th September 2010, 23:41
QGraphicsView/Scene/Item is strictly 2 dimensional, but it does offer collision detection if that's what you're looking for.

There has been some complaining here about performance of this algorithm, however.

rajji_saini
7th September 2010, 23:47
Yup, thats exactly what I am looking for ... I do not care about the 3D.
It will be great if you could please provide me some info related to the collision detection and its pros & cons so that I will have a better idea.


Regards,
Raj

wysota
8th September 2010, 00:03
Yup, thats exactly what I am looking for ... I do not care about the 3D.
It will be great if you could please provide me some info related to the collision detection and its pros & cons so that I will have a better idea.

What is it exactly that you want to do? Why were you asking about QGLWidget?

rajji_saini
8th September 2010, 00:24
Here is what I am trying ....

MyGraphicsView::MyGraphicsView(QWidget *parent):QGraphicsView(parent)
{
myScene = new QGraphicsScene(this);
setScene(myScene);
setViewport(new GLWidget(this));

}
Here I am setting my custom QGLWidget as as viewport of my QGraphicsView.
So this is where I need help with.

Regards,
Raj

wysota
8th September 2010, 00:49
I mean what is your ultimate goal of doing all that? The GL viewport doesn't change anything if you are using Graphics View, it just gives you hardware acceleration without changing the API layer. So collision detection is still done by Graphics View and not QGLWidget. For collision detection in the scene see the family of QGraphicsScene::items() and QGraphicsScene::collidingItems() methods.

rajji_saini
8th September 2010, 01:22
Yes, I am using QGLWidget on QGraphicsView for hardware acceleration.
I am trying to create a map control with very high refresh rate something similar to TomTom device in a moving vehicle(i.e a fast moving map). But it supports interaction with items on the map.

So my confusion was that once I set the QGLWidget as viewport how is it going to change the behavior ... May be I didnt put my question properly in the beginning :(
As you are suggested that Collision detection is still done by QGraphicsView. I will go ahead and try it out.

Thanks for your help.
Regards,
Raj