diff options
Diffstat (limited to 'core/src/sk/neuromancer/sphaera/rewrite/DirectedSphere.java')
| -rwxr-xr-x | core/src/sk/neuromancer/sphaera/rewrite/DirectedSphere.java | 105 |
1 files changed, 105 insertions, 0 deletions
diff --git a/core/src/sk/neuromancer/sphaera/rewrite/DirectedSphere.java b/core/src/sk/neuromancer/sphaera/rewrite/DirectedSphere.java new file mode 100755 index 0000000..885553c --- /dev/null +++ b/core/src/sk/neuromancer/sphaera/rewrite/DirectedSphere.java @@ -0,0 +1,105 @@ +package sk.neuromancer.sphaera.rewrite; + +import com.badlogic.gdx.graphics.g3d.Material; +import com.badlogic.gdx.math.Vector3; + +import sk.neuromancer.sphaera.interf.Moving; + +public class DirectedSphere extends Sphere implements Moving { + + private Vector3 direction; + + public DirectedSphere() { + super(); + this.direction = Vector3.Zero.cpy(); + } + + public DirectedSphere(float radius) { + super(radius); + } + + public DirectedSphere(float radius, Material... mat) { + super(radius, mat); + } + + public DirectedSphere(float x, float y, float z, float radius, + Material... mat) { + super(x, y, z, radius, mat); + } + + public DirectedSphere(Sphere parent, float a, float b, float radius, + Material... mat) { + super(parent, a, b, radius, mat); + } + + public DirectedSphere(Sphere parent, float a, float b, float radius, Vector3 direction, + Material... mat) { + super(parent, a, b, radius, mat); + this.direction = direction; + } + + public void randomDirection(){ + Vector3 relative = this.getRelativePosition(); + Vector3 random = new Vector3().setToRandomDirection(); + Vector3 circleNormal = relative.cpy().crs(random); + float angle = SphereUtils.angleDeg(random, relative); + random.rotate(circleNormal, angle); + this.direction = random; + } + + @Override + public void forward(float angle) { + Vector3 oldRelative = this.getRelativePosition(); + Vector3 circleNormal = oldRelative.cpy().crs(this.direction); + Vector3 newRelative = oldRelative.cpy().rotate(circleNormal, angle); + this.setVelocity(newRelative.cpy().sub(oldRelative)); + } + + @Override + public void back(float angle) { + this.forward(-angle); + } + + @Override + public void rotateAzimuth(float angle) { + this.direction.rotate(this.getRelativePosition(), angle); + } + + @Override + public void rotateLeft(float angle) { + rotateAzimuth(angle); + } + + @Override + public void rotateRight(float angle) { + rotateAzimuth(-angle); + } + + @Override + public void move(float howMuch) { + if(this.getVelocity().len() == 0) + return; + Vector3 oldRelative = this.getRelativePosition(); + super.move(howMuch); + Vector3 newRelative = this.getRelativePosition(); + this.updateDirection(oldRelative, newRelative); + } + + private void updateDirection(Vector3 oldPos, Vector3 newPos) { + Vector3 circleNormal = oldPos.cpy().crs(newPos); + float angle = SphereUtils.angleDeg(oldPos, newPos); + this.direction = circleNormal.cpy().crs(newPos); + } + + public void setDirection(float x, float y, float z){ + this.direction = new Vector3(x,y,z); + } + + public void setDirection(Vector3 direction){ + this.direction = direction; + } + + public Vector3 getDirection(){ + return this.direction.cpy(); + } +} |
