From 1a4415779cab4ea2ff714bf9e4214fc3c4db696a Mon Sep 17 00:00:00 2001 From: Robert Seifert Date: Wed, 5 Jun 2013 01:50:27 -0400 Subject: [PATCH] Worked on orbit helper/network This is going to need a ton of work and love to get right. Right now its not even going to function. --- .../dark/library/math/OrbitHelper.java | 42 ------- .../dark/library/math/OrbitNetworkRing.java | 103 ++++++++++++++++++ 2 files changed, 103 insertions(+), 42 deletions(-) delete mode 100644 src/minecraft/dark/library/math/OrbitHelper.java create mode 100644 src/minecraft/dark/library/math/OrbitNetworkRing.java diff --git a/src/minecraft/dark/library/math/OrbitHelper.java b/src/minecraft/dark/library/math/OrbitHelper.java deleted file mode 100644 index cb0cb2ea7..000000000 --- a/src/minecraft/dark/library/math/OrbitHelper.java +++ /dev/null @@ -1,42 +0,0 @@ -package dark.library.math; - -import universalelectricity.core.vector.Vector3; - -public class OrbitHelper -{ - /** - * Get the offset of the center of the circle and object will be if move around the edge of the - * circle so far - * - * @param radus distance of the circle - * @param pos in the circle - * @return change from center of the circle - */ - public Vector3 getRadianPos(float radus, int pos, float spacing) - { - return null; - } - - /** - * Gets the spacing in order to to have x number of the same width object orbit a point - * - * @param radus of the circle - * @param width of the object including spacing - * @param number of objects - * @return spacing in radians of the circle - */ - public float getObjectSpacing(double radus, double width, double number) - { - return 0; - } - - public Vector3 getCirclePos(int objects, double width, double radius) - { - if (radius < (width + (width / 2)) * objects) - { - radius = (width + width / 2) * objects; - } - float spacing = this.getObjectSpacing(radius, width, objects); - return null; - } -} diff --git a/src/minecraft/dark/library/math/OrbitNetworkRing.java b/src/minecraft/dark/library/math/OrbitNetworkRing.java new file mode 100644 index 000000000..01b5dee7b --- /dev/null +++ b/src/minecraft/dark/library/math/OrbitNetworkRing.java @@ -0,0 +1,103 @@ +package dark.library.math; + +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map.Entry; + +import net.minecraft.entity.Entity; +import universalelectricity.core.vector.Vector3; + +public class OrbitNetworkRing +{ + float orbitRadius; + Vector3 rotationChange = new Vector3(0, 0, 0); + + HashMap orbitMemeber = new HashMap(); + + public OrbitNetworkRing(HashMap entities) + { + if (entities != null) + { + this.orbitMemeber.putAll(entities); + } + } + + public HashMap getOrbitMemebers() + { + if (this.orbitMemeber == null) + { + this.orbitMemeber = new HashMap(); + } + return this.orbitMemeber; + } + + /** + * Increase the rotation angles of the orbitRing + * + * @param vec - rotation change stored as a vector3 + * @param increase - add the vec rotation to current rotation + */ + public void changeRotation(Vector3 vec, boolean increase) + { + Vector3 preRotation = rotationChange.clone(); + this.rotationChange = vec; + if (increase) + { + this.rotationChange.add(preRotation); + } + } + + /** + * Get the rotation change of the orbit + */ + public Vector3 getRotation() + { + if (this.rotationChange == null) + { + this.rotationChange = new Vector3(0, 0, 0); + } + return this.rotationChange; + } + + /** + * Ideal minimal radius needed for the number of objects + */ + public float getMinRadius() + { + float width = 0; + Iterator> it = this.getOrbitMemebers().entrySet().iterator(); + while (it.hasNext()) + { + Entity entity = it.next().getKey(); + width += entity.width; + } + width = width / this.getOrbitMemebers().size(); + return ((width + (width / 2)) * this.getOrbitMemebers().size()); + } + + /** + * + * @param objectSize - side of the object in the direction it will orbit + * @param radIncrase - increase in radius size + * @param objects - number of the objects in the orbit + * @param pos - position in the orbit + * @return offset distance from orbit center + * + * Note this only gives the offset from the orbit point. This needs to be used to in combo with + * something else to get the orbit point. Then add the result of this to get the pos of the + * object + */ + public Vector3 getOrbitOffset(int pos) + { + float minRadius = this.getMinRadius(); + if (this.orbitRadius < minRadius) + { + this.orbitRadius = minRadius; + } + float spacing = this.orbitRadius / this.getOrbitMemebers().size(); + + double x = this.orbitRadius * Math.cos((spacing * pos) + this.getRotation().y); + double z = this.orbitRadius * Math.sin((spacing * pos) + this.getRotation().y); + return null; + } +}