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


Java Ray.setOrigin方法代码示例

本文整理汇总了Java中com.jme3.math.Ray.setOrigin方法的典型用法代码示例。如果您正苦于以下问题:Java Ray.setOrigin方法的具体用法?Java Ray.setOrigin怎么用?Java Ray.setOrigin使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.jme3.math.Ray的用法示例。


在下文中一共展示了Ray.setOrigin方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: doPick

import com.jme3.math.Ray; //导入方法依赖的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

示例2: getTerrainCollisionPoint

import com.jme3.math.Ray; //导入方法依赖的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

示例3: getTerrainCollisionPoint

import com.jme3.math.Ray; //导入方法依赖的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();
}
 
开发者ID:chototsu,项目名称:MikuMikuStudio,代码行数:27,代码来源:TerrainCameraController.java

示例4: getCollisionFromScreenPos

import com.jme3.math.Ray; //导入方法依赖的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

示例5: pick

import com.jme3.math.Ray; //导入方法依赖的package包/类
private static CollisionResult pick(Camera cam, Vector2f mouseLoc, Node node) {
    CollisionResults results = new CollisionResults();
    Ray ray = new Ray();
    Vector3f pos = cam.getWorldCoordinates(mouseLoc, 0).clone();
    Vector3f dir = cam.getWorldCoordinates(mouseLoc, 0.125f).clone();
    dir.subtractLocal(pos).normalizeLocal();
    ray.setOrigin(pos);
    ray.setDirection(dir);
    node.collideWith(ray, results);
    CollisionResult result = results.getClosestCollision();
    return result;
}
 
开发者ID:jMonkeyEngine,项目名称:sdk,代码行数:13,代码来源:SceneEditTool.java

示例6: pickActors

import com.jme3.math.Ray; //导入方法依赖的package包/类
private List<Actor> pickActors(List<Actor> store) {
    TempVars tv = TempVars.get();
    
    Vector2f v2d = tv.vect2d.set(app.getInputManager().getCursorPosition());
    Vector3f click3d = app.getCamera().getWorldCoordinates(v2d, 0, tv.vect1);
    Vector3f dir = app.getCamera().getWorldCoordinates(v2d, 1, tv.vect2)
            .subtractLocal(click3d).normalizeLocal();
    
    Ray ray = new Ray();
    ray.setOrigin(click3d);
    ray.setDirection(dir);
    
    List<Actor> temps = new ArrayList<Actor>();
    scene.getEntities(Actor.class, temps);
   BoundingVolume bv;
    for (Actor a : temps) {
        bv = a.getSpatial().getWorldBound();
        if (bv == null) {
            continue;
        }
        if (bv.intersects(ray)) {
            store.add(a);
        }
    }
    sortEntities(store);
    tv.release();
    return store;
}
 
开发者ID:huliqing,项目名称:LuoYing,代码行数:29,代码来源:SimpleRpgGame.java

示例7: pick

import com.jme3.math.Ray; //导入方法依赖的package包/类
private CollisionResult pick(Camera cam, Vector2f mouseLoc, Node node) {
    CollisionResults results = new CollisionResults();
    Ray ray = new Ray();
    Vector3f pos = cam.getWorldCoordinates(mouseLoc, 0).clone();
    Vector3f dir = cam.getWorldCoordinates(mouseLoc, 0.1f).clone();
    dir.subtractLocal(pos).normalizeLocal();
    ray.setOrigin(pos);
    ray.setDirection(dir);
    node.collideWith(ray, results);
    CollisionResult result = results.getClosestCollision();
    return result;
}
 
开发者ID:chototsu,项目名称:MikuMikuStudio,代码行数:13,代码来源:SceneEditTool.java

示例8: computeLodEntropy

import com.jme3.math.Ray; //导入方法依赖的package包/类
public static float computeLodEntropy(Mesh terrainBlock, IntBuffer lodIndices){
    // Bounding box for the terrain block
    BoundingBox bbox = (BoundingBox) terrainBlock.getBound();

    // Vertex positions for the block
    FloatBuffer positions = terrainBlock.getFloatBuffer(Type.Position);

    // Prepare to cast rays
    Vector3f pos = new Vector3f();
    Vector3f dir = new Vector3f(0, -1, 0);
    Ray ray = new Ray(pos, dir);

    // Prepare collision results
    CollisionResults results = new CollisionResults();

    // Set the LOD indices on the block
    VertexBuffer originalIndices = terrainBlock.getBuffer(Type.Index);

    terrainBlock.clearBuffer(Type.Index);
    terrainBlock.setBuffer(Type.Index, 3, lodIndices);

    // Recalculate collision mesh
    terrainBlock.createCollisionData();

    float entropy = 0;
    for (int i = 0; i < positions.capacity() / 3; i++){
        BufferUtils.populateFromBuffer(pos, positions, i);

        float realHeight = pos.y;

        pos.addLocal(0, bbox.getYExtent(), 0);
        ray.setOrigin(pos);

        results.clear();
        terrainBlock.collideWith(ray, Matrix4f.IDENTITY, bbox, results);

        if (results.size() > 0){
            Vector3f contactPoint = results.getClosestCollision().getContactPoint();
            float delta = Math.abs(realHeight - contactPoint.y);
            entropy = Math.max(delta, entropy);
        }
    }

    // Restore original indices
    terrainBlock.clearBuffer(Type.Index);
    terrainBlock.setBuffer(originalIndices);

    return entropy;
}
 
开发者ID:mleoking,项目名称:PhET,代码行数:50,代码来源:EntropyComputeUtil.java

示例9: hasObstacleActor

import com.jme3.math.Ray; //导入方法依赖的package包/类
private boolean hasObstacleActor(Entity self, List<Actor> actors) {
        TempVars tv = TempVars.get();
        Temp temp = Temp.get();
        
        ActorModule selfActorModule = self.getModule(ActorModule.class);
        Vector3f viewDirection;
        if (selfActorModule != null) {
            viewDirection = selfActorModule.getViewDirection();
        } else {
            viewDirection = self.getSpatial().getWorldRotation().multLocal(new Vector3f(0,0,1));
        }
        
        Vector3f origin = tv.vect1.set(self.getSpatial().getWorldBound().getCenter());
        Vector3f dir = tv.vect2.set(viewDirection).normalizeLocal();
        float zExtent = GeometryUtils.getBoundingVolumeZExtent(self.getSpatial());
        origin.addLocal(dir.mult(zExtent, tv.vect3));
        
//        DebugDynamicUtils.debugArrow(self.toString(), origin, dir, zExtent);
        
        // 检查碰撞
//        float checkDistance = zExtent;
        float checkDistance = zExtent * 1.5f; // modify20160504, * 1.5f,稍微加大了一点距离
        float checkDistanceSquare = checkDistance * checkDistance;
        Vector3f targetOrigin = tv.vect4;
        
        boolean obstacle = false;
        Ray ray = temp.ray;
        ray.setOrigin(origin);
        ray.setDirection(dir);
        ray.setLimit(checkDistance);
        for (Entity a : actors) {
            if (a == self) {
                continue;
            }
            
            // 如果距离跳过checkDistance,则不视为障碍(该判断用于优化性能)
            // 减少ray检测
            targetOrigin.set(a.getSpatial().getWorldBound().getCenter());
            if (targetOrigin.distanceSquared(origin) > checkDistanceSquare) {
                continue;
            }
            
            // 使用ray也可以,但是使用WorldBound可能性能更好一些。
            if (a.getSpatial().getWorldBound().intersects(ray)) {
                obstacle = true;
                break;
            }
        }
        
        // 释放缓存
        tv.release();
        temp.release();
        return obstacle;
    }
 
开发者ID:huliqing,项目名称:LuoYing,代码行数:55,代码来源:RayDetour.java

示例10: computeLodEntropy

import com.jme3.math.Ray; //导入方法依赖的package包/类
public static float computeLodEntropy(Mesh terrainBlock, Buffer lodIndices){
    // Bounding box for the terrain block
    BoundingBox bbox = (BoundingBox) terrainBlock.getBound();

    // Vertex positions for the block
    FloatBuffer positions = terrainBlock.getFloatBuffer(Type.Position);

    // Prepare to cast rays
    Vector3f pos = new Vector3f();
    Vector3f dir = new Vector3f(0, -1, 0);
    Ray ray = new Ray(pos, dir);

    // Prepare collision results
    CollisionResults results = new CollisionResults();

    // Set the LOD indices on the block
    VertexBuffer originalIndices = terrainBlock.getBuffer(Type.Index);

    terrainBlock.clearBuffer(Type.Index);
    if (lodIndices instanceof IntBuffer)
        terrainBlock.setBuffer(Type.Index, 3, (IntBuffer)lodIndices);
    else if (lodIndices instanceof ShortBuffer) {
        terrainBlock.setBuffer(Type.Index, 3, (ShortBuffer) lodIndices);
    }

    // Recalculate collision mesh
    terrainBlock.createCollisionData();

    float entropy = 0;
    for (int i = 0; i < positions.limit() / 3; i++){
        BufferUtils.populateFromBuffer(pos, positions, i);

        float realHeight = pos.y;

        pos.addLocal(0, bbox.getYExtent(), 0);
        ray.setOrigin(pos);

        results.clear();
        terrainBlock.collideWith(ray, Matrix4f.IDENTITY, bbox, results);

        if (results.size() > 0){
            Vector3f contactPoint = results.getClosestCollision().getContactPoint();
            float delta = Math.abs(realHeight - contactPoint.y);
            entropy = Math.max(delta, entropy);
        }
    }

    // Restore original indices
    terrainBlock.clearBuffer(Type.Index);
    terrainBlock.setBuffer(originalIndices);

    return entropy;
}
 
开发者ID:chototsu,项目名称:MikuMikuStudio,代码行数:54,代码来源:EntropyComputeUtil.java


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