使用 Python 的 3d 游戏,从无到有
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4303851/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
3d game with Python, starting from nothing
提问by Not Available
So we want to program a 3d game for school, we can probably use blender for the 3d models, however we are totally clueless as to how to use them in a game/application.
所以我们想为学校编写一个 3d 游戏,我们可能可以将 Blender 用于 3d 模型,但是我们完全不知道如何在游戏/应用程序中使用它们。
Are there any recommended guides/documents we should read on general 3d game programming and perhaps python specific stuff.
是否有任何我们应该阅读的关于一般 3d 游戏编程以及 Python 特定内容的推荐指南/文档。
We are also possibly considering programming it in C++ but for now I think it's easier to use Python as we can fully focus on the 3d mechanics that way.
我们也可能考虑用 C++ 编程,但现在我认为使用 Python 更容易,因为我们可以完全专注于 3d 机制。
采纳答案by Rob Vermeulen
There's Pygame:A game framework for the Python language. If you need to know the basics for game development (engine, flow, ui, mathematics), this framework with all its examples will help you a lot. This won't take you by the hand and guide you step by step through game-development, but if you need a reference and a decent framework, than this is a good start.
有Pygame:Python 语言的游戏框架。如果您需要了解游戏开发的基础知识(引擎、流程、用户界面、数学),这个框架及其所有示例将对您有很大帮助。这不会带你一步一步地指导你完成游戏开发,但如果你需要一个参考和一个像样的框架,那么这是一个好的开始。
There's also PyOpenGL: The official Python wrapper for OpenGL programming. Again with lots of programming examples in the field and tons of code snippets on how to use 3d models and the likes. Can be used together with PyGame.
还有PyOpenGL:用于 OpenGL 编程的官方 Python 包装器。再次提供了大量该领域的编程示例以及关于如何使用 3d 模型等的大量代码片段。可以与 PyGame 一起使用。
But you should startby familiarizing yourself with some 3D basics. Look around at the GameDev.netsite. Learn a thing or two about matrices (and perhaps quaternions). There are lots of beginners tutorialsand references available to get you started.
但是您应该先熟悉一些 3D 基础知识。环顾GameDev.net站点。学习一两件事关于矩阵(也许还有四元数)。有很多初学者教程和参考资料可供您入门。
edit: I almost forgot: there's also Panda3Dwith extensive scripting possibilities for Python. Maybe that'll offer a higher level of game development.
编辑:我差点忘了:还有Panda3D为 Python 提供了广泛的脚本编写可能性。也许这会提供更高水平的游戏开发。
回答by Kos
回答by Blam
回答by Jakob Bowyer
If you want to write a 3D game you might want to start by understanding the basics of programming and computer science. Starting with the top and learning a language, then find yourself a good graphics library for example Panda, Pygame are all good choices, then there are other parts to consider like networking with twisted for example or a physics engine. It might also be a good choice to consider using a working engine like the unreal engine as often game designers get too wrapped up in game mechanics and not the game itself
如果您想编写 3D 游戏,您可能需要先了解编程和计算机科学的基础知识。从顶部开始学习一门语言,然后为自己找到一个好的图形库,例如 Panda,Pygame 都是不错的选择,然后还有其他部分需要考虑,例如使用 Twisted 联网或物理引擎。考虑使用像虚幻引擎这样的工作引擎也可能是一个不错的选择,因为游戏设计师通常过于关注游戏机制而不是游戏本身
回答by Robert
I would implement the time-critical stuff as 3D and its object handling + rendering in raw C/C++ and let an embedded Python with external modules handle the game logic (object movement, object properties, scripting and so on).
我会将时间关键的东西实现为 3D 及其对象处理 + 原始 C/C++ 渲染,并让带有外部模块的嵌入式 Python 处理游戏逻辑(对象移动、对象属性、脚本等)。
回答by Unreason
You should be aware that 3D game consists of
您应该知道 3D 游戏包括
- animated 3D models
- 3D environment (including NPCs and objects)
- simulation of interaction between the environment and the models (game logic and game mechanics)
- user interface (starting, saving and game settings)
- 动画 3D 模型
- 3D 环境(包括 NPC 和物体)
- 模拟环境和模型之间的交互(游戏逻辑和游戏机制)
- 用户界面(启动、保存和游戏设置)
The game logic and mechanics is going to usually the biggest and most complicated part and you should try to wrap your head against that first.
游戏逻辑和机制通常是最大和最复杂的部分,你应该首先尝试解决这个问题。
Modeling 3D objects and environment should be much easier after that.
之后对 3D 对象和环境进行建模应该会容易得多。
回答by Jonathan Hartley
An alternative to PyGame, which I personally prefer, is pyglet. http://pyglet.org
我个人更喜欢 PyGame 的替代品是 pyglet。 http://pyglet.org
回答by OverloadProjekt Developer
It's quit easy to code simple 3D games. The position of any object on the screen can always be calculated as simply as:
编写简单的 3D 游戏非常容易。屏幕上任何对象的位置总是可以简单地计算为:
position = (x/z*fov,x/z*fov)
where xand zare both horizontal axis and fovis the player's field of view, in [radians/degrees/pixels/...].
其中x和z都是水平轴,fov是玩家的视野,单位为 [弧度/度/像素/...]。
When you rotate around, the word is rotating not you. It means that you are always looking against positive z. Quaternions is the best way to rotate the world around you.
当你旋转时,这个词在旋转而不是你。这意味着你总是在反对正 z。四元数是旋转您周围世界的最佳方式。
Ps. use vertexarrays or arrays to for the fastest possible 3d graphics
附言。使用顶点数组或数组来获得尽可能快的 3d 图形

