Created
January 5, 2016 22:29
-
-
Save nanonull/edb4b1ef5e2f352adbdc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protected void process(Entity e) { | |
// TODO if baseBody was destroyed then disable rotation | |
StationaryGunComponent gunComponent = components.get(e); | |
Box2dBodyComponent bodyComponent = Box2dBodySystem.components.get(e); | |
float expectedWorldAngle = gunComponent.getExpectedWorldAngleRads(); | |
float currWorldAngle = bodyComponent.body.getAngle(); | |
float angleDelta = MathUtilsExt.diffAbsoluteRadians(currWorldAngle, expectedWorldAngle); | |
float absDelta = Math.abs(angleDelta); | |
float angleStep; | |
if (absDelta > ROTATE_STEP) { | |
angleStep = angleDelta / absDelta * ROTATE_STEP; | |
} else { | |
angleStep = angleDelta; | |
} | |
float rotationBalance = gunComponent.getRotationBalance(); | |
float newRotationBalance = rotationBalance + angleStep; | |
if (newRotationBalance < 0 || newRotationBalance > gunComponent.getRangeRadians()) { | |
// TODO rotate to bound | |
return; | |
} | |
gunComponent.setRotationBalance(newRotationBalance); | |
Vector2 position = bodyComponent.body.getPosition(); | |
bodyComponent.body.setTransform(position.x, position.y, currWorldAngle + angleStep); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment