本文整理汇总了Java中com.jme3.math.Ray类的典型用法代码示例。如果您正苦于以下问题:Java Ray类的具体用法?Java Ray怎么用?Java Ray使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Ray类属于com.jme3.math包,在下文中一共展示了Ray类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onAnalog
import com.jme3.math.Ray; //导入依赖的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.math.Ray; //导入依赖的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: getClicked
import com.jme3.math.Ray; //导入依赖的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;
}
示例4: main
import com.jme3.math.Ray; //导入依赖的package包/类
public static void main(String[] args){
Ray r = new Ray(Vector3f.ZERO, Vector3f.UNIT_X);
BoundingBox bbox = new BoundingBox(new Vector3f(5, 0, 0), 1, 1, 1);
CollisionResults res = new CollisionResults();
bbox.collideWith(r, res);
System.out.println("Bounding:" +bbox);
System.out.println("Ray: "+r);
System.out.println("Num collisions: "+res.size());
for (int i = 0; i < res.size(); i++){
System.out.println("--- Collision #"+i+" ---");
float dist = res.getCollision(i).getDistance();
Vector3f pt = res.getCollision(i).getContactPoint();
System.out.println("distance: "+dist);
System.out.println("point: "+pt);
}
}
示例5: checkTriangles
import com.jme3.math.Ray; //导入依赖的package包/类
protected boolean checkTriangles(float gridX, float gridY, Ray pick, Vector3f intersection, TerrainPatch patch, Triangle store) {
if (!getTriangles(gridX, gridY, patch))
return false;
if (pick.intersectWhere(gridTriA, intersection)) {
store.set(gridTriA.get1(), gridTriA.get2(), gridTriA.get3());
return true;
} else {
if (pick.intersectWhere(gridTriB, intersection)) {
store.set(gridTriB.get1(), gridTriB.get2(), gridTriB.get3());
return true;
}
}
return false;
}
示例6: collideWith
import com.jme3.math.Ray; //导入依赖的package包/类
@Override
public int collideWith(Collidable other, CollisionResults results) throws UnsupportedCollisionException {
if (refreshFlags != 0)
throw new IllegalStateException("Scene graph must be updated" +
" before checking collision");
if (other instanceof BoundingVolume)
if (!getWorldBound().intersects((BoundingVolume)other))
return 0;
if(other instanceof Ray)
return collideWithRay((Ray)other, results);
else if (other instanceof BoundingVolume)
return collideWithBoundingVolume((BoundingVolume)other, results);
else {
throw new UnsupportedCollisionException("TerrainPatch cannnot collide with "+other.getClass().getName());
}
}
示例7: getHeight
import com.jme3.math.Ray; //导入依赖的package包/类
protected float getHeight(float x, float z, Vector2f xz) {
float topLeft = getHeightmapHeight((int)FastMath.floor(x), (int)FastMath.ceil(z));
float topRight = getHeightmapHeight((int)FastMath.ceil(x), (int)FastMath.ceil(z));
float bottomLeft = getHeightmapHeight((int)FastMath.floor(x), (int)FastMath.floor(z));
float bottomRight = getHeightmapHeight((int)FastMath.ceil(x), (int)FastMath.floor(z));
// create a vertical, down-facing, ray and get the height from that
float max = Math.max(Math.max(Math.max(topLeft, topRight), bottomRight),bottomLeft);
max = max*getWorldScale().y;
Ray ray = new Ray(new Vector3f(xz.x,max+10f,xz.y), new Vector3f(0,-1,0).normalizeLocal());
CollisionResults cr = new CollisionResults();
int num = this.collideWith(ray, cr);
if (num > 0)
return cr.getClosestCollision().getContactPoint().y;
else
return 0;
}
示例8: collideWith
import com.jme3.math.Ray; //导入依赖的package包/类
@Override
public int collideWith(Collidable other, CollisionResults results){
int total = 0;
if (other instanceof Ray)
return collideWithRay((Ray)other, results);
// if it didn't collide with this bbox, return
if (other instanceof BoundingVolume)
if (!this.getWorldBound().intersects((BoundingVolume)other))
return total;
for (Spatial child : children){
total += child.collideWith(other, results);
}
return total;
}
示例9: findPick
import com.jme3.math.Ray; //导入依赖的package包/类
/**
* Gather the terrain patches that intersect the given ray (toTest).
* This only tests the bounding boxes
* @param toTest
* @param results
*/
public void findPick(Ray toTest, List<TerrainPickData> results) {
if (getWorldBound() != null) {
if (getWorldBound().intersects(toTest)) {
// further checking needed.
for (int i = 0; i < getQuantity(); i++) {
if (children.get(i) instanceof TerrainPatch) {
TerrainPatch tp = (TerrainPatch) children.get(i);
if (tp.getWorldBound().intersects(toTest)) {
CollisionResults cr = new CollisionResults();
toTest.collideWith(tp.getWorldBound(), cr);
if (cr != null && cr.getClosestCollision() != null) {
cr.getClosestCollision().getDistance();
results.add(new TerrainPickData(tp, cr.getClosestCollision()));
}
}
}
else
((TerrainQuad) children.get(i)).findPick(toTest, results);
}
}
}
}
示例10: collideWith
import com.jme3.math.Ray; //导入依赖的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());
}
}
示例11: intersects
import com.jme3.math.Ray; //导入依赖的package包/类
public boolean intersects(Ray ray) {
assert Vector3f.isValidVector(center);
TempVars vars = TempVars.get();
Vector3f diff = vars.vect1.set(ray.getOrigin()).subtractLocal(center);
float radiusSquared = getRadius() * getRadius();
float a = diff.dot(diff) - radiusSquared;
if (a <= 0.0) {
// in sphere
return true;
}
// outside sphere
float b = ray.getDirection().dot(diff);
vars.release();
if (b >= 0.0) {
return false;
}
return b * b >= a;
}
示例12: intersectWhere
import com.jme3.math.Ray; //导入依赖的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);
}
}
}
示例13: 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;
}
示例14: 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();
}
示例15: distanceOfPick
import com.jme3.math.Ray; //导入依赖的package包/类
/**
* 获取射线与指定Spatial的碰撞的最近点,如果不存在碰撞则返回null.
* @param ray
* @param spatial
* @return
*/
public final static Float distanceOfPick(Ray ray, Spatial spatial) {
BoundingVolume bv = spatial.getWorldBound();
if (bv == null || !bv.intersects(ray))
return null;
TempPick tp = TempPick.get();
CollisionResults cr = tp.results;
cr.clear();
PickManager.pickResults(ray, spatial, cr);
Float result = null;
if (cr.size() > 0) {
result = cr.getClosestCollision().getDistance();
}
tp.release();
return result;
}