本文整理匯總了Java中com.jme3.scene.Spatial.collideWith方法的典型用法代碼示例。如果您正苦於以下問題:Java Spatial.collideWith方法的具體用法?Java Spatial.collideWith怎麽用?Java Spatial.collideWith使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.jme3.scene.Spatial
的用法示例。
在下文中一共展示了Spatial.collideWith方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getCollisionFromScreenPos
import com.jme3.scene.Spatial; //導入方法依賴的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();
}
示例2: renderDepth
import com.jme3.scene.Spatial; //導入方法依賴的package包/類
public BufferedImage renderDepth( File fout, float scale, Pano pano, Spatial scene, double minDepth, double maxDepth ) {
BufferedImage out = new BufferedImage( (int) ( a.distance( b ) * scale ), (int) ( ( heightMax- heightMin) * scale ), BufferedImage.TYPE_3BYTE_BGR );
Vector3f o = Jme3z.to ( pano.location );
for ( int x = 0; x < out.getWidth(); x++ ) {
for ( int y = 0; y < out.getHeight(); y++ ) {
CollisionResults results = new CollisionResults();
float[] target = uvToWorld( x / (float) out.getWidth(), 1 - ( y / (float) out.getHeight() ) );
Vector3f ray = new Vector3f (target[0], target[1], target[2]);
ray.subtractLocal( o );
scene.collideWith(new Ray( o, ray), results);
CollisionResult cr = results.getClosestCollision();
double dist = maxDepth;
if (cr != null)
dist = Math.min (maxDepth, cr.getDistance() );
dist = Mathz.clamp ( ( dist - minDepth ) / ( maxDepth - minDepth ), 0, 1);
int d = (int)(dist * 256);
double r = dist*256 - d;
int c = Colour.asInt(
Mathz.clamp ( d + (r > 0.25 ? 1 : 0), 0, 255),
Mathz.clamp ( d + (r > 0.50 ? 1 : 0), 0, 255),
Mathz.clamp ( d + (r > 0.75 ? 1 : 0), 0, 255) );
out.setRGB( x, y, c );
}
System.out.println( x + " / " + out.getWidth() );
}
if ( fout != null )
try {
ImageIO.write( out, "png", fout );
} catch ( IOException e1 ) {
e1.printStackTrace();
}
return out;
}