本文整理汇总了Java中com.badlogic.gdx.math.Intersector类的典型用法代码示例。如果您正苦于以下问题:Java Intersector类的具体用法?Java Intersector怎么用?Java Intersector使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Intersector类属于com.badlogic.gdx.math包,在下文中一共展示了Intersector类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: isPointInRegion
import com.badlogic.gdx.math.Intersector; //导入依赖的package包/类
/**
/**
* Checks if two specific coordinates are within a PolygonRegion
* and sets tappedRegion to this region
*
* @param pointX absolute value of X coordinate
* @param pointY absolute value of Y coordinate
* @return true if in a region, false if not.
*/
private boolean isPointInRegion(float pointX, float pointY) {
for (AssetMap.Region region : data.getMapAsset().getRegions()) {
tappedRegion = region;
float[] vertices = region.getVertices();
// for Intersector, we have to convert to percentual x/y coordinates. Simply divide by screen width/height
if (Intersector.isPointInPolygon(vertices, 0, vertices.length, pointX / Gdx.graphics.getWidth(), pointY / Gdx.graphics.getHeight())) {
clickedRegionLabel.setText("Region: " + region.getName());
return true;
}
}
clickedRegionLabel.setText("Region: None");
return false;
}
示例2: touchEnklave
import com.badlogic.gdx.math.Intersector; //导入依赖的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: getObject
import com.badlogic.gdx.math.Intersector; //导入依赖的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;
}
示例4: checkCollision
import com.badlogic.gdx.math.Intersector; //导入依赖的package包/类
@Override
public boolean checkCollision(Vector2 p1, Vector2 p2) {
// Intersect left edge
if (Intersector.intersectSegments(p1.x, p1.y, p2.x, p2.y, mXPos, mYPos, mXPos, mYPos + mHeight, null))
return true;
// Intersect right edge
if (Intersector.intersectSegments(p1.x, p1.y, p2.x, p2.y, mXPos + mWidth, mYPos, mXPos + mWidth,
mYPos + mHeight, null))
return true;
// Intersect top edge
if (Intersector.intersectSegments(p1.x, p1.y, p2.x, p2.y, mXPos, mYPos + mHeight, mXPos + mWidth,
mYPos + mHeight, null))
return true;
// Intersect bottom edge
if (Intersector.intersectSegments(p1.x, p1.y, p2.x, p2.y, mXPos, mYPos, mXPos + mWidth, mYPos, null))
return true;
return false;
}
示例5: verticalRayTest
import com.badlogic.gdx.math.Intersector; //导入依赖的package包/类
/**
* Make a ray test at this point, using a ray spanning from far up in the sky, to far down in the ground,
* along the up axis.
*
* @param testPoint The test point
* @param out The point of intersection between ray and triangle
* @param allowedMeshParts Which mesh parts to test. Null if all meshparts should be tested.
* @return The triangle, or null if ray did not hit any triangles.
*/
public Triangle verticalRayTest(Vector3 testPoint, Vector3 out, Bits allowedMeshParts) {
tmpRayVerticalRayTest.set(
tmpVerticalRayTest1.set(Constants.V3_UP).scl(500).add(testPoint),
tmpVerticalRayTest2.set(Constants.V3_DOWN));
Triangle hitTri = rayTest(tmpRayVerticalRayTest, 1000, allowedMeshParts);
if (hitTri == null) {
// TODO: Perhaps this should be Nan?
out.set(Float.POSITIVE_INFINITY, Float.POSITIVE_INFINITY, Float.POSITIVE_INFINITY);
return null;
} else {
Intersector.intersectRayTriangle(tmpRayVerticalRayTest, hitTri.a, hitTri.b, hitTri.c, out);
return hitTri;
}
}
示例6: isWithinCameraView
import com.badlogic.gdx.math.Intersector; //导入依赖的package包/类
/**
* checks if a game object is within the given camera's viewport.
*
* @param camera game camera to check if the game object is within the view port
* @param gameObj game object to check
*
* @return <b>true</b> if game object is within camera viewport. <b>false</b> otherwise.
*/
public static boolean isWithinCameraView(Camera camera, GameObject gameObj) {
if (cameraBounds == null) {
// first call to this method
// create a Rectangle instance and keep it for later use
// it is better to keep an instance to avoid gc during update/render calls
cameraBounds = new Rectangle();
}
cameraBounds.x = camera.position.x - camera.viewportWidth / 2;
cameraBounds.y = camera.position.y - camera.viewportHeight / 2;
cameraBounds.width = camera.viewportWidth;
cameraBounds.height = camera.viewportHeight;
return Intersector.overlaps(cameraBounds, gameObj.getBoundingRectangle());
}
示例7: collideWithHull
import com.badlogic.gdx.math.Intersector; //导入依赖的package包/类
/**
* Check if a line from a to b intersects with the convext hull.
* If so, the point of intersection is stored in the intersect vector.
* @param a point one
* @param b point two
* @param intersect point of intersection
* @return true if intersect. Point of intersection stored in intersect
*/
public boolean collideWithHull(Vector2 a, Vector2 b, Vector2 intersect) {
//for each line segment between two vertices
float[] verticies = hullPoly.getTransformedVertices();
for (int v = 0; v < verticies.length - 2; v += 2) {
float xA = verticies[v];
float yA = verticies[v + 1];
float xB = verticies[v + 2];
float yB = verticies[v + 3];
// convex hull line between A and B
Vector2 edgeA = new Vector2(xA, yA);
Vector2 edgeB = new Vector2(xB, yB);
if (Intersector.intersectSegments(edgeA, edgeB, a, b, intersect)) {
//the two lines intersect. point of intersection is set in variable intersect
return true;
}
}
return false;
}
示例8: isColliding
import com.badlogic.gdx.math.Intersector; //导入依赖的package包/类
private boolean isColliding(Vector2 planetPosition, float planetRadius) {
if (corner01.dst(planetPosition) < planetRadius) {
return true;
}
if (corner02.dst(planetPosition) < planetRadius) {
return true;
}
if (corner03.dst(planetPosition) < planetRadius) {
return true;
}
if (corner04.dst(planetPosition) < planetRadius) {
return true;
}
return Intersector.isPointInTriangle(planetPosition, corner01, corner02, corner03)
|| Intersector.isPointInTriangle(planetPosition, corner03, corner04, corner01);
}
示例9: collisionCheck
import com.badlogic.gdx.math.Intersector; //导入依赖的package包/类
private static void collisionCheck(Bullet bullet, Ship ship) {
if (bullet.id!=ship.id && ship.alive) {
for(int i = 0; i<ship.collisionPoints.size;++i) {
if(Intersector.isPointInPolygon(bullet.collisionPoints, ship.collisionPoints.get(i))) {
ship.damage(bullet.damage);
GameInstance.getInstance().bulletHit(ship, bullet);
bullet.alive = false;
return;
}
}
for(int i = 0; i<bullet.collisionPoints.size;++i) {
if(Intersector.isPointInPolygon(ship.collisionPoints, bullet.collisionPoints.get(i))) {
ship.damage(bullet.damage);
GameInstance.getInstance().bulletHit(ship, bullet);
bullet.alive = false;
return;
}
}
}
}
示例10: touchDown
import com.badlogic.gdx.math.Intersector; //导入依赖的package包/类
@Override
public boolean touchDown(int x, int y, int pointer, int button) {
collisionRay = cam.getPickRay(x, y);
if(numPlayers >0 && Intersector.intersectRayBoundsFast(collisionRay, touchAreaP1) && GameInstance.getInstance().factorys.size>0) {
((FactoryProduction) GameInstance.getInstance().factorys.get(0)).button_held = true;
pointerP1 = pointer;
touchedP1 = true;
}
if(numPlayers >1 && Intersector.intersectRayBoundsFast(collisionRay, touchAreaP2) && GameInstance.getInstance().factorys.size>1) {
((FactoryProduction) GameInstance.getInstance().factorys.get(1)).button_held = true;
pointerP2 = pointer;
touchedP2 = true;
}
if(numPlayers >2 && Intersector.intersectRayBoundsFast(collisionRay, touchAreaP3) && GameInstance.getInstance().factorys.size>2) {
((FactoryProduction) GameInstance.getInstance().factorys.get(2)).button_held = true;
pointerP3 = pointer;
touchedP3 = true;
}
if(numPlayers >3 && Intersector.intersectRayBoundsFast(collisionRay, touchAreaP4) && GameInstance.getInstance().factorys.size>3) {
((FactoryProduction) GameInstance.getInstance().factorys.get(3)).button_held = true;
pointerP4 = pointer;
touchedP4 = true;
}
return false;
}
示例11: updateRunning
import com.badlogic.gdx.math.Intersector; //导入依赖的package包/类
public void updateRunning(float delta) {
if (delta > .15f) {
delta = .15f;
}
bird.update(delta);
scroller.update(delta);
if (scroller.collides(bird) && bird.isAlive()) {
scroller.stop();
bird.die();
AssetLoader.deadSound.play();
}
if (Intersector.overlaps(bird.getBoundingCircle(), ground)) {
scroller.stop();
bird.die();
bird.decelerate();
currentState = GameState.GAMEOVER;
}
}
示例12: placeOilFactory
import com.badlogic.gdx.math.Intersector; //导入依赖的package包/类
public void placeOilFactory() {
float oilRectWidth = 2f;
Rectangle factoryRect = new Rectangle(president.getX()
+ President.WIDTH / 2f - oilRectWidth / 2f, president.getY() - 4, oilRectWidth, 1);
for (Entity ent : levelEntities.get(OilField.class)) {
final OilField field = (OilField) ent;
if (field.isHasFactory())
continue;
if (Intersector.intersectRectangles(field.bounds, factoryRect,
tmpRect)) {
levelEntities.get(OilFactory.class).add(
new OilFactory(field.getX() + field.getWidth()/2f - OilFactory.WIDTH / 2f));
field.setHasFactory(true);
GameScore.getInstance().incDemocracyLevel();
break;
}
}
}
示例13: damagePresident
import com.badlogic.gdx.math.Intersector; //导入依赖的package包/类
private void damagePresident() {
@SuppressWarnings("unchecked")
List<Bullet> bullets = (List<Bullet>) (Object) level.levelEntities
.get(Bullet.class);
President pres = level.president;
for (Bullet bullet : bullets) {
if (bullet.isMarkedToDelete())
continue;
for (Rectangle bound : pres.getBounds()) {
if (Intersector.intersectRectangles(bound, bullet.bounds,
tmpRect)) {
pres.doDamage(Constants.TERR_DAMAGE);
bullet.markDeleted();
break;
}
}
}
}
示例14: destroyKamaz
import com.badlogic.gdx.math.Intersector; //导入依赖的package包/类
private void destroyKamaz() {
@SuppressWarnings("unchecked")
List<Rocket> rockets = (List<Rocket>) (Object) level.levelEntities
.get(Rocket.class);
@SuppressWarnings("unchecked")
List<TntVehicle> vehicles = (List<TntVehicle>) (Object) level.levelEntities
.get(TntVehicle.class);
for (Rocket rocket : rockets) {
for (TntVehicle vehicle : vehicles) {
if (rocket.isMarkedToDelete() || vehicle.isDestroyed())
continue;
if (Intersector.intersectRectangles(rocket.bounds,
vehicle.bounds, tmpRect)) {
rocket.markDeleted();
vehicle.setDestroyed(true);
Assets.kamazExpSound.play();
GameScore.getInstance().priceTNTVehicle();
level.bum(vehicle.getX(), vehicle.getY());
}
}
}
}
示例15: checkForPaddleCollision
import com.badlogic.gdx.math.Intersector; //导入依赖的package包/类
private void checkForPaddleCollision() {
for (Paddle hitPaddle : paddleList) {
if (Intersector.overlaps(hitPaddle, ball)) {
paddleHits++;
ball.xVel *= -1;
if (ball.xVel > 0) {ball.xVel += 20;} else {ball.xVel -= 20;}
paddleCollisionSound.play();
startScreenShake();
if (hitPaddle.name.equals("paddle1")) {
ball.setPosition((hitPaddle.x + hitPaddle.width), ball.y);
} else if (hitPaddle.name.equals("paddle2")) {
ball.setPosition((hitPaddle.x - ball.width), ball.y);
}
}
}
}