本文整理汇总了Java中com.jme3.collision.CollisionResults.clear方法的典型用法代码示例。如果您正苦于以下问题:Java CollisionResults.clear方法的具体用法?Java CollisionResults.clear怎么用?Java CollisionResults.clear使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.jme3.collision.CollisionResults
的用法示例。
在下文中一共展示了CollisionResults.clear方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: distanceOfPick
import com.jme3.collision.CollisionResults; //导入方法依赖的package包/类
/**
* 获取射线与指定Spatial的碰撞的最近点,如果不存在碰撞则返回null.
* @param ray
* @param spatial
* @return
*/
public final static Float distanceOfPick(Ray ray, Spatial spatial) {
BoundingVolume bv = spatial.getWorldBound();
if (bv == null || !bv.intersects(ray))
return null;
TempPick tp = TempPick.get();
CollisionResults cr = tp.results;
cr.clear();
PickManager.pickResults(ray, spatial, cr);
Float result = null;
if (cr.size() > 0) {
result = cr.getClosestCollision().getDistance();
}
tp.release();
return result;
}
示例2: getTerrainHeight
import com.jme3.collision.CollisionResults; //导入方法依赖的package包/类
/**
* @deprecated 不再使用这个方法,在position超出terrain的范围的时候可能会获得不正确的值。
* 获得terrain的高位位置,并将结果存放到position返回
* @param terrain
* @param position 指定的地点
* @return
*/
public static Vector3f getTerrainHeight(Spatial terrain, Vector3f position) {
// 设置随机点的高度值
TempVars tv = TempVars.get();
Temp tp = Temp.get();
Vector3f ori = tv.vect1.set(position).setY(999999);
Vector3f dir = tv.vect2.set(position).setY(-999999).subtractLocal(ori);
CollisionResults store = tp.results;
store.clear();
RayUtils.collideWith(ori, dir, terrain, store);
CollisionResult result = store.getFarthestCollision();
if (result != null) {
position.set(result.getContactPoint());
}
tv.release();
tp.release();
return position;
}
示例3: hasObstacle
import com.jme3.collision.CollisionResults; //导入方法依赖的package包/类
private boolean hasObstacle(Spatial root, Vector3f origin, Vector3f direction, float limit) {
Temp tp = Temp.get();
CollisionResults results = tp.results;
results.clear();
collideWith(origin, direction, root, results);
boolean result = false;
for (CollisionResult r : results) {
if (r.getDistance() > limit) {
break;
}
if (isObstacle(r.getGeometry())) {
// 障碍物找到
// Log.get(GeometryUtils.class).log(Level.INFO, "Found obstacle infront! distance={0}, name={1}"
// , new Object[] {r.getDistance(), r.getGeometry().getName()});
result = true;
break;
}
}
tp.release();
return result;
}
示例4: pickSpatial
import com.jme3.collision.CollisionResults; //导入方法依赖的package包/类
/**
* 选择最近的物体
* @param ray
* @param pickRoot
* @return
*/
public final static Spatial pickSpatial(Ray ray, Spatial pickRoot) {
TempPick tp = TempPick.get();
CollisionResults cr = tp.results;
cr.clear();
PickManager.pickResults(ray, pickRoot, cr);
Spatial result = null;
if (cr.size() > 0) {
result = cr.getClosestCollision().getGeometry();
}
tp.release();
return result;
}
示例5: pickPoint
import com.jme3.collision.CollisionResults; //导入方法依赖的package包/类
/**
* 获取最近的选择点,如果不存在则返回null.
* @param ray
* @param pickRoot
* @return
*/
public final static Vector3f pickPoint(Ray ray, Spatial pickRoot) {
TempPick tp = TempPick.get();
CollisionResults cr = tp.results;
cr.clear();
PickManager.pickResults(ray, pickRoot, cr);
Vector3f result = null;
if (cr.size() > 0) {
result = cr.getClosestCollision().getContactPoint();
}
tp.release();
return result;
}
示例6: computeLodEntropy
import com.jme3.collision.CollisionResults; //导入方法依赖的package包/类
public static float computeLodEntropy(Mesh terrainBlock, IntBuffer lodIndices){
// Bounding box for the terrain block
BoundingBox bbox = (BoundingBox) terrainBlock.getBound();
// Vertex positions for the block
FloatBuffer positions = terrainBlock.getFloatBuffer(Type.Position);
// Prepare to cast rays
Vector3f pos = new Vector3f();
Vector3f dir = new Vector3f(0, -1, 0);
Ray ray = new Ray(pos, dir);
// Prepare collision results
CollisionResults results = new CollisionResults();
// Set the LOD indices on the block
VertexBuffer originalIndices = terrainBlock.getBuffer(Type.Index);
terrainBlock.clearBuffer(Type.Index);
terrainBlock.setBuffer(Type.Index, 3, lodIndices);
// Recalculate collision mesh
terrainBlock.createCollisionData();
float entropy = 0;
for (int i = 0; i < positions.capacity() / 3; i++){
BufferUtils.populateFromBuffer(pos, positions, i);
float realHeight = pos.y;
pos.addLocal(0, bbox.getYExtent(), 0);
ray.setOrigin(pos);
results.clear();
terrainBlock.collideWith(ray, Matrix4f.IDENTITY, bbox, results);
if (results.size() > 0){
Vector3f contactPoint = results.getClosestCollision().getContactPoint();
float delta = Math.abs(realHeight - contactPoint.y);
entropy = Math.max(delta, entropy);
}
}
// Restore original indices
terrainBlock.clearBuffer(Type.Index);
terrainBlock.setBuffer(originalIndices);
return entropy;
}
示例7: computeLodEntropy
import com.jme3.collision.CollisionResults; //导入方法依赖的package包/类
public static float computeLodEntropy(Mesh terrainBlock, Buffer lodIndices){
// Bounding box for the terrain block
BoundingBox bbox = (BoundingBox) terrainBlock.getBound();
// Vertex positions for the block
FloatBuffer positions = terrainBlock.getFloatBuffer(Type.Position);
// Prepare to cast rays
Vector3f pos = new Vector3f();
Vector3f dir = new Vector3f(0, -1, 0);
Ray ray = new Ray(pos, dir);
// Prepare collision results
CollisionResults results = new CollisionResults();
// Set the LOD indices on the block
VertexBuffer originalIndices = terrainBlock.getBuffer(Type.Index);
terrainBlock.clearBuffer(Type.Index);
if (lodIndices instanceof IntBuffer)
terrainBlock.setBuffer(Type.Index, 3, (IntBuffer)lodIndices);
else if (lodIndices instanceof ShortBuffer) {
terrainBlock.setBuffer(Type.Index, 3, (ShortBuffer) lodIndices);
}
// Recalculate collision mesh
terrainBlock.createCollisionData();
float entropy = 0;
for (int i = 0; i < positions.limit() / 3; i++){
BufferUtils.populateFromBuffer(pos, positions, i);
float realHeight = pos.y;
pos.addLocal(0, bbox.getYExtent(), 0);
ray.setOrigin(pos);
results.clear();
terrainBlock.collideWith(ray, Matrix4f.IDENTITY, bbox, results);
if (results.size() > 0){
Vector3f contactPoint = results.getClosestCollision().getContactPoint();
float delta = Math.abs(realHeight - contactPoint.y);
entropy = Math.max(delta, entropy);
}
}
// Restore original indices
terrainBlock.clearBuffer(Type.Index);
terrainBlock.setBuffer(originalIndices);
return entropy;
}