Does pyGame do 3d?

前端 未结 11 655
醉话见心
醉话见心 2020-12-29 21:45

I can\'t seem to find the answer to this question anywhere. I realise that you have to use pyOpenGL or something similar to do openGL stuff, but I was wondering if its possi

相关标签:
11条回答
  • 2020-12-29 21:52

    Pygame was never originally meant to do 3d, but there is a way you can do 3d with any 2d graphics library. All you need is the following function, which converts 3d points to 2d points, which allows you to make any 3d shape by just drawing lines on a screen.

    def convert_to_2d(point=[0,0,0]):
        return [point[0]*(point[2]*.3),point[1]*(point[2]*.3)]
    

    This is called pseudo 3d, or 2.5d. This can be done, but may be slow, and is extremely difficult to do, so it is suggested that you use a library meant for 3d.

    0 讨论(0)
  • 2020-12-29 21:52

    You can make like this :

    def convert_2d(x, y, z, horizon):
        d = 1 - (z/horizon)
        return x*d, y*d
    def draw_list_of_points(lst):
        '''Assume that lst is a list of 3 dimentionnal points like [(0, 0, 0), (1, 6, 2)...
        Let's take 200 for the horizon, it can give us a pretty clean 3D''' 
        for x, y, z in lst:
            pygame.draw.circle(screen, color, convert_2d(x, y, z, 200), 1)
    
    

    But it's not very fast. If you want fast try to implement in C++/SDL2 or C. Pygame is not very good for 3d graphics.

    0 讨论(0)
  • 2020-12-29 21:53

    Python Soya can render 3d graphics on pygame surfaces.

    0 讨论(0)
  • 2020-12-29 21:53

    Pygame is just a library for changing the color of pixels (and some other useful stuff for programming games). You can do this by blitting images to the screen or directly setting the colors of pixels.

    Because of this, it is easy to write 2D games with pygame, as the above is all you really need. But a 3D game is just some 3D objects 'squashed' (rendered) into 2D so that it can be displayed on the screen. So, to make a 3D game using only pygame, you would have handle this rendering by yourself, including all the complex matrix maths necessary.

    Not only would this run slowly because of the immense processing power involved in this, but it would require you to write a massive 3D rendering/rasterisation engine. And because of python being interpreted it would be even slower. The correct approach would be to have this process run on the GPU using (Py)opengl.

    So, yes it is technically possible to do 3D using only pygame, but definitely not recommended. I would suggest you learn Panda3D or some similar 3D engine.

    0 讨论(0)
  • 2020-12-29 21:56

    If you want 3D projection functions and all of that stuff you'll have to use a 3D API but if you want to do a basic 3D look I recommend Peter's Website tutorial: http://www.petercollingridge.co.uk/pygame-3d-graphics-tutorial

    0 讨论(0)
  • 2020-12-29 21:56

    What you see as a 3D is actually a 2D game. After all, you are watching your screen, which (normally ;) ) is 2D. The virtual world (which is in 3D) is projected onto a plane, which is then shown on your screen. Our brains then convert that 2D image into a 3D one (like they do with the image of our eyes), making it look like it's 3D.

    So it's relatively easy to make a 3D game: you just create a virtual world using a multidimensional matrix and then project it each loop on a 2D plane, which you display on your screen.

    One tutorial that you can put on your way to 3D programs (using pygame) is this one .

    0 讨论(0)
提交回复
热议问题