List of usage examples for com.badlogic.gdx.math Vector2 sub
@Override
public Vector2 sub(Vector2 v)
From source file:org.destinationsol.game.item.Loot.java
License:Apache License
public void maybePulled(SolShip ship, Vector2 pullerPos, float radius) { if (ship == myOwner) return;/* w ww . java 2 s . c om*/ Vector2 toPuller = SolMath.getVec(pullerPos); toPuller.sub(getPosition()); float pullerDist = toPuller.len(); if (0 < pullerDist && pullerDist < radius) { toPuller.scl(PULL_DESIRED_SPD / pullerDist); Vector2 spd = myBody.getLinearVelocity(); Vector2 spdDiff = SolMath.distVec(spd, toPuller); float spdDiffLen = spdDiff.len(); if (spdDiffLen > 0) { spdDiff.scl(PULL_FORCE / spdDiffLen); myBody.applyForceToCenter(spdDiff, true); } SolMath.free(spdDiff); } SolMath.free(toPuller); }
From source file:org.destinationsol.game.item.Loot.java
License:Apache License
public void pickedUp(SolGame game, SolShip ship) { myLife = 0;/*from w ww .ja v a 2 s. c om*/ Vector2 spd = new Vector2(ship.getPosition()); spd.sub(myPos); float fadeTime = .25f; spd.scl(1 / fadeTime); spd.add(ship.getSpd()); game.getPartMan().blip(game, myPos, myAngle, myItem.getItemType().sz, fadeTime, spd, myItem.getIcon(game)); game.getSoundMan().play(game, myItem.getItemType().pickUpSound, null, this); }
From source file:org.destinationsol.game.planet.FlatPlaceFinder.java
License:Apache License
public Vector2 find(SolGame game, Planet p, ConsumedAngles takenAngles, float objHalfWidth) { Vector2 pPos = p.getPos();/*from w w w . j av a2 s .c om*/ Vector2 res = new Vector2(pPos); float minDeviation = 90; float resAngle = 0; float objAngularHalfWidth = SolMath.angularWidthOfSphere(objHalfWidth, p.getGroundHeight()); for (int i = 0; i < 20; i++) { float angle = SolMath.rnd(180); if (takenAngles != null && takenAngles.isConsumed(angle, objAngularHalfWidth)) continue; myDeviation = angle; SolMath.fromAl(myVec, angle, p.getFullHeight()); myVec.add(pPos); game.getObjMan().getWorld().rayCast(myRayBack, myVec, pPos); if (myDeviation < minDeviation) { res.set(myVec); minDeviation = myDeviation; resAngle = angle; } } if (takenAngles != null) takenAngles.add(resAngle, objAngularHalfWidth); res.sub(pPos); SolMath.rotate(res, -p.getAngle()); return res; }
From source file:org.destinationsol.game.planet.PlanetBind.java
License:Apache License
public void setDiff(Vector2 diff, Vector2 pos, boolean precise) { SolMath.toWorld(diff, myRelPos, myPlanet.getAngle(), myPlanet.getPos(), precise); diff.sub(pos); }
From source file:org.destinationsol.game.planet.PlanetManager.java
License:Apache License
private void applyGrav(SolGame game, SolSystem nearestSys) { float npGh = myNearestPlanet.getGroundHeight(); float npFh = myNearestPlanet.getFullHeight(); float npMinH = myNearestPlanet.getMinGroundHeight(); Vector2 npPos = myNearestPlanet.getPos(); Vector2 sysPos = nearestSys.getPos(); float npGravConst = myNearestPlanet.getGravConst(); List<SolObject> objs = game.getObjMan().getObjs(); for (int i = 0, objsSize = objs.size(); i < objsSize; i++) { SolObject obj = objs.get(i);//from w w w . ja va 2 s . co m if (!obj.receivesGravity()) continue; Vector2 objPos = obj.getPosition(); float minDist; Vector2 srcPos; float gravConst; boolean onPlanet; float toNp = npPos.dst(objPos); float toSys = sysPos.dst(objPos); if (toNp < npFh) { if (recoverObj(obj, toNp, npMinH)) continue; minDist = npGh; srcPos = npPos; gravConst = npGravConst; onPlanet = true; } else if (toSys < Const.SUN_RADIUS) { minDist = SunSingleton.SUN_HOT_RAD; srcPos = sysPos; gravConst = SunSingleton.GRAV_CONST; onPlanet = false; } else { continue; } Vector2 grav = SolMath.getVec(srcPos); grav.sub(objPos); float len = grav.len(); grav.nor(); if (len < minDist) { len = minDist; } float g = gravConst / len / len; grav.scl(g); obj.receiveForce(grav, game, true); SolMath.free(grav); if (!onPlanet) { mySunSingleton.doDmg(game, obj, toSys); } } }
From source file:org.destinationsol.game.planet.PlanetObjectsBuilder.java
License:Apache License
private RectSprite createCloudSprite(ArrayList<TextureAtlas.AtlasRegion> cloudTexs, float maxAngleShift, float maxDistShift, float baseDist, TextureManager textureManager) { TextureAtlas.AtlasRegion tex = SolMath.elemRnd(cloudTexs); if (SolMath.test(.5f)) tex = textureManager.getFlipped(tex); float angleShiftRel = SolMath.rnd(1); float distPerc = 1 - SolMath.abs(angleShiftRel); float sz = .5f * (1 + distPerc) * MAX_CLOUD_PIECE_SZ; float relAngle = SolMath.rnd(30); float rotSpd = SolMath.rnd(MAX_CLOUT_PIECE_ROT_SPD); float angleShift = angleShiftRel * maxAngleShift; float distShift = maxDistShift == 0 ? 0 : distPerc * SolMath.rnd(0, maxDistShift); float dist = baseDist + distShift; Vector2 basePos = SolMath.getVec(0, -baseDist); Vector2 relPos = new Vector2(0, -dist); SolMath.rotate(relPos, angleShift, true); relPos.sub(basePos); SolMath.free(basePos);/* w ww . j av a 2s.co m*/ return new RectSprite(tex, sz, 0, 0, relPos, DraLevel.CLOUDS, relAngle, rotSpd, SolColor.W, false); }
From source file:org.destinationsol.game.planet.SunSingleton.java
License:Apache License
public void draw(SolGame game, GameDrawer drawer) { Vector2 camPos = game.getCam().getPos(); SolSystem sys = game.getPlanetMan().getNearestSystem(camPos); Vector2 toCam = SolMath.getVec(camPos); toCam.sub(sys.getPos()); float toCamLen = toCam.len(); if (toCamLen < Const.SUN_RADIUS) { float closeness = 1 - toCamLen / Const.SUN_RADIUS; myGradTint.a = SolMath.clamp(closeness * 4, 0, 1); myFillTint.a = SolMath.clamp((closeness - .25f) * 4, 0, 1); float sz = 2 * game.getCam().getViewDist(); float gradAngle = SolMath.angle(toCam) + 90; drawer.draw(myWhiteTex, sz * 2, sz * 2, sz, sz, camPos.x, camPos.y, 0, myFillTint); drawer.draw(myGradTex, sz * 2, sz * 2, sz, sz, camPos.x, camPos.y, gradAngle, myGradTint); }/*from w w w . j a v a2 s . c o m*/ SolMath.free(toCam); }
From source file:org.destinationsol.game.planet.TileObject.java
License:Apache License
@Override public void update(SolGame game) { setDependentParams();//from ww w . j a va 2 s . c o m if (myBody != null) { float ts = game.getTimeStep(); Vector2 spd = SolMath.getVec(myPos); spd.sub(myBody.getPosition()); spd.scl(1f / ts); myBody.setLinearVelocity(spd); SolMath.free(spd); float bodyAngle = myBody.getAngle() * SolMath.radDeg; float av = SolMath.norm(myAngle - bodyAngle) * SolMath.degRad / ts; myBody.setAngularVelocity(av); } }
From source file:org.destinationsol.game.StarPort.java
License:Apache License
@Override public void update(SolGame game) { setParamsFromBody();/* w ww . ja v a 2 s .com*/ float fps = 1 / game.getTimeStep(); Vector2 spd = getDesiredPos(myFrom, myTo, true); // Adjust position so that StarPorts are not overlapping spd = adjustDesiredPos(game, this, spd); spd.sub(myPos).scl(fps / 4); myBody.setLinearVelocity(spd); SolMath.free(spd); float desiredAngle = SolMath.angle(myFrom.getPos(), myTo.getPos()); myBody.setAngularVelocity((desiredAngle - myAngle) * SolMath.degRad * fps / 4); SolShip ship = ForceBeacon.pullShips(game, this, myPos, null, null, .4f * SIZE); if (ship != null && ship.getMoney() >= FARE && ship.getPosition().dst(myPos) < .05f * SIZE) { ship.setMoney(ship.getMoney() - FARE); Transcendent t = new Transcendent(ship, myFrom, myTo, game); ObjectManager objectManager = game.getObjMan(); objectManager.addObjDelayed(t); blip(game, ship); game.getSoundMan().play(game, game.getSpecialSounds().transcendentCreated, null, t); objectManager.removeObjDelayed(ship); } for (int i = 0, myLightsSize = myLights.size(); i < myLightsSize; i++) { LightSrc l = myLights.get(i); l.update(true, myAngle, game); } }
From source file:org.matheusdev.ror.view.EntityView.java
License:Open Source License
public void draw(SpriteBatch batch, Entity e, Sprite sprite, float width, float xoffset, float yoffset) { Body body = e.getBody();//w w w.j av a 2s. c om // Super-Duper important Box2D-Magic code: // This should be / is in almost every Box2D project // It takes the Body and the associated sprite and // renders the sprite properly, using the body's // position, rotation and origin. final float worldToSprite = sprite.getWidth() / width; final float spriteToWorld = width / sprite.getWidth(); // Get body position: final float bodyX = e.getX(); final float bodyY = e.getY(); // Get body center: final Vector2 center = body.getLocalCenter(); final Vector2 massCenter = body.getMassData().center; center.sub(massCenter).add(xoffset, yoffset); // Compute sprite-space center: final Vector2 spriteCenter = new Vector2(sprite.getWidth() / 2, sprite.getHeight() / 2) .sub((center.cpy().scl(worldToSprite))); // Upload to sprite: sprite.setScale(1f * spriteToWorld); sprite.setRotation(e.getRotation() * MathUtils.radiansToDegrees); sprite.setOrigin(spriteCenter.x, spriteCenter.y); sprite.setPosition(bodyX - spriteCenter.x, bodyY - spriteCenter.y); // Draw Sprite: sprite.draw(batch); }