如何像iOS游戏“Contre Jour”一样创建土地(山丘)?
如何像iOS游戏一样创建土地(山丘)反对日记? (使用 Box2d 和 OpenGL)
我的想法:
物理 (Box2d)
我认为我们有物体或夹具数组。
当我们触摸屏幕时,确定触摸位置。
如果触摸位置离陆地不远,我们就开始扫描物体数组,寻找坐标最接近触摸位置的物体。
当触摸移动时,将右侧主体移动到新坐标(
body->SetTransform(...)
)。
您认为使用大量尸体的效率如何?并通过坐标找到合适的物体?
图形(OpenGL)
有一个通过绘制土地(山丘)创建的顶点和三角形数组? 这是真的吗?
How to create the land (hills) like iOS game Contre Jour? (Using Box2d and OpenGL)
My ideas:
Physics (Box2d)
I think we have array of bodies or fixture.
When we to touch screen, determine touch location.
If the touch location is not far from land, we begin to scan the array of bodies, and are looking for a body with coordinates closest to touch Location.
When case a touch Move, move the right body to a new coordinate (
body->SetTransform(...)
).
What do you think, efficient to use a large number of bodies? And find for the right body by coordinates?
Graphics (OpenGL)
There is an array of vertices and triangles created by drawing the land (hills)?
Is this true?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用函数 b2World::QueryAABB 获取给定区域中的灯具列表,然后检查这些灯具的最佳选项。 Box2D 测试台执行此操作是为了找出用鼠标抓取哪个夹具,以便您可以查看该源代码。 :http://www.iforce2d.net/b2dtut/world-querying
另请参阅 移动身体时,您确实可以使用 SetTransform,如果对象不需要沿途与任何东西交互,这会很好。另一种选择可能是将 SetLinearVelocity 设置为一个速度,该速度将在一个时间步内将主体移动到拖动到的点。如果您希望连续拖动对象并使其在移动时能够碰撞到物体,那么这是一个更好的方法,因为它不会立即将身体传送到手指位置。如果主体是子弹主体,那么它还可以防止用户拖动物体穿过其他对象,例如静态墙壁。记住当手指抬起时将速度设置为零:)
You can use the function b2World::QueryAABB to get a list of the fixtures in a given area, then check those for the best option. The Box2D testbed does this to find out which fixture to grab with the mouse so you could check out that source code. See also: http://www.iforce2d.net/b2dtut/world-querying
To move the body you can indeed use SetTransform, which would be good if the object does not need to interact with anything along the way. Another option might be to SetLinearVelocity to a velocity that will move the body to the dragged-to point in one time step. This is a better method if you want a continuous drag with the object being able to bump into things as it moves, because it does not teleport the body instantly to the finger position. If the body is a bullet body then it also prevents the user from dragging things through other objects, eg a static wall. Remember to set the velocity to zero when the finger is lifted :)