本文整理汇总了Java中com.jme3.collision.CollisionResults类的典型用法代码示例。如果您正苦于以下问题:Java CollisionResults类的具体用法?Java CollisionResults怎么用?Java CollisionResults使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
CollisionResults类属于com.jme3.collision包,在下文中一共展示了CollisionResults类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getClicked
import com.jme3.collision.CollisionResults; //导入依赖的package包/类
private CollisionResult getClicked() {
CollisionResults results = new CollisionResults();
Vector2f click2d = inputManager.getCursorPosition();
Vector3f click3d = cam.getWorldCoordinates(
new Vector2f(click2d.x, click2d.y), 0f).clone();
Vector3f dir = cam.getWorldCoordinates(
new Vector2f(click2d.x, click2d.y), 1f).subtractLocal(click3d).normalizeLocal();
Ray ray = new Ray(click3d, dir);
rootNode.collideWith(ray, results);
if (results.size() > 0)
return results.getClosestCollision();
else
return null;
}
示例2: main
import com.jme3.collision.CollisionResults; //导入依赖的package包/类
public static void main(String[] args){
Ray r = new Ray(Vector3f.ZERO, Vector3f.UNIT_X);
BoundingBox bbox = new BoundingBox(new Vector3f(5, 0, 0), 1, 1, 1);
CollisionResults res = new CollisionResults();
bbox.collideWith(r, res);
System.out.println("Bounding:" +bbox);
System.out.println("Ray: "+r);
System.out.println("Num collisions: "+res.size());
for (int i = 0; i < res.size(); i++){
System.out.println("--- Collision #"+i+" ---");
float dist = res.getCollision(i).getDistance();
Vector3f pt = res.getCollision(i).getContactPoint();
System.out.println("distance: "+dist);
System.out.println("point: "+pt);
}
}
示例3: collideWith
import com.jme3.collision.CollisionResults; //导入依赖的package包/类
public int collideWith(Collidable other, CollisionResults results) {
if (other instanceof BoundingVolume) {
BoundingVolume bv = (BoundingVolume) other;
return bv.collideWith(this, results);
} else if (other instanceof AbstractTriangle) {
AbstractTriangle tri = (AbstractTriangle) other;
float d = intersects(tri.get1(), tri.get2(), tri.get3());
if (Float.isInfinite(d) || Float.isNaN(d)) {
return 0;
}
Vector3f point = new Vector3f(direction).multLocal(d).addLocal(origin);
results.addCollision(new CollisionResult(point, d));
return 1;
} else {
throw new UnsupportedCollisionException();
}
}
示例4: collideWith
import com.jme3.collision.CollisionResults; //导入依赖的package包/类
@Override
public int collideWith(Collidable other, CollisionResults results) throws UnsupportedCollisionException {
if (refreshFlags != 0)
throw new IllegalStateException("Scene graph must be updated" +
" before checking collision");
if (other instanceof BoundingVolume)
if (!getWorldBound().intersects((BoundingVolume)other))
return 0;
if(other instanceof Ray)
return collideWithRay((Ray)other, results);
else if (other instanceof BoundingVolume)
return collideWithBoundingVolume((BoundingVolume)other, results);
else {
throw new UnsupportedCollisionException("TerrainPatch cannnot collide with "+other.getClass().getName());
}
}
示例5: getHeight
import com.jme3.collision.CollisionResults; //导入依赖的package包/类
protected float getHeight(float x, float z, Vector2f xz) {
float topLeft = getHeightmapHeight((int)FastMath.floor(x), (int)FastMath.ceil(z));
float topRight = getHeightmapHeight((int)FastMath.ceil(x), (int)FastMath.ceil(z));
float bottomLeft = getHeightmapHeight((int)FastMath.floor(x), (int)FastMath.floor(z));
float bottomRight = getHeightmapHeight((int)FastMath.ceil(x), (int)FastMath.floor(z));
// create a vertical, down-facing, ray and get the height from that
float max = Math.max(Math.max(Math.max(topLeft, topRight), bottomRight),bottomLeft);
max = max*getWorldScale().y;
Ray ray = new Ray(new Vector3f(xz.x,max+10f,xz.y), new Vector3f(0,-1,0).normalizeLocal());
CollisionResults cr = new CollisionResults();
int num = this.collideWith(ray, cr);
if (num > 0)
return cr.getClosestCollision().getContactPoint().y;
else
return 0;
}
示例6: collideWith
import com.jme3.collision.CollisionResults; //导入依赖的package包/类
@Override
public int collideWith(Collidable other, CollisionResults results){
int total = 0;
if (other instanceof Ray)
return collideWithRay((Ray)other, results);
// if it didn't collide with this bbox, return
if (other instanceof BoundingVolume)
if (!this.getWorldBound().intersects((BoundingVolume)other))
return total;
for (Spatial child : children){
total += child.collideWith(other, results);
}
return total;
}
示例7: findPick
import com.jme3.collision.CollisionResults; //导入依赖的package包/类
/**
* Gather the terrain patches that intersect the given ray (toTest).
* This only tests the bounding boxes
* @param toTest
* @param results
*/
public void findPick(Ray toTest, List<TerrainPickData> results) {
if (getWorldBound() != null) {
if (getWorldBound().intersects(toTest)) {
// further checking needed.
for (int i = 0; i < getQuantity(); i++) {
if (children.get(i) instanceof TerrainPatch) {
TerrainPatch tp = (TerrainPatch) children.get(i);
if (tp.getWorldBound().intersects(toTest)) {
CollisionResults cr = new CollisionResults();
toTest.collideWith(tp.getWorldBound(), cr);
if (cr != null && cr.getClosestCollision() != null) {
cr.getClosestCollision().getDistance();
results.add(new TerrainPickData(tp, cr.getClosestCollision()));
}
}
}
else
((TerrainQuad) children.get(i)).findPick(toTest, results);
}
}
}
}
示例8: collideWith
import com.jme3.collision.CollisionResults; //导入依赖的package包/类
public int collideWith(Collidable other, CollisionResults results) {
// Force bound to update
checkDoBoundUpdate();
// Update transform, and compute cached world matrix
computeWorldMatrix();
assert (refreshFlags & (RF_BOUND | RF_TRANSFORM)) == 0;
if (mesh != null) {
// NOTE: BIHTree in mesh already checks collision with the
// mesh's bound
int prevSize = results.size();
int added = mesh.collideWith(other, cachedWorldMat, worldBound, results);
int newSize = results.size();
for (int i = prevSize; i < newSize; i++) {
results.getCollisionDirect(i).setGeometry(this);
}
return added;
}
return 0;
}
示例9: collideWith
import com.jme3.collision.CollisionResults; //导入依赖的package包/类
public int collideWith(Collidable other, CollisionResults results) {
if (other instanceof Ray) {
Ray ray = (Ray) other;
return collideWithRay(ray, results);
} else if (other instanceof Triangle) {
Triangle t = (Triangle) other;
if (intersects(t.get1(), t.get2(), t.get3())) {
CollisionResult r = new CollisionResult();
results.addCollision(r);
return 1;
}
return 0;
} else {
throw new UnsupportedCollisionException("With: " + other.getClass().getSimpleName());
}
}
示例10: intersectWhere
import com.jme3.collision.CollisionResults; //导入依赖的package包/类
public final void intersectWhere(Ray r, Geometry[] geoms, float sceneMin, float sceneMax,
CollisionResults results){
for (OCTTriangle t : tris){
float d = r.intersects(t.get1(), t.get2(), t.get3());
if (Float.isInfinite(d))
continue;
Vector3f contactPoint = new Vector3f(r.getDirection()).multLocal(d).addLocal(r.getOrigin());
CollisionResult result = new CollisionResult(geoms[t.getGeometryIndex()],
contactPoint,
d,
t.getTriangleIndex());
results.addCollision(result);
}
for (int i = 0; i < 8; i++){
Octnode child = children[i];
if (child == null)
continue;
if (child.bbox.intersects(r)){
child.intersectWhere(r, geoms, sceneMin, sceneMax, results);
}
}
}
示例11: doPick
import com.jme3.collision.CollisionResults; //导入依赖的package包/类
private static CollisionResult doPick(Camera cam, Vector2f mouseLoc, Node node, Spatial exclude) {
CollisionResults results = new CollisionResults();
Ray ray = new Ray();
Vector3f pos = cam.getWorldCoordinates(mouseLoc, 0).clone();
Vector3f dir = cam.getWorldCoordinates(mouseLoc, 0.3f).clone();
dir.subtractLocal(pos).normalizeLocal();
ray.setOrigin(pos);
ray.setDirection(dir);
node.collideWith(ray, results);
CollisionResult result = null;
if (exclude == null) {
result = results.getClosestCollision();
} else {
Iterator<CollisionResult> it = results.iterator();
while (it.hasNext()) {
CollisionResult cr = it.next();
if (isExcluded(cr.getGeometry(), exclude)) {
continue;
} else {
return cr;
}
}
}
return result;
}
示例12: getTerrainCollisionPoint
import com.jme3.collision.CollisionResults; //导入依赖的package包/类
/**
* Find where on the terrain the mouse intersects.
*/
protected Vector3f getTerrainCollisionPoint() {
if (editorController.getTerrain(null) == null) {
return null;
}
CollisionResults results = new CollisionResults();
Ray ray = new Ray();
Vector3f pos = cam.getWorldCoordinates(new Vector2f(mouseX, mouseY), 0).clone();
Vector3f dir = cam.getWorldCoordinates(new Vector2f(mouseX, mouseY), 0.3f).clone();
dir.subtractLocal(pos).normalizeLocal();
ray.setOrigin(pos);
ray.setDirection(dir);
editorController.getTerrain(null).collideWith(ray, results);
if (results.size() == 0) {
return null;
}
final CollisionResult result = results.getClosestCollision();
return result.getContactPoint();
}
示例13: wakeNearbyItems
import com.jme3.collision.CollisionResults; //导入依赖的package包/类
public void wakeNearbyItems(Spatial s, float boundingVolumeScale) {
Spatial item = getItem(s);
if (item == null) {
return;
}
BoundingVolume bv = item.getWorldBound().clone();
Transform trans = new Transform(Vector3f.ZERO, Quaternion.IDENTITY,
Vector3f.UNIT_XYZ.mult(boundingVolumeScale));
bv = bv.transform(trans);
CollisionResults res = new CollisionResults();
for (Spatial i : items) {
if (i == item) {
continue;
}
i.collideWith(bv, res);
if (res.size() > 0) {
i.getControl(MyRigidBodyControl.class).activate();
}
}
}
示例14: 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;
}
示例15: 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;
}