Best way to approach making a 2D graphics window (probably in a grid)?
-
I have done (and plan to do more) research about this on my own using the Qt documentation but I also want to get the opinions of more experienced people, so sorry if it seems like I'm not trying to figure this out on my own, I just want some tips.
I wish to make a simulation program that simulates vehicles driving around a preset area, and essentially is doing things like seeing if the vehicles collide or if certain areas get very crowded. The actually logic behind this I am fine with figuring out, its displaying it that I am a little unsure on. I would like to essentially have a grid with transparent cells and an image behind the cells that is the actually area the vehicles will be going. I will then represent the vehicles as different colored squares or rectangles ( 1 cell or 2) and have them move around by just coloring in some of the transparent cells with a solid color at a time. That is the bare minimum of what I would like to achieve and I think it is possible using some combination of QLabel and possibly QGridLayout.
However, if possible and I have the time I am also interested in perhaps the objects not being limited to a grid and instead just using raw coordinates so they could be anywhere on within the designated area. Additionally, I would like to try to have the vehicles actually represented by small sprites (that I would make on my own), and able to move diagonally at different angles that 45 degrees (which would be the limitation if I used a grid). Not all of this has to happen but I would like to have as much of it as possible.
So basically, I just want to see if anyone has done something like this before using Qt and has any advice to give on the best way to approach it. The grid solution I listed should work but I know its not that pretty.
Thanks for your continued support.
-
Hi,
Maybe the Colliding Mice example might be of interest
-
As far as I understand the description there are 2 problems in the question:
1.) Visualization. I would use QGraphicsView/QGraphicsScene approach. It can even help you to determine collision detection, But you can use OpenGl, VTK or any other visualization including QPainter.- Collision detection. This is not a simple task to implement efficiently.
As I said you can move your objects, then check if collision happens with QGrapicsItem.
The easiest to implement, and probably more reliable solution would be to use Bullet library (google it).
Large improvement could be made if you use priority queue, which would provide you linear time performance.
- Collision detection. This is not a simple task to implement efficiently.
-
Thank you for the ideas. I will keep this in mind.