本文整理汇总了Java中com.jme3.collision.CollisionResult.getContactPoint方法的典型用法代码示例。如果您正苦于以下问题:Java CollisionResult.getContactPoint方法的具体用法?Java CollisionResult.getContactPoint怎么用?Java CollisionResult.getContactPoint使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.jme3.collision.CollisionResult
的用法示例。
在下文中一共展示了CollisionResult.getContactPoint方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onAnalog
import com.jme3.collision.CollisionResult; //导入方法依赖的package包/类
@Override
public void onAnalog( String name, float value, float tpf ) {
CollisionResult cr = getClicked();
Vector3f pos = null;
if (cr != null)
pos = cr.getContactPoint();
if (pos == null) {
Vector3f dir = cam.getWorldCoordinates( getInputManager().getCursorPosition(), -10 );
dir.subtractLocal( cam.getLocation() );
new Ray( cam.getLocation(), dir ).intersectsWherePlane( new Plane(Jme3z.UP, 0), pos = new Vector3f() );
}
cursorPosition = Jme3z.from( pos );
if (pos != null)
point.setPosition( pos.add ( cam.getDirection().mult( -0.3f ) ));
}
示例2: getSurfaceSelected
import com.jme3.collision.CollisionResult; //导入方法依赖的package包/类
private Vector3f getSurfaceSelected(float dist) {
CollisionResult cr = getClicked();
Vector3f pos = null;
if (cr != null)
pos = cr.getContactPoint();
if (pos == null) {
Vector3f dir = cam.getWorldCoordinates( getInputManager().getCursorPosition(), -dist );
dir.subtractLocal( cam.getLocation() );
new Ray( cam.getLocation(), dir ).intersectsWherePlane( new Plane(Jme3z.UP, 0), pos = new Vector3f() );
}
return pos;
}
示例3: getTerrainCollisionPoint
import com.jme3.collision.CollisionResult; //导入方法依赖的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();
}
示例4: castRay
import com.jme3.collision.CollisionResult; //导入方法依赖的package包/类
/**
* Cast the defined ray on the defined collision node then return it
* converted as Hex event.
* @todo Does not work properly when picking a tile by the side
* @param ray Can be get from {@link #get3DRay(CastFrom)}
* @return null if no collision.
*/
public MouseInputEvent castRay(Ray ray) {
CollisionResults results = new CollisionResults();
ray = ray != null ? ray : get3DRay(CastFrom.SCREEN_CENTER);
collisionNode.collideWith(ray, results);
if (results.size() != 0) {
for (int i = 0; i < results.size(); i++) {
CollisionResult closest = results.getCollision(i);
if (!closest.getGeometry().getParent().getName().equals(HexGridBuffer.class.getName() + ":FX:Node")) {
setDebugPosition(closest.getContactPoint());
// HexCoordinate newPos = convertMouseCollision(results);
HexCoordinate newPos = new HexCoordinate(closest.getContactPoint());
return new MouseInputEvent(null, newPos, null, ray, closest);
}
}
return null;
} else {
//Error catching.
LoggerFactory.getLogger(GridRayCastControl.class).debug("Null raycast on {}", collisionNode);
rayDebug.removeFromParent();
return null;
}
}
示例5: processExitSurface
import com.jme3.collision.CollisionResult; //导入方法依赖的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();
}
}
示例6: getTerrainCollisionPoint
import com.jme3.collision.CollisionResult; //导入方法依赖的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();
}
示例7: 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;
}
示例8: getWorldIntersection
import com.jme3.collision.CollisionResult; //导入方法依赖的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;
}
示例9: pickWorldLocation
import com.jme3.collision.CollisionResult; //导入方法依赖的package包/类
public static Vector3f pickWorldLocation(Camera cam, Vector2f mouseLoc, Node rootNode, Spatial exclude) {
CollisionResult cr = doPick(cam, mouseLoc, rootNode, exclude);
if (cr != null) {
return cr.getContactPoint();
} else {
return null;
}
}
示例10: getCursorPosOnMovingPlane
import com.jme3.collision.CollisionResult; //导入方法依赖的package包/类
private Vector3f getCursorPosOnMovingPlane() {
CollisionResult res = getCursorClosestCollision(movingPlane);
if (res != null) {
return res.getContactPoint();
} else {
return null;
}
}
示例11: controlUpdate
import com.jme3.collision.CollisionResult; //导入方法依赖的package包/类
@Override
protected void controlUpdate(float tpf) {
terrain = ((Node) spatial.getParent()).getChild("terrain-freeGame01Scene");
if(terrain != null) {
ray.setOrigin(spatial.getWorldTranslation().add(up));
ray.setLimit(200.0f);
collisionResults.clear();
terrain.collideWith(ray, collisionResults);
for(CollisionResult collisionResult : collisionResults) {
Vector3f collisionLocal = collisionResult.getContactPoint();
spatial.setLocalTranslation(spatial.getLocalTranslation().setY(collisionLocal.getY() + offset));
}
}
}
示例12: changeTargetPosition
import com.jme3.collision.CollisionResult; //导入方法依赖的package包/类
/**
* Metod for changing target position.
*
* @param tpf time per frame
*/
protected void changeTargetPosition(float tpf) {
time -= tpf;
Vector3f forward;
if (this.agent.getVelocity() != null) {
forward = this.agent.getVelocity().normalize();
} else {
forward = this.agent.fordwardVector();
}
if (forward.equals(Vector3f.UNIT_Y)) {
forward = forward.add(new Vector3f(0, 0, SphereWanderBehavior.SIDE_REFERENCE_OFFSET));
}
//Update sphere position
this.wanderSphere.setCenter(this.agent.getLocalTranslation().add(forward.mult(SphereWanderBehavior.OFFSET_DISTANCE + this.agent.getRadius() + this.sphereRadius)));
if (time <= 0) {
this.calculateNewRandomDir();
time = timeInterval;
}
Vector3f sideVector = forward.cross(Vector3f.UNIT_Y).normalize();
Vector3f rayDir = (this.agent.offset(wanderSphere.getCenter())).add(sideVector.mult(this.randomDirection.x));//.add(Vector3f.UNIT_Y.mult(this.randomDirection.y));
Ray ray = new Ray(this.agent.getLocalTranslation(), rayDir);
CollisionResults results = new CollisionResults();
this.wanderSphere.collideWith(ray, results);
CollisionResult collisionResult = results.getCollision(1); //The collision with the second hemisphere
this.targetPosition = collisionResult.getContactPoint();
}
示例13: getPointedCoord
import com.jme3.collision.CollisionResult; //导入方法依赖的package包/类
public static Point2D getPointedCoord(Node n, Ray r) {
CollisionResult collision = getCollision(n, r);
if (collision == null) {
return null;
}
// return Translator.toPoint2D(collision.getContactPoint());
Vector3f p = collision.getContactPoint();
return new Point2D(p.x, p.y);
}
示例14: pickWorldLocation
import com.jme3.collision.CollisionResult; //导入方法依赖的package包/类
protected Vector3f pickWorldLocation(Camera cam, Vector2f mouseLoc, Node rootNode) {
CollisionResult cr = pick(cam, mouseLoc, rootNode);
if (cr != null) {
return cr.getContactPoint();
} else {
return null;
}
}
示例15: calculateNextFootStep
import com.jme3.collision.CollisionResult; //导入方法依赖的package包/类
private void calculateNextFootStep() {
Vector3f hipLocation = body.getWorldTranslation();
Vector3f moveDirection = new Vector3f(0, 0, -1);
moveDirection = body.getWorldRotation().mult(moveDirection);
moveDirection.y = 0;
moveDirection.normalizeLocal();
// TODO: query up axis from application
Vector3f upVector = new Vector3f(0, 1, 0);
Vector3f sagVector = moveDirection.cross(upVector);
sagVector.normalizeLocal();
// start ray casting from current support foot
Vector3f currentSupport ;
Material material ;
if ("right".equals(type)) {
currentSupport = body.getChild("leftFootJointX").getWorldTranslation();
material = rightFootMaterial;
} else {
currentSupport = body.getChild("rightFootJointX").getWorldTranslation();
material = leftFootMaterial;
}
Vector3f currentDir = currentSupport.subtract(hipLocation);
float dist = currentDir.dot(sagVector);
currentDir.addLocal(-dist * sagVector.x, -dist * sagVector.y, -dist * sagVector.z);
currentDir.normalizeLocal();
float alpha = FastMath.acos(currentDir.dot(moveDirection)) * FastMath.RAD_TO_DEG;
//System.out.println("alpha : " + alpha * FastMath.RAD_TO_DEG);
if (alpha > 70) {
alpha = 70;
}
boolean found = false;
do {
Vector3f rayDirection = moveDirection.mult(FastMath.cos(alpha * FastMath.DEG_TO_RAD)).add(upVector.mult(-FastMath.sin(alpha * FastMath.DEG_TO_RAD)));
Ray ray = new Ray(hipLocation, rayDirection);
results.clear();
// Collect intersections between ray and all nodes in results list.
body.getParent().collideWith(ray, results);
CollisionResult closest = results.getClosestCollision();
if (closest == null) {
alpha -= 1.0f;
continue;
}
if (!body.hasChild(closest.getGeometry())) {
Vector3f normal = closest.getContactNormal();
if (normal.y > .6f) {
found = true;
current = new FootStep(material, closest.getContactPoint());
body.getParent().attachChild(current);
}
}
alpha -= 5.0f;
} while (!found && alpha > 30);
}