本文整理汇总了Java中com.jme3.collision.CollisionResults.getClosestCollision方法的典型用法代码示例。如果您正苦于以下问题:Java CollisionResults.getClosestCollision方法的具体用法?Java CollisionResults.getClosestCollision怎么用?Java CollisionResults.getClosestCollision使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.jme3.collision.CollisionResults
的用法示例。
在下文中一共展示了CollisionResults.getClosestCollision方法的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: 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);
}
}
}
}
示例3: 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;
}
示例4: 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();
}
示例5: triggerViewAtom
import com.jme3.collision.CollisionResults; //导入方法依赖的package包/类
public void triggerViewAtom() {
CollisionResults results = new CollisionResults();
Vector2f click2d = app.getInputManager().getCursorPosition();
Vector3f click3d = app.getCamera().getWorldCoordinates(
new Vector2f(click2d.x, click2d.y), 0f).clone();
Vector3f dir = app.getCamera().getWorldCoordinates(
new Vector2f(click2d.x, click2d.y), 1f).subtractLocal(click3d).normalizeLocal();
Ray ray = new Ray(click3d, dir);
moleculeNode.collideWith(ray, results);
CollisionResult result = results.getClosestCollision();
if (result == null) {
return;
}
Geometry geom = result.getGeometry();
String symbol = findSymbolOf(geom);
if (symbol != null) {
setAtomView(symbol);
}
}
示例6: addToBlockTerrain
import com.jme3.collision.CollisionResults; //导入方法依赖的package包/类
public void addToBlockTerrain(BlockTerrainControl blockTerrain, Vector3Int location, Vector3Int size){
Spatial spatial = blockTerrain.getSettings().getAssetManager().loadModel(modelPath);
Vector3f bounds = getBounds(spatial);
Vector3f relativeBlockSize = new Vector3f((bounds.getX() / size.getX()), (bounds.getY() / size.getY()), (bounds.getZ() / size.getZ()));
Geometry testBlockBox = new Geometry("", new Box(relativeBlockSize.divide(2), relativeBlockSize.getX(), relativeBlockSize.getY(), relativeBlockSize.getZ()));
Vector3Int tmpLocation = new Vector3Int();
for(int x=0;x<size.getX();x++){
for(int y=0;y<size.getY();y++){
for(int z=0;z<size.getZ();z++){
testBlockBox.setLocalTranslation(
(relativeBlockSize.getX() * x) - (bounds.getX() / 2),
(relativeBlockSize.getY() * y),
(relativeBlockSize.getZ() * z) - (bounds.getZ() / 2)
);
CollisionResults collisionResults = new CollisionResults();
spatial.collideWith(testBlockBox.getWorldBound(), collisionResults);
CollisionResult collisionResult = collisionResults.getClosestCollision();
if(collisionResult != null){
tmpLocation.set(location).addLocal(x, y, z);
Block block = getMaterialBlock(collisionResult.getGeometry().getMaterial());
blockTerrain.setBlock(tmpLocation, block);
}
}
}
}
}
示例7: MouseRayInputAction
import com.jme3.collision.CollisionResults; //导入方法依赖的package包/类
@Override
public MouseInputEvent MouseRayInputAction(MouseInputEventType mouseInputType, Ray ray) {
EntitySet entities = entityData.getEntities(RenderComponent.class, HexPositionComponent.class);
if (entities.isEmpty()) {
return null;
}
if (mouseInputType.equals(MouseInputEventType.RMB)) {
CollisionResults results = renderSystem.subSystemCollideWith(this, ray);
if (results.size() > 0) {
CollisionResult closest = results.getClosestCollision();
for (Entity e : entities) {
Spatial s = closest.getGeometry().getParent();
do {
if (s != null && s.getName().equals(renderSystem.getSpatialName(e.getId()))) {
// mouseSystem.setDebugPosition(closest.getContactPoint());
HexCoordinate pos = entityData.getComponent(e.getId(), HexPositionComponent.class).getPosition();
return new MouseInputEvent(MouseInputEventType.RMB, pos, mapData.getTile(pos).getHeight(), ray, closest);
}
s = s.getParent();
} while (s != null && !s.getParent().getName().equals(renderSystem.getRenderNodeName()));
}
}
}
return null;
}
示例8: processExitSurface
import com.jme3.collision.CollisionResults; //导入方法依赖的package包/类
protected void processExitSurface() {
this.surfaceNormal = null;
this.exitPoint = null;
CollisionResults results = new CollisionResults();
Vector3f vel = this.agent.getVelocity();
if (vel == null) {
vel = new Vector3f();
}
Ray ray = new Ray(this.agent.getLocalTranslation(), vel);
this.containmentArea.collideWith(ray, results);
CollisionResult closestCollision = results.getClosestCollision();
if (closestCollision != null) {
this.surfaceNormal = closestCollision.getContactNormal();
//closestCollision.getTriangle(new Triangle()).getNormal();
this.exitPoint = closestCollision.getContactPoint();
}
}
示例9: closestNonColliding
import com.jme3.collision.CollisionResults; //导入方法依赖的package包/类
public static Vector3f closestNonColliding(Spatial walls, Vector3f start,
Vector3f target, float room) {
_tempVec.set(target).setY(1000f);
Ray down = new Ray(_tempVec, Globals.DOWN);
CollisionResults insideCheck = new CollisionResults();
int collisionAmount = walls.collideWith(down, insideCheck);
if (collisionAmount == 0) {
return target;
}
Vector3f dir = target.subtract(start).normalizeLocal();
Ray fromChar = new Ray(start, dir);
CollisionResults collisionResults = new CollisionResults();
insideCheck.getCollision(0).getGeometry()
.collideWith(fromChar, collisionResults);
CollisionResult collision = collisionResults.getClosestCollision();
return collision == null ? target
: collision.getContactPoint()
.add(dir.negateLocal().multLocal(room));
}
示例10: 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);
tp.ensurePositiveVolumeBBox();
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 if (children.get(i) instanceof TerrainQuad) {
((TerrainQuad) children.get(i)).findPick(toTest, results);
}
}
}
}
}
示例11: 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 == null) {
return null;
}
final CollisionResult result = results.getClosestCollision();
if (result == null) {
return null;
}
return result.getContactPoint();
}
示例12: raycast
import com.jme3.collision.CollisionResults; //导入方法依赖的package包/类
/**
* Performs a raycast from the given vector in the given direction in the geometry space
* of the given Node. Returns true if the first collision is with the given target Entity,
* and false otherwise.
*
* @param from the position to start the ray
* @param direction the direction to raycast in
* @param target the Entity to attempt to hit
* @param root the Node containing all Geometries to be considered
* @return true if the first collision of the raycast is with target, false otherwise
*/
public static boolean raycast(Vector3f from, Vector3f direction, Entity target, Node root) {
CollisionResults results = new CollisionResults();
Ray ray = new Ray(from, direction);
root.collideWith(ray, results);
if (results.size() > 0) {
CollisionResult closest = results.getClosestCollision();
// while this cast is ugly, it's considered proper usage
// of JME's userdata system.
Geometry geom = closest.getGeometry();
Entity entity = geom.getUserData("entity");
if (entity == null)
collisionWarningMessage(geom);
return entity == target;
}
return false;
}
示例13: getCollisionFromScreenPos
import com.jme3.collision.CollisionResults; //导入方法依赖的package包/类
/**
* Get a collision on spatial from screen position.
*
* @param spatial the spatial.
* @param camera the camera.
* @param screenX the screen X coord.
* @param screenY the screen Y coord.
* @return the collision or null.
*/
@Nullable
public static CollisionResult getCollisionFromScreenPos(@NotNull final Spatial spatial,
@NotNull final Camera camera,
final float screenX,
final float screenY) {
final LocalObjects local = LocalObjects.get();
final Vector2f cursor = local.nextVector(screenX, screenY);
final Vector3f click3d = camera.getWorldCoordinates(cursor, 0f, local.nextVector());
final Vector3f dir = camera.getWorldCoordinates(cursor, 1f, local.nextVector())
.subtractLocal(click3d)
.normalizeLocal();
final Ray ray = local.nextRay();
ray.setOrigin(click3d);
ray.setDirection(dir);
final CollisionResults results = local.nextCollisionResults();
spatial.updateModelBound();
spatial.collideWith(ray, results);
if (results.size() < 1) {
return null;
}
return results.getClosestCollision();
}
示例14: simpleUpdate
import com.jme3.collision.CollisionResults; //导入方法依赖的package包/类
@Override
public void simpleUpdate(float tpf){
Vector3f origin = cam.getWorldCoordinates(inputManager.getCursorPosition(), 0.0f);
Vector3f direction = cam.getWorldCoordinates(inputManager.getCursorPosition(), 0.3f);
direction.subtractLocal(origin).normalizeLocal();
Ray ray = new Ray(origin, direction);
CollisionResults results = new CollisionResults();
shootables.collideWith(ray, results);
// System.out.println("----- Collisions? " + results.size() + "-----");
// for (int i = 0; i < results.size(); i++) {
// // For each hit, we know distance, impact point, name of geometry.
// float dist = results.getCollision(i).getDistance();
// Vector3f pt = results.getCollision(i).getWorldContactPoint();
// String hit = results.getCollision(i).getGeometry().getName();
// System.out.println("* Collision #" + i);
// System.out.println(" You shot " + hit + " at " + pt + ", " + dist + " wu away.");
// }
if (results.size() > 0) {
CollisionResult closest = results.getClosestCollision();
mark.setLocalTranslation(closest.getContactPoint());
Quaternion q = new Quaternion();
q.lookAt(closest.getContactNormal(), Vector3f.UNIT_Y);
mark.setLocalRotation(q);
rootNode.attachChild(mark);
} else {
rootNode.detachChild(mark);
}
}
示例15: getWorldIntersection
import com.jme3.collision.CollisionResults; //导入方法依赖的package包/类
private Vector3f getWorldIntersection() {
Vector3f origin = cam.getWorldCoordinates(new Vector2f(settings.getWidth() / 2, settings.getHeight() / 2), 0.0f);
Vector3f direction = cam.getWorldCoordinates(new Vector2f(settings.getWidth() / 2, settings.getHeight() / 2), 0.3f);
direction.subtractLocal(origin).normalizeLocal();
Ray ray = new Ray(origin, direction);
CollisionResults results = new CollisionResults();
int numCollisions = terrain.collideWith(ray, results);
if (numCollisions > 0) {
CollisionResult hit = results.getClosestCollision();
return hit.getContactPoint();
}
return null;
}