April 27th, 2013, 09:44 AM
Some advice on graphics
Well I'm a student at university and I'm planning my final year project which will be a simulation of the Earth and its atmosphere and how objects interact with it. I think I'm ok with the physics side of things as this will simply be a matter of vector calculations etc. But I want to be able to represent the simulation in 2D graphics. For example a window that shows a ballistic trajectory through the atmosphere etc.
My question is, what is the best method of creating these graphics? Because the window would need to update quite quickly to essentially create a real time video of the simulation.
I have some basic experience with PyGame but I think that the origin system being based on the top left of the screen (y co-ordinates increase in value with decreased height) will create a lot of problems. I understand that I could convert all the co-ordinates into PyGame co-ordinates but this isn't exactly an elegant solution.
Is there any more suitable module that could do what I need it to?
April 27th, 2013, 10:27 AM
The standard in 2d graphics is the top left corner. I felt this a bit strange at first but honestly you do get used to it. It really shouldn't complicate your problem very much.
That said, you could just draw everything to a surface with respect to the way you envision the coordinate system, and then before drawing that surface to the screen use pygame.transform.flip to flip it.
Either way it shouldn't be a huge hurtle.
April 27th, 2013, 10:36 AM
I see. I think I'll go with your suggestion of using the transform.flip() function. Thanks for that.
PyGame does seem to be the best option because it has a big community and plenty of documentation. Where as pyglet and a lot of the other alternatives have almost no documentation.
Another question. I want to simulate the atmosphere getting thinner with height. So essentially a density gradient. What's the best way of showing this graphically in pyGame? Would it be by simply creating an image and importing it? Or is there some way to do it within pyGame?
It would also be cool to have the ability to zoom in on a point, but I can see this getting complicated very quickly. Would it simply be a matter of enlarging the surfaces that I've drawn and fixing their co-ordinates? For example if I had 2 circles drawn to the screen with radius 50 each and wanted 2x zoom. Would I just need to enlarge them to radius 100 and move their co-ordinates so that the spacing remains the same?
Or is there a better way of doing it?
Thanks again for the reply
April 27th, 2013, 10:45 AM
For zooming, again pygame.transform most likely holds the answers but it depends. If you just want the image on the screen to appear bigger that is one thing, but if you want something that looked like a single pixel to look like a circle when you zoom in that is a different story.
In the case of the latter you will probably need to keep track of some scale factor. Again it shouldn't be impossible. It will just take some messing around until you get it to work the way you envision.
For the question of the gradient again not sure quite what you are going for. You could easily create a gradient through a variety of methods (blitting varying transparencies of black on the screen; blitting a prerendered gradient over the top of your image; etc).
April 27th, 2013, 11:38 AM
I think open_gl uses a right handed coordinate system. The transformations are easy. Spend a little time studying homogeneous coordinates.
In other words, (0,0) transforms to (0,1) and (1,1)->(1,0).
+-----+ +------+ +-----+
|0 0 1| |1 0 0| |0 1 1|
|1 1 1| * |0 _1 0| = |1 0 1|
+-----+ |0 1 1| +-----+
((0,0) in the usual Cartesian system of algebra maps to (0,1) screen coordinate (left, bottom),
(1,1) Cartesian -> (1,0) ie. (right, top) on the screen.)
I've set this up so that for the matrix mulltiplication
A are the world space coordinates, listed as each row representing a point,
B is the transformation matrix,
and C are the row-wise screen coordinate points.
What's with the extra dimension?
It accounts for a constant. Let W represent world coordinate, S the screen coordinate.
(W, 1) * |1 0 0| = (Wx -Wy+1 1) = (S, 1)
|0 _1 0|
|0 1 1|
[/code] are essential for python code and Makefiles!
April 27th, 2013, 11:40 AM
You covered what I was trying to say. The atmosphere gets thinner at higher altitudes and I wanted to show this in the graphic. So using transparency will cover it.
Thanks again man, much appreciated. Once I get the project going I'll be updating my progress here as much as the university guidelines allow me to.
Afterward I'll try and convert it into a game of some kind so that people can play around with it.