用于游戏开发的 2D 矢量建模
制作我的小行星克隆(用 C 语言) 我相当喜欢基于矢量的实体,但我只是将它们编码为 x,y 点数组。对于像 Asteroids 这样的东西来说这很好,但是如果我想制作更复杂的 2D 模型我该怎么办?
我注意到有大量的 3D 建模软件,还有充足的有关将 3D 模型导入 C/C++ 程序以与 Open GL 一起使用的教程和帮助。
然而,与 3D 相比,我对创建基于 2D 矢量的模型更感兴趣,因为我非常乐意继续尝试 2D 游戏一段时间。二维建模这样的概念是否存在?是否有用于创建和导出 2D 模型的工具以及专门用于导入 2D 模型的库,或者只是在 3D 软件中创建平面模型,然后导入这些文件(例如 .3ds、.ms3d)并将它们平放在 z 轴上?
到目前为止,我唯一的想法可能是使用 Inkscape 之类的东西进行建模,生成 SVG 文件,然后使用 Cairo 导入并渲染它们。这会有效吗,或者您还有其他建议吗?
请注意,我对任何类型的建模都是新手,所以我可能会问一个愚蠢的问题......
Making my Asteroids clone (in C) I've rather fallen in love with vector-based entities, but I've simply coded them in as x,y-point arrays. That's been fine for something like Asteroids, but what should I do if I want to make more complex 2D models?
I note that there is an awful lot of 3D modelling software out there, as well as ample tutorials and help on importing 3D models into one's C/C++ program for use with Open GL.
However I'm rather more interested in creating 2D vector-based models than 3D, as I'm perfectly happy to keep trying 2D games for a while yet. Does such a concept as 2D modelling exist? Are there tools for creating and exporting 2D models and libraries for importing 2D models specifically, or does one just create flat models in 3D software and then import those files (e.g. .3ds, .ms3d) and lay them flat onto the z-axis?
My only thought so far was perhaps using something like Inkscape for modelling, generate SVG files, and then use Cairo to import and render them. Will that work well, or do you have other recommendations?
Note I'm a bit of a newbie to modelling of any kind, so I may be asking a silly question...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
无需支持我自己的答案,但我对使用 SVG 做了更多研究。由于我使用的是 OpenGL,OpenVG 似乎是一个不错的匹配。
似乎除了 librsvg 之外的所有方法都没有真正允许加载 SVG 文件,因此可能需要另一个步骤将 SVG 解析为适当的 OpenVG 结构(主要看起来是大浮点数组,所以不太难)。同样,从 SVG 到 OpenVG 的项目似乎也存在一对一的映射,这是有希望的。据我所知,OpenVG 几乎是为 SVG 设计的。
我可能会使用 ShivaVG。也许它并不完美,但它吸引了老虎,而且我喜欢纯 C / OpenGL 实现,而且我严重怀疑我是否会做那么复杂的事情。
No need to upvote my own answer, but I've done a bit more research into using SVG. As I'm using OpenGL, it seems that OpenVG might be a good match.
It seems that all except librsvg stop short of actually allowing SVG files to be loaded in, so presumably there needs to be another step where SVGs are parsed into appropriate OpenVG structures (which mostly seem to be big float arrays, so not too hard). There likewise seems to be a one-to-one mapping of items from SVG to OpenVG, which is promising. As far as I can tell, OpenVG was pretty much made for SVGs.
I will probably use ShivaVG. Maybe it's not perfect, but it draws the tiger and I love a pure C / OpenGL implementation, and I seriously doubt I'll be doing anything all that complex just yet.
就 2D 矢量游戏编程而言,它通常是 Flash 和 Flex 的领域。
仍然 SVG 并通过 Cairo 加载它似乎是一个可行的解决方案。尽管我会注意确保您启用了硬件加速(最好是 OpenGL 后端)。
就 2D 格式而言,任何格式都不会像 SVG 那样获得良好的支持,所以我会坚持使用它。从技术上讲,像 Collada 或 X3D 这样的东西确实支持 2D 图形,但实际上它们有很多无用的(对于 2D 程序员来说)膨胀。
As far as 2D vector game programming goes, it usually is the domain of Flash and Flex.
Still SVG and loading it via Cairo seems to be a viable solution. Although I'd take care to make sure that you have hardware acceleration enabled (OpenGL backend preferably).
As far as 2D formats go, you won't get as good support as for SVG for any format, so I'd stick with it. Technically things like Collada or X3D do support 2D graphics, but practically they have a lot of useless (for a 2D programmer) bloat.
SVG 是 2D 的最佳选择:)
如果绘图速度是一个问题,您必须小心文件的复杂程度 - 并且请注意,SVG 也没有针对解析速度进行优化,因此您可能会遇到问题加载模型时会产生显着的启动时间损失。
SVG is the way to go for 2D :)
If drawing speed is an issue, you'll have to be careful about how complicated your files get though - and note that SVG isn't optimised for speed of parsing either, so you might incur a significant start-up time penalty while you load your models.