当前位置: 首页>>代码示例>>Java>>正文


Java Spatial.collideWith方法代码示例

本文整理汇总了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();
}
 
开发者ID:JavaSaBr,项目名称:jmonkeybuilder,代码行数:39,代码来源:GeomUtils.java

示例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;
}
 
开发者ID:twak,项目名称:chordatlas,代码行数:47,代码来源:ImagePlaneGen.java


注:本文中的com.jme3.scene.Spatial.collideWith方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。