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.
This commit is contained in:
parent
1d146a3617
commit
1a4415779c
2 changed files with 103 additions and 42 deletions
|
@ -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;
|
|
||||||
}
|
|
||||||
}
|
|
103
src/minecraft/dark/library/math/OrbitNetworkRing.java
Normal file
103
src/minecraft/dark/library/math/OrbitNetworkRing.java
Normal file
|
@ -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<Entity, Integer> orbitMemeber = new HashMap<Entity, Integer>();
|
||||||
|
|
||||||
|
public OrbitNetworkRing(HashMap<Entity, Integer> entities)
|
||||||
|
{
|
||||||
|
if (entities != null)
|
||||||
|
{
|
||||||
|
this.orbitMemeber.putAll(entities);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public HashMap<Entity, Integer> getOrbitMemebers()
|
||||||
|
{
|
||||||
|
if (this.orbitMemeber == null)
|
||||||
|
{
|
||||||
|
this.orbitMemeber = new HashMap<Entity, Integer>();
|
||||||
|
}
|
||||||
|
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<Entry<Entity, Integer>> 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;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue