本文整理汇总了Java中com.badlogic.gdx.math.collision.Ray类的典型用法代码示例。如果您正苦于以下问题:Java Ray类的具体用法?Java Ray怎么用?Java Ray使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Ray类属于com.badlogic.gdx.math.collision包,在下文中一共展示了Ray类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: draw
import com.badlogic.gdx.math.collision.Ray; //导入依赖的package包/类
@Override
public void draw(Batch batch, float parentAlpha) {
batch.draw(texture, getX(), getY(), getWidth(), getHeight());
for(int i = 0; i < xCells; i++)
for(int j = 0; j < yCells; j++)
if(cells[i][j] != null) {
batch.draw(cells[i][j].texture, getX() + i * getWidth() / xCells, getY() + j * getHeight() / yCells, getWidth() / xCells, getHeight() / yCells);
if(cells[i][j].price > money.$)
batch.draw(cellX, getX() + i * getWidth() / xCells, getY() + j * getHeight() / yCells, getWidth() / xCells, getHeight() / yCells);
}
if (paused)
return;
if(Gdx.input.isTouched() && lastCell != null) {
Ray ray = camera.getPickRay(Gdx.input.getX(), Gdx.input.getY());
Vector3 pos = Tools.closestRayTest(btcollisionWorld, new ClosestRayResultCallback(ray.origin, new Vector3(ray.direction).setLength(9999).add(ray.origin)));
if(pos != null && Tools.closestRayTestObject(btcollisionWorld, new ClosestRayResultCallback(ray.origin, new Vector3(ray.direction).setLength(9999).add(ray.origin))).getUserValue() == 0) {
Vector3 vector = world.getVector(pos);
if(vector != null && ghost != null) {
ghost.transform.setToTranslation(pos);
ghost.transform.rotate(vector, 30);
}
if(ghost != null)
modelBatch.render(ghost, environment);
}
}
}
示例2: touchEnklave
import com.badlogic.gdx.math.collision.Ray; //导入依赖的package包/类
public boolean touchEnklave(PerspectiveCamera camera,int screenX,int screenY){
coordonate = null;
instanceModel.calculateBoundingBox(box).mul(instanceModel.transform);
box.getCenter(position);
box.getDimensions(dimensions);
Ray ray = camera.getPickRay(screenX,screenY);
// instanceModel.transform.getTranslation(position);
// position.add(box.getCenter(new Vector3()));
// Gdx.app.log("res"+ray.toString(),"position"+position);
if(Intersector.intersectRayBoundsFast(ray,box)){ // position, box.getDimensions(new Vector3()).len(), null)) {
coordonate = new SpaceCoordonate();
coordonate.x = Math.abs(Math.abs(position.x) - Math.abs(camera.position.x)) / (Gdx.graphics.getHeight() * 0.026f);
coordonate.y = Math.abs(Math.abs(position.y) - Math.abs(camera.position.y)) / (Gdx.graphics.getHeight() * 0.026f);
coordonate.z = -(Math.abs((Gdx.graphics.getHeight() * 0.033f) - Math.abs(camera.position.z)) / (Gdx.graphics.getHeight() * 0.026f));
if (box.getCenterX() < camera.position.x) {
coordonate.x = -coordonate.x;
}
if (box.getCenterY() < camera.position.y) {
coordonate.y = -coordonate.y;
}
return true;
}
return false;
}
示例3: drawRay
import com.badlogic.gdx.math.collision.Ray; //导入依赖的package包/类
private void drawRay(GL2 gl, Ray ray) {
float axisSize = 50;
Vector3 v = new Vector3(ray.direction);
v.scl(axisSize);
//Draw Camera Axis
if (colide >= 0) {
gl.glColor3d(1.0, 0.0, 0.0);
} else {
gl.glColor3d(0.0, 0.0, 1.0);
}
gl.glBegin(GL.GL_LINES);
gl.glVertex3d(view.getX(), 1, view.getZ());
gl.glVertex3d(view.getX() + v.x, view.getY() + v.y, view.getZ() + v.z);
gl.glEnd();
}
示例4: getObject
import com.badlogic.gdx.math.collision.Ray; //导入依赖的package包/类
public GameObject getObject (int screenX, int screenY) {
Ray ray = camera.getPickRay(screenX, screenY);
GameObject result = null;
float distance = -1;
for (ModelInstance item : instances) {
if(item instanceof GameObject){
GameObject gameObject = (GameObject) item;
if(gameObject.enabled){
Vector3 position = gameObject.transform.getTranslation(new Vector3());
gameObject.updateBox();
position.add(gameObject.center);
float dist2 = ray.origin.dst2(position);
if (distance >= 0f && dist2 > distance) continue;
if (Intersector.intersectRayBoundsFast(ray, gameObject.bounds)) {
result = gameObject;
distance = dist2;
}
}
}
}
return result;
}
示例5: binarySearch
import com.badlogic.gdx.math.collision.Ray; //导入依赖的package包/类
private Vector3 binarySearch(int count, float start, float finish, Ray ray)
{
float half = start + ((finish - start) * 0.5f);
if (count >= RECURSION_COUNT)
{
return getPointOnRay(ray, half);
}
if (intersectionInRange(start, half, ray))
{
return binarySearch(count + 1, start, half, ray);
}
else
{
return binarySearch(count + 1, half, finish, ray);
}
}
示例6: tap
import com.badlogic.gdx.math.collision.Ray; //导入依赖的package包/类
@Override
public boolean tap (float x, float y, int count, int button) {
Ray ray = camera.getPickRay(x, y);
rayFrom.set(ray.origin);
rayTo.set(ray.direction).scl(50f).add(rayFrom); // 50 meters max from the origin
// Because we reuse the ClosestRayResultCallback, we need reset it's values
rayTestCB.setCollisionObject(null);
rayTestCB.setClosestHitFraction(1f);
rayTestCB.setRayFromWorld(rayFrom);
rayTestCB.setRayToWorld(rayTo);
world.collisionWorld.rayTest(rayFrom, rayTo, rayTestCB);
if (rayTestCB.hasHit()) {
final btCollisionObject obj = rayTestCB.getCollisionObject();
if (!obj.isStaticOrKinematicObject()) {
final btRigidBody body = (btRigidBody)(obj);
body.activate();
body.applyCentralImpulse(tmpV2.set(ray.direction).scl(20f));
}
}
return true;
}
示例7: getRayIntersection
import com.badlogic.gdx.math.collision.Ray; //导入依赖的package包/类
public Vector3 getRayIntersection(Vector3 out, Ray ray) {
// TODO improve performance. use binary search
float curDistance = 2;
int rounds = 0;
ray.getEndPoint(out, curDistance);
boolean isUnder = isUnderTerrain(out);
while (true) {
rounds++;
ray.getEndPoint(out, curDistance);
boolean u = isUnderTerrain(out);
if (u != isUnder || rounds == 10000) {
return out;
}
curDistance += u ? -0.1f : 0.1f;
}
}
示例8: mouseMoved
import com.badlogic.gdx.math.collision.Ray; //导入依赖的package包/类
@Override
public boolean mouseMoved(int screenX, int screenY) {
if (this.model == null || modelInstance == null) return false;
final ProjectContext context = getProjectManager().current();
final Ray ray = getProjectManager().current().currScene.viewport.getPickRay(screenX, screenY);
if (context.currScene.terrains.size > 0 && modelInstance != null) {
MeshPartBuilder.VertexInfo vi = TerrainUtils.getRayIntersectionAndUp(context.currScene.terrains, ray);
if (vi != null) {
if (shouldRespectTerrainSlope) {
modelInstance.transform.setToLookAt(DEFAULT_ORIENTATION, vi.normal);
}
modelInstance.transform.setTranslation(vi.position);
}
} else {
tempV3.set(getProjectManager().current().currScene.cam.position);
tempV3.add(ray.direction.nor().scl(200));
modelInstance.transform.setTranslation(tempV3);
}
return false;
}
示例9: rayTest
import com.badlogic.gdx.math.collision.Ray; //导入依赖的package包/类
public Entity rayTest(Ray ray, Vector3 hitPointWorld, short belongsToFlag, short collidesWithFlag,
float rayDistance, Bits layers) {
rayFrom.set(ray.origin);
rayTo.set(ray.direction).scl(rayDistance).add(rayFrom);
callback.setCollisionObject(null);
callback.setClosestHitFraction(1f);
callback.setRay(ray, rayDistance);
callback.setLayers(layers);
callback.setCollisionFilterMask(belongsToFlag);
callback.setCollisionFilterGroup(collidesWithFlag);
dynamicsWorld.rayTest(rayFrom, rayTo, callback);
if (callback.hasHit()) {
if (hitPointWorld != null) {
callback.getHitPointWorld(hitPointWorld);
}
long entityId = callback.getCollisionObject().getUserPointer();
return getEntity(entityId);
}
return null;
}
示例10: rayTest
import com.badlogic.gdx.math.collision.Ray; //导入依赖的package包/类
/**
* Get the triangle which this ray intersects. Returns null if no triangle is intersected.
*
* @param ray
* @param distance
* @param allowedMeshParts
* @return
*/
public Triangle rayTest(Ray ray, float distance, Bits allowedMeshParts) {
Triangle hitTriangle = null;
tmpRayTestRayFrom.set(ray.origin);
tmpRayTestRayTo.set(ray.direction).scl(distance).add(tmpRayTestRayFrom);
raycastCallback.setHitFraction(1);
raycastCallback.clearReport();
raycastCallback.setFrom(tmpRayTestRayFrom);
raycastCallback.setTo(tmpRayTestRayTo);
raycastCallback.setAllowedMeshPartIndices(allowedMeshParts);
collisionShape.performRaycast(raycastCallback, tmpRayTestRayFrom, tmpRayTestRayTo);
if (raycastCallback.triangleIndex != -1) {
hitTriangle = graph.getTriangleFromMeshPart(raycastCallback.partId, raycastCallback.triangleIndex);
}
return hitTriangle;
}
示例11: processDragPan
import com.badlogic.gdx.math.collision.Ray; //导入依赖的package包/类
public void processDragPan(Ray dragCurrentRay, Ray lastDragProcessedRay) {
followTarget = null;
// TODO:
// Can probably be optimized, but simply storing worldDragLast.set(worldDragCurrent)
// caused jitter for some reason.
Intersector.intersectRayPlane(dragCurrentRay, worldGroundPlane, worldDragCurrent);
Intersector.intersectRayPlane(lastDragProcessedRay, worldGroundPlane, worldDragLast);
tmp1.set(worldDragLast).sub(worldDragCurrent);
tmp1.y = 0;
ray.origin.set(camera.targetPosition).add(tmp1);
ray.direction.set(camera.targetDirection);
if (Intersector.intersectRayBoundsFast(ray, worldBoundingBox)) {
camera.targetPosition.add(tmp1);
worldGroundTarget.add(tmp1);
}
}
示例12: calculateCameraPickIntersection
import com.badlogic.gdx.math.collision.Ray; //导入依赖的package包/类
public Vector3 calculateCameraPickIntersection(Camera camera, int screenX, int screenY, Vector3 out) {
Ray pickRay = camera.getPickRay(screenX, screenY);
rayFrom.set(pickRay.origin);
tmpVector2.set(pickRay.direction).nor().scl(1000);
tmpVector.set(pickRay.origin).add(tmpVector2);
rayTo.set(tmpVector);
callback.setCollisionObject(null);
callback.setClosestHitFraction(1f);
callback.setRayFromWorld(rayFrom);
callback.setRayToWorld(rayTo);
callback.setCollisionFilterMask((short) -1);
callback.setCollisionFilterGroup((short) -1);
dynamicsWorld.rayTest(rayFrom, rayTo, callback);
if (callback.hasHit()) {
callback.getHitPointWorld(out);
return out;
}
return null;
}
示例13: intersect
import com.badlogic.gdx.math.collision.Ray; //导入依赖的package包/类
/**
* Intersects the shape with a Ray
*
* @see Ray
* @param ray the Ray that will be casted over the shape
* @param intersectionVector a Vector3 for the intersection point between the shape and the ray
* @return true if the Ray intersect this shape
*/
public boolean intersect(Ray ray, Vector3 intersectionVector) {
if (verticesDirty) {
verticesDirty = false;
tempVertices = new float[vertices.length];
System.arraycopy(vertices, 0, tempVertices, 0, vertices.length);
for (int i = 0; i < vertices.length;) {
tempVector.x = tempVertices[i];
tempVector.y = tempVertices[i + 1];
tempVector.z = tempVertices[i + 2];
tempVector.mul(transformation);
tempVertices[i++] = tempVector.x;
tempVertices[i++] = tempVector.y;
tempVertices[i++] = tempVector.z;
}
}
return Intersector.intersectRayTriangles(ray, tempVertices, indices, mesh.getVertexSize() / (Float.SIZE / 8), intersectionVector);
}
示例14: pickVoxelRay
import com.badlogic.gdx.math.collision.Ray; //导入依赖的package包/类
public Chunk pickVoxelRay(Island island, Vector3 selVoxel, boolean lmb, int x, int y) {
Chunk selectedChunk = null;
Ray ray = camera.getPickRay(x, y);
float distance = 0;
for (Chunk c : island.getChunks()) {
if (c == null) continue;
if (c.inFrustum && !c.isEmpty()) {
tmp1.set(island.pos.x + c.pos.x, island.pos.y + c.pos.y, island.pos.z + c.pos.z);
tmp2.set(tmp1.cpy().add(Chunk.SIZE, Chunk.SIZE, Chunk.SIZE));
bb.set(tmp1, tmp2);
if (Intersector.intersectRayBounds(ray, bb, null) && c.pickVoxel(ray, tmp5, tmp6)) {
float dst = ray.origin.dst(tmp5);
if ((distance == 0 || dst < distance) && dst <= pickRayMaxDistance) {
distance = dst;
selVoxel.set(tmp6).add(c.pos);
selectedChunk = c;
}
}
}
}
return selectedChunk;
}
示例15: rayTest
import com.badlogic.gdx.math.collision.Ray; //导入依赖的package包/类
private btCollisionObject rayTest (Collision<Vector3> output, Ray ray) {
rayFrom.set(ray.origin);
// 500 meters max from the origin
rayTo.set(ray.direction).scl(500f).add(rayFrom);
// we reuse the ClosestRayResultCallback, thus we need to reset its
// values
callback.setCollisionObject(null);
callback.setClosestHitFraction(1f);
callback.setRayFromWorld(rayFrom);
callback.setRayToWorld(rayTo);
world.rayTest(rayFrom, rayTo, callback);
if (callback.hasHit()) {
callback.getHitPointWorld(output.point);
callback.getHitNormalWorld(output.normal);
return callback.getCollisionObject();
}
return null;
}