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


Java CollisionResult类代码示例

本文整理汇总了Java中com.jme3.collision.CollisionResult的典型用法代码示例。如果您正苦于以下问题:Java CollisionResult类的具体用法?Java CollisionResult怎么用?Java CollisionResult使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


CollisionResult类属于com.jme3.collision包,在下文中一共展示了CollisionResult类的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 ) ));
}
 
开发者ID:twak,项目名称:chordatlas,代码行数:22,代码来源:Tweed.java

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

示例3: getClicked

import com.jme3.collision.CollisionResult; //导入依赖的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;
}
 
开发者ID:twak,项目名称:chordatlas,代码行数:18,代码来源:Tweed.java

示例4: setCollisionPlane

import com.jme3.collision.CollisionResult; //导入依赖的package包/类
@Override
public void setCollisionPlane(@NotNull final CollisionResult collisionResult) {

    final EditorTransformSupport editorControl = getEditorControl();
    final Transform transform = editorControl.getTransformCenter();

    if (transform == null) {
        LOGGER.warning(this, "not found transform center for the " + editorControl);
        return;
    }

    detectPickedAxis(editorControl, collisionResult);

    // set the collision Plane location and rotation
    final Node collisionPlane = getCollisionPlane();
    collisionPlane.setLocalTranslation(transform.getTranslation());
    collisionPlane.setLocalRotation(Quaternion.IDENTITY);
}
 
开发者ID:JavaSaBr,项目名称:jmonkeybuilder,代码行数:19,代码来源:AbstractTransformControl.java

示例5: collideWith

import com.jme3.collision.CollisionResult; //导入依赖的package包/类
public int collideWith(Collidable other, CollisionResults results) {
    if (other instanceof BoundingVolume) {
        BoundingVolume bv = (BoundingVolume) other;
        return bv.collideWith(this, results);
    } else if (other instanceof AbstractTriangle) {
        AbstractTriangle tri = (AbstractTriangle) other;
        float d = intersects(tri.get1(), tri.get2(), tri.get3());
        if (Float.isInfinite(d) || Float.isNaN(d)) {
            return 0;
        }

        Vector3f point = new Vector3f(direction).multLocal(d).addLocal(origin);
        results.addCollision(new CollisionResult(point, d));
        return 1;
    } else {
        throw new UnsupportedCollisionException();
    }
}
 
开发者ID:mleoking,项目名称:PhET,代码行数:19,代码来源:Ray.java

示例6: collideWith

import com.jme3.collision.CollisionResult; //导入依赖的package包/类
public int collideWith(Collidable other, CollisionResults results) {
    if (other instanceof Ray) {
        Ray ray = (Ray) other;
        return collideWithRay(ray, results);
    } else if (other instanceof Triangle) {
        Triangle t = (Triangle) other;
        if (intersects(t.get1(), t.get2(), t.get3())) {
            CollisionResult r = new CollisionResult();
            results.addCollision(r);
            return 1;
        }
        return 0;
    } else {
        throw new UnsupportedCollisionException("With: " + other.getClass().getSimpleName());
    }
}
 
开发者ID:mleoking,项目名称:PhET,代码行数:17,代码来源:BoundingBox.java

示例7: intersectWhere

import com.jme3.collision.CollisionResult; //导入依赖的package包/类
public final void intersectWhere(Ray r, Geometry[] geoms, float sceneMin, float sceneMax,
                                        CollisionResults results){
    for (OCTTriangle t : tris){
        float d = r.intersects(t.get1(), t.get2(), t.get3());
        if (Float.isInfinite(d))
            continue;

        Vector3f contactPoint = new Vector3f(r.getDirection()).multLocal(d).addLocal(r.getOrigin());
        CollisionResult result = new CollisionResult(geoms[t.getGeometryIndex()],
                                                     contactPoint,
                                                     d,
                                                     t.getTriangleIndex());
        results.addCollision(result);
    }
    for (int i = 0; i < 8; i++){
        Octnode child = children[i];
        if (child == null)
            continue;

        if (child.bbox.intersects(r)){
            child.intersectWhere(r, geoms, sceneMin, sceneMax, results);
        }
    }
}
 
开发者ID:mleoking,项目名称:PhET,代码行数:25,代码来源:Octnode.java

示例8: doPick

import com.jme3.collision.CollisionResult; //导入依赖的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;
}
 
开发者ID:jMonkeyEngine,项目名称:sdk,代码行数:27,代码来源:SceneEditTool.java

示例9: 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();
}
 
开发者ID:jMonkeyEngine,项目名称:sdk,代码行数:24,代码来源:TerrainCameraController.java

示例10: getTerrainHeight

import com.jme3.collision.CollisionResult; //导入依赖的package包/类
/**
 * @deprecated 不再使用这个方法,在position超出terrain的范围的时候可能会获得不正确的值。
 * 获得terrain的高位位置,并将结果存放到position返回
 * @param terrain
 * @param position 指定的地点
 * @return 
 */
public static Vector3f getTerrainHeight(Spatial terrain, Vector3f position) {
    // 设置随机点的高度值
    TempVars tv = TempVars.get();
    Temp tp = Temp.get();
    Vector3f ori = tv.vect1.set(position).setY(999999);
    Vector3f dir = tv.vect2.set(position).setY(-999999).subtractLocal(ori);
    CollisionResults store = tp.results;
    store.clear();
    RayUtils.collideWith(ori, dir, terrain, store);
    CollisionResult result = store.getFarthestCollision();
    if (result != null) {
        position.set(result.getContactPoint());
    }
    tv.release();
    tp.release();
    return position;
}
 
开发者ID:huliqing,项目名称:LuoYing,代码行数:25,代码来源:GeometryUtils.java

示例11: hasObstacle

import com.jme3.collision.CollisionResult; //导入依赖的package包/类
private boolean hasObstacle(Spatial root, Vector3f origin, Vector3f direction, float limit) {
        Temp tp = Temp.get();
        CollisionResults results = tp.results;
        results.clear();
        collideWith(origin, direction, root, results);
        boolean result = false;
        for (CollisionResult r : results) {
            if (r.getDistance() > limit) {
                break;
            }
            if (isObstacle(r.getGeometry())) {
                // 障碍物找到
//                Log.get(GeometryUtils.class).log(Level.INFO, "Found obstacle infront! distance={0}, name={1}"
//                        , new Object[] {r.getDistance(), r.getGeometry().getName()});
                result = true;
                break;
            }
 
        }
        tp.release();
        return result;
    }
 
开发者ID:huliqing,项目名称:LuoYing,代码行数:23,代码来源:SummonItem.java

示例12: 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);
    }
}
 
开发者ID:matthewseal,项目名称:MoleculeViewer,代码行数:23,代码来源:MVAppState.java

示例13: addToBlockTerrain

import com.jme3.collision.CollisionResult; //导入依赖的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);
                }
            }
        }
    }
}
 
开发者ID:jMonkeyEngine-Contributions,项目名称:cubes,代码行数:27,代码来源:BlockModel.java

示例14: 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;
        }
    }
 
开发者ID:MultiverseKing,项目名称:HexGrid_JME,代码行数:30,代码来源:GridRayCastControl.java

示例15: MouseRayInputAction

import com.jme3.collision.CollisionResult; //导入依赖的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;
}
 
开发者ID:MultiverseKing,项目名称:MultiverseKing_JME,代码行数:26,代码来源:BattleSystem.java


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