本文介绍了使用iPhone的OpenGL ES有效的二维(和碰撞检测)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这可能是一个更普遍的OpenGL的问题。使用OpenGL ES的2D,并通过教程读书,我学会了如何做像旋转和移动屏幕周围的物体的基本矩阵变换。到目前为止,一切都很好 - 我有一些对象移动和旋转。

this may be a more general opengl question. using OpenGL ES for 2d, and reading through the tutorials, I learned how to do the basic matrix transformations like rotating and moving an object around the screen. so far, so good - I have some objects moving around and rotating.

有我的下一个步骤是执行碰撞检测。一些简单的像边界框之间检查交集可能会是好的。不过,我坚持,因为为了知道什么时候边框相交,我必须知道的平移,旋转我的对象的坐标。但我不能找到一种方式来获得OpenGL的这些数字。

the next step for me is to do collision detection. something simple like checking for intersection between bounding boxes would probably be ok. however, I'm stuck because in order to know when the bounding boxes intersect, I have to know the translated, rotated coordinates of my objects. but I can't find a way to get those numbers from OpenGL.

所以我真的需要做的旋转和转换自己,除了有OpenGL的做出来,只是为了获得翻译的坐标?或者是有一些方法来应用当前的矩阵到一个顶点,并获得满意的结果?不能OpenGL的做数学题的速度远远超过我?

so do I really have to do the rotations and transformations myself, in addition to having OpenGL do them, just to get the translated coordinates? or is there some way to apply the current matrices to a vertex and get the results? couldn't OpenGL do the math much faster than me?

感谢您的帮助,我会AP preciate一些关于如何这种事情通常是一般建议。

thanks for any help, I would appreciate some general advice on how this kind of thing is usually done.

推荐答案

视觉信息和碰撞的信息通常是单独处理的游戏。请注意,您应该重新使用所有的转换的在你的物理code信息(即所有的矩阵),而不是顶点信息。这听起来有点低效和直觉在第一。

Visual information and collision information are usually treated individually in games. Note that you should reuse all your transform information in your physics code (that is all your matrices), not the vertex information. It does sound a bit inefficient and counter intuitive at first.

,其中一个原因是,它是不寻常的,要求的碰撞检测在多边形精度。相反,近似卷是足够了。

One of the reasons is that it is unusual to require collision detection at polygon accuracy. Instead, approximate volumes are usually sufficient.

所以,你很少会去碰撞一组多边形与另一组多边形 - 事实上你应该尝试您最难的不是。你应该碰撞领域对自己,框,线条或横扫领域(胶囊)。较大的非凸模型可以被分解成多个凸卷和单独处理。

So you're rarely ever going to collide a set of polygons with another set of polygons - in fact you should be trying your hardest not to. You should be colliding spheres against themselves, boxes, lines or "swept" spheres (capsules). Larger non-convex models can be broken into multiple convex volumes and treated separately.

因此​​,如果直接使用视觉网格碰撞,你的物理code会比使用较低细节目,或近似体积如球体或框中慢得多。这是一个有点多的痛苦,但碰撞的缓慢部分是不转换,其实际检测 - 所以此方法确实可以工作了快

So if you were using the visual mesh directly for collision, your physics code would be much slower than using a lower-detail mesh, or approximate volume like a sphere or a box. It is a bit more of a pain, but the slow part of collision isn't the transforms, its the actual detection - so this method actually works out faster.

根据你的比赛,我会考虑用球尽可能多的 - 他们并不需要旋转,并且测试是容易的。它也容易生成一个边界球,在模型加载时间,前几何消失到GPU土地。

Depending on your game, I'd consider using spheres as much as possible - they don't need to be rotated, and tests are easy. Its also easy to generate a bounding sphere at model load time, before the geometry disappears into GPU land.

本书是一个很好的资源,并有大量的的信息也是如此。

This book is a very good resource, and there is lots of online information as well.

这篇关于使用iPhone的OpenGL ES有效的二维(和碰撞检测)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-31 10:34