本文整理汇总了Java中com.jme3.collision.CollisionResult.getGeometry方法的典型用法代码示例。如果您正苦于以下问题:Java CollisionResult.getGeometry方法的具体用法?Java CollisionResult.getGeometry怎么用?Java CollisionResult.getGeometry使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.jme3.collision.CollisionResult
的用法示例。
在下文中一共展示了CollisionResult.getGeometry方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: triggerViewAtom
import com.jme3.collision.CollisionResult; //导入方法依赖的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);
}
}
示例2: raycast
import com.jme3.collision.CollisionResult; //导入方法依赖的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;
}
示例3: raycastHitResult
import com.jme3.collision.CollisionResult; //导入方法依赖的package包/类
/**
* Performs a raycast from the given vector in the given direction in the geometry space
* of the given Node. Returns a List of EntityHitResult, which encodes every Entity collided
* with and the distance at which the collision occured.
*
* @param from the position to start the ray
* @param direction the direction to raycast in
* @param root the Node containing all Geometries to be considered
* @return a List of EntityHitResult encoding the collisions
*/
public static List<EntityHitResult> raycastHitResult (Vector3f from, Vector3f direction, Node root) {
CollisionResults results = new CollisionResults();
Ray ray = new Ray(from, direction);
root.collideWith(ray, results);
List<EntityHitResult> hit = new ArrayList<EntityHitResult> ();
Entity entity;
Geometry geom;
for (CollisionResult result : results) {
geom = result.getGeometry();
entity = geom.getUserData("entity");
if (entity == null)
collisionWarningMessage(geom);
else
hit.add(new EntityHitResult(entity, result.getDistance(), result.getContactPoint()));
}
return hit;
}
示例4: onAnalog
import com.jme3.collision.CollisionResult; //导入方法依赖的package包/类
public void onAnalog( String name, float intensity, float tpf ) {
if ( name.equals( CLICK ) ) {
if ( tool.isDragging() ) {
tool.dragging( inputManager.getCursorPosition(), getSurfaceSelected( 0 ) );
checkForEnd = false;
} else {
CollisionResult cr = getClicked();
if ( cr == null )
tool.clear();
if ( tool instanceof PlaneTool || (cr != null && cr.getGeometry().getUserData( CLICK ) instanceof Handle ) ) {
tool.dragStart( cr == null ? null : cr.getGeometry(), inputManager.getCursorPosition(), getSurfaceSelected( 0 ) );
checkForEnd = false;
} else {
if ( cr != null ) {
Spatial target = cr.getGeometry();
while ( target.getParent().getUserData( HandleMe.class.getSimpleName() ) != null )
target = target.getParent();
tool.clickedOn( target, cr.getContactPoint(), inputManager.getCursorPosition() );
}
}
}
}
}
示例5: detectPickedAxis
import com.jme3.collision.CollisionResult; //导入方法依赖的package包/类
protected void detectPickedAxis(@NotNull final EditorTransformSupport editorControl,
@NotNull final CollisionResult collisionResult) {
final Geometry geometry = collisionResult.getGeometry();
final String geometryName = geometry.getName();
if (geometryName.contains(getNodeX())) {
editorControl.setPickedAxis(PickedAxis.X);
} else if (geometryName.contains(getNodeY())) {
editorControl.setPickedAxis(PickedAxis.Y);
} else if (geometryName.contains(getNodeZ())) {
editorControl.setPickedAxis(PickedAxis.Z);
}
}
示例6: getBuildableAtCursor
import com.jme3.collision.CollisionResult; //导入方法依赖的package包/类
public BuildableControl getBuildableAtCursor() {
Camera cam = app.getCamera();
CollisionResults results = new CollisionResults();
Vector2f click2d = inputManager.getCursorPosition();
// Convert 2d location to 3d location with depth 0
Vector3f click3d = cam.getWorldCoordinates(new Vector2f(click2d.getX(), click2d.getY()), 0);
// Cast ray forward from this point
Vector3f dir = cam.getWorldCoordinates(new Vector2f(click2d.getX(), click2d.getY()), 1f).subtractLocal(click3d);
Ray ray = new Ray(click3d, dir);
rootNode.collideWith(ray, results);
for (int i = 0; i < results.size(); i++) {
final CollisionResult collision = results.getCollision(i);
/*
* Find closest geometry that has a BuildableControl, and try the
* parents if none can be found
*/
Spatial geometry = collision.getGeometry();
while (geometry != null) {
BuildableControl bc = geometry.getControl(BuildableControl.class);
if (bc != null) {
float dist = collision.getDistance();
Vector3f pt = collision.getContactPoint();
String target = geometry.getName();
return bc;
} else {
geometry = geometry.getParent();
}
}
}
return null;
}
示例7: getHUDCollisionUnderPoint
import com.jme3.collision.CollisionResult; //导入方法依赖的package包/类
/**
* NOTE: only call this from the Swing EDT
*
* @param view The view that contains the HUD nodes to look for
* @param point The screen point at which we are casting the ray
* @return Collision information
*/
public static HUDNodeCollision getHUDCollisionUnderPoint( JMEView view, Vector2f point ) {
CollisionResults results = view.hitsUnderPoint( point );
for ( CollisionResult result : results ) {
Geometry geometry = result.getGeometry();
if ( geometry instanceof HUDNode ) {
final HUDNode node = (HUDNode) geometry;
final Vector3f hitPoint = node.transformEventCoordinates( point.x, point.y );
return new HUDNodeCollision( result, hitPoint, node, point );
}
}
return null;
}
示例8: pickWorldSpatial
import com.jme3.collision.CollisionResult; //导入方法依赖的package包/类
/**
* Given the mouse coordinates, pick the geometry that is closest to the
* camera.
*
* @param cam the Camera
* @param mouseLoc the position of the mouse
* @param jmeRootNode to pick from
* @return the selected spatial, or null if nothing
*/
public static Spatial pickWorldSpatial(Camera cam, Vector2f mouseLoc, JmeNode jmeRootNode) {
Node rootNode = jmeRootNode.getLookup().lookup(Node.class);
CollisionResult cr = pick(cam, mouseLoc, rootNode);
if (cr != null) {
return cr.getGeometry();
} else {
return null;
}
}
示例9: pickAxisMarker
import com.jme3.collision.CollisionResult; //导入方法依赖的package包/类
/**
* Pick a part of the axis marker. The result is a Vector3f that represents
* what part of the axis was selected. For example if (1,0,0) is returned,
* then the X-axis pole was selected. If (0,1,1) is returned, then the Y-Z
* plane was selected.
*
* @param cam the Camera
* @param mouseLoc the position of the mouse
* @param pickType the type of markers to select
* @return null if it did not intersect the marker
*/
protected Vector3f pickAxisMarker(Camera cam, Vector2f mouseLoc, AxisMarkerPickType pickType) {
if (axisMarker == null) {
return null;
}
CollisionResult cr = pick(cam, mouseLoc, axisMarker);
if (cr == null || cr.getGeometry() == null) {
return null;
}
String collisionName = cr.getGeometry().getName();
if (pickType != null) {
if (pickType == AxisMarkerPickType.planeOnly || pickType == AxisMarkerPickType.axisAndPlane) {
if ("quadXY".equals(collisionName) || "circleXY".equals(collisionName)) {
return QUAD_XY;
} else if ("quadXZ".equals(collisionName) || "circleXZ".equals(collisionName)) {
return QUAD_XZ;
} else if ("quadYZ".equals(collisionName) || "circleYZ".equals(collisionName)) {
return QUAD_YZ;
}
}
if (pickType == AxisMarkerPickType.axisOnly || pickType == AxisMarkerPickType.axisAndPlane) {
if ("arrowX".equals(collisionName) || "coneX".equals(collisionName) || "boxX".equals(collisionName)) {
return ARROW_X;
} else if ("arrowY".equals(collisionName) || "coneY".equals(collisionName) || "boxY".equals(collisionName)) {
return ARROW_Y;
} else if ("arrowZ".equals(collisionName) || "coneZ".equals(collisionName) || "boxZ".equals(collisionName)) {
return ARROW_Z;
}
}
}
return null;
}
示例10: pickCurve
import com.jme3.collision.CollisionResult; //导入方法依赖的package包/类
private void pickCurve(Ray ray) {
CollisionResults results = new CollisionResults();
curveNode.collideWith(ray, results);
if (results.size()==0) {
selectedCurveIndex = -1;
selectedPointIndex = -1;
selectCurve(-1, null);
} else {
CollisionResult result = results.getClosestCollision();
Geometry geom = result.getGeometry();
if (geom.getName().startsWith("Curve")) {
int index = Integer.parseInt(geom.getName().substring("Curve".length()));
selectedCurveIndex = index;
selectedPointIndex = -1;
selectCurve(index, null);
} else if (geom.getName().startsWith("ControlPoint")) {
String n = geom.getName().substring("ControlPoint".length());
String[] parts = n.split(":");
selectedCurveIndex = Integer.parseInt(parts[0]);
selectedPointIndex = Integer.parseInt(parts[1]);
selectCurve(selectedCurveIndex, featureCurves.get(selectedCurveIndex).getPoints()[selectedPointIndex]);
} else {
selectedCurveIndex = -1;
selectedPointIndex = -1;
selectCurve(-1, null);
}
}
}
示例11: update
import com.jme3.collision.CollisionResult; //导入方法依赖的package包/类
@Override
public void update( float tpf ) {
super.update(tpf);
long time = System.nanoTime();
if( time - lastSample < sampleFrequency )
return;
lastSample = time;
Vector2f cursor = getApplication().getInputManager().getCursorPosition();
CollisionResults collisions = getCollisions(cursor);
for( CollisionResult cr : collisions ) {
Geometry geom = cr.getGeometry();
if( geom == selected ) {
// If the hover is already the selection then
// don't bother changinge
if( geom == hover ) {
return;
}
}
if( isIgnored(geom) ) {
continue;
}
setHover(geom);
return;
}
// Else clear the hover
setHover(null);
}
示例12: getPointedGeometry
import com.jme3.collision.CollisionResult; //导入方法依赖的package包/类
public static Geometry getPointedGeometry(Node n, Ray r) {
CollisionResult collision = getCollision(n, r);
if (collision == null) {
return null;
}
return collision.getGeometry();
}
示例13: pickWorldSpatial
import com.jme3.collision.CollisionResult; //导入方法依赖的package包/类
/**
* Given the mouse coordinates, pick the geometry that is closest to the camera.
* @param jmeRootNode to pick from
* @return the selected spatial, or null if nothing
*/
protected Spatial pickWorldSpatial(Camera cam, Vector2f mouseLoc, JmeNode jmeRootNode) {
Node rootNode = jmeRootNode.getLookup().lookup(Node.class);
CollisionResult cr = pick(cam, mouseLoc, rootNode);
if (cr != null) {
return cr.getGeometry();
} else {
return null;
}
}
示例14: doLink
import com.jme3.collision.CollisionResult; //导入方法依赖的package包/类
private Vector3f doLink(SandboxViewport viewport) {
CollisionResults results = new CollisionResults();
// Convert screen click to 3d position
InputManager inputManager = viewport.getInputManager();
Vector2f click2d = inputManager.getCursorPosition();
Camera cam = viewport.getCamera();
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);
// Aim the ray from the clicked spot forwards.
Ray ray = new Ray(click3d, dir);
// Collect intersections between ray and all nodes in results list.
Node sceneElements = viewport.getSceneElements();
sceneElements.collideWith(ray, results);
CollisionResult result = results.getClosestCollision();
if (result == null) {
return cam.getWorldCoordinates(new Vector2f(click2d.x, click2d.y), 0.5f).clone();
}
Geometry g = result.getGeometry();
Prefab prefab = viewport.findPrefabParent(g);
if (prefab != null) {
prefab.updateModelBound();
BoundingVolume bv = prefab.getWorldBound();
if (bv.getType() == Type.AABB) {
BoundingBox bb = (BoundingBox) bv;
if (wireBoxGeometryLinkParent != null) {
wireBoxGeometryLinkParent.removeFromParent();
}
wireBoxGeometryLinkParent = WireBox.makeGeometry(bb);
wireBoxGeometryLinkParent.setMaterial(wireBoxMaterial);
wireBoxGeometryLinkParent.setLocalTranslation(bb.getCenter().clone());
if (wireBoxGeometryLinkParent.getParent() == null) {
viewport.getRootNode().attachChild(wireBoxGeometryLinkParent);
}
}
String sLinkText = currentChildElement.getName() + "->" + prefab.getName();
linkText.setText(sLinkText);
linkText.setLocalTranslation(click2d.x, click2d.y, .2f);
//linkText.updateModelBound();
//System.out.println("Setting linkText on : " + click2d );
textBackground.setDimension(linkText.getLineWidth() + 2, linkText.getLineHeight() + 4);
textBackgroundGeometry.updateModelBound();
textBackgroundGeometry.setLocalTranslation(click2d.x - 1, click2d.y - linkText.getLineHeight() - 2, .1f);
return result.getContactPoint();
} else {
wireBoxGeometryLinkParent.removeFromParent();
return result.getContactPoint();
}
}
示例15: doPickText
import com.jme3.collision.CollisionResult; //导入方法依赖的package包/类
private void doPickText() {
CollisionResults results = new CollisionResults();
// Convert screen click to 3d position
Vector2f click2d = viewport.getInputManager().getCursorPosition();
Camera cam = viewport.getCamera();
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);
// Aim the ray from the clicked spot forwards.
Ray ray = new Ray(click3d, dir);
// Collect intersections between ray and all nodes in results list.
Node sceneElements = viewport.getSceneElements();
sceneElements.collideWith(ray, results);
CollisionResult result = results.getClosestCollision();
if (result == null) {
linkText.setText("");
textBackground.setDimension(0, 0);
textBackgroundGeometry.updateModelBound();
return;
}
Geometry g = result.getGeometry();
Prefab prefab = viewport.findPrefabParent(g);
if (prefab != null) {
prefab.updateModelBound();
BoundingVolume bv = prefab.getWorldBound();
if (bv.getType() == BoundingVolume.Type.AABB) {
BoundingBox bb = (BoundingBox) bv;
if ( wireBoxGeometryLinkParent != null ){
wireBoxGeometryLinkParent.removeFromParent();
}
wireBoxGeometryLinkParent = WireBox.makeGeometry(bb);
wireBoxGeometryLinkParent.setMaterial(wireBoxMaterial);
wireBoxGeometryLinkParent.setLocalTranslation(bb.getCenter().clone());
if (wireBoxGeometryLinkParent.getParent() == null) {
viewport.getRootNode().attachChild(wireBoxGeometryLinkParent);
}
}
linkText.setText(prefab.getName());
linkText.setLocalTranslation(click2d.x, click2d.y, 0.01f);
textBackground.setDimension(linkText.getLineWidth() + 2, linkText.getLineHeight() + 4);
textBackgroundGeometry.updateModelBound();
textBackgroundGeometry.setLocalTranslation(click2d.x - 1, click2d.y - linkText.getLineHeight() - 2, 0f);
} else {
linkText.setText("");
textBackground.setDimension(0, 0);
textBackgroundGeometry.updateModelBound();
wireBoxGeometryLinkParent.removeFromParent();
}
}