我是游戏开发和使用jMonkey引擎的新手。我开始开发无尽的跑步游戏。为了运行,我创建了带有Blender的地图并将其导入到jME。
如屏幕截图所示,我已将其添加到地形中并形成了一些山脉。现在,我需要获取地图的确切矢量点(屏幕截图中的A点,类似A点)。
这将帮助我检测正在运行的对象是否在地图上。有人可以给我答案或告诉我专家使用的替代方法吗?
这是截图
更新
我想检测运行对象是否在银色道路上。我怎样才能做到这一点?
解决该问题的常用方法是使用射线投射,其中测试一条假想线与化身(行驶的物体)下方的物体(地面,道路)的相交处。
这是一个使用jMonkeyEngine 3提供的机制的示例:
public boolean isOnRoad(Vector3f avatarPosition, Geometry road) {
// Pointing downwards (assuming that the Y-axis is facing upwards in your game)
Vector3f direction = new Vector3f(0, -1, 0);
// Create a line that starts at 'avatarPosition' and has a direction
Ray ray = new Ray(avatarPosition, direction);
// Results of the collision test are written into this object
CollisionResults results = new CollisionResults();
// Test for collisions between the road and the ray
road.collideWith(ray, results);
// If there is a collision, avatarPosition is above the road
return results.size() != 0;
}
您需要将化身的位置传递给函数。
avatarPosition = avatar.getLocalTranslation();
如果您的道路由打包到一个节点中的多个几何组成,则也可以将节点而不是单个几何传递到函数中。collideWith()
在Node上调用将测试其所有子级。
如果节点还包含场景的其他部分,则上面的功能可能无法正常工作。
调用road.collideWith(ray, results)
会在第一次使用公路网时隐式构建BIH树(边界间隔层次树)。这将加快碰撞测试的速度,因为它不必针对道路的每个三角形检查射线。在每个更新周期中,这样做的速度将足够快。
此外,您可以处理碰撞测试的结果。
这将返回最接近起点的交点的确切点:
Vector3f p = results.getClosestCollision().getContactPoint();
使用迭代器,您可以分别处理所有冲突,从最接近到最远的冲突排序:
Iterator<CollisionResult> it = results.iterator();
while(it.hasNext())
{
CollisionResult collisionResult = it.next();
Vector3f p = collisionResult.getContactPoint();
Geometry geom = collisionResult.getGeometry();
// Do something with contact point and geometry
}
有关碰撞的更多信息:http : //hub.jmonkeyengine.org/wiki/doku.php/jme3 : advanced :collision_and_intersection
射线投射还用于使用十字准线或鼠标在3D场景中选择对象。
这称为采摘:http : //hub.jmonkeyengine.org/wiki/doku.php/jme3 : beginner :
hello_picking
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句