Merge branch 'development' of https://bitbucket.org/calclavia/resonant-induction into development

This commit is contained in:
tgame14 2014-04-17 18:01:49 +03:00
commit b62a1d5f3e

View file

@ -15,7 +15,8 @@ import universalelectricity.api.vector.Vector3;
import java.util.Iterator;
import java.util.Map.Entry;
/** A mechanical node for mechanical energy.
/**
* A mechanical node for mechanical energy.
* <p/>
* Useful Formula:
* <p/>
@ -25,14 +26,18 @@ import java.util.Map.Entry;
* Torque = r (Radius) * F (Force) * sin0 (Direction/Angle of the force applied. 90 degrees if
* optimal.)
*
* @author Calclavia */
public class MechanicalNode extends Node<INodeProvider, TickingGrid, MechanicalNode> implements IMechanicalNode
* @author Calclavia
*/
public class MechanicalNode extends Node<INodeProvider, TickingGrid, MechanicalNode>
implements IMechanicalNode
{
public double torque = 0;
public double prevAngularVelocity, angularVelocity = 0;
public float acceleration = 2f;
/** The current rotation of the mechanical node. */
/**
* The current rotation of the mechanical node.
*/
public double angle = 0;
public double prev_angle = 0;
protected double maxDeltaAngle = Math.toRadians(180);
@ -68,10 +73,14 @@ public class MechanicalNode extends Node<INodeProvider, TickingGrid, MechanicalN
if (!ResonantInduction.proxy.isPaused())
{
if (angularVelocity >= 0)
{
angle += Math.min(angularVelocity, this.maxDeltaAngle) * deltaTime;
}
else
{
angle += Math.max(angularVelocity, -this.maxDeltaAngle) * deltaTime;
}
}
if (angle % (Math.PI * 2) != angle)
{
@ -81,7 +90,7 @@ public class MechanicalNode extends Node<INodeProvider, TickingGrid, MechanicalN
if (world() != null && !world().isRemote)
{
double acceleration = this.acceleration * deltaTime;
final double acceleration = this.acceleration * deltaTime;
/** Energy loss */
double torqueLoss = Math.min(Math.abs(getTorque()), (Math.abs(getTorque() * getTorqueLoad()) + getTorqueLoad() / 10) * deltaTime);
@ -106,6 +115,11 @@ public class MechanicalNode extends Node<INodeProvider, TickingGrid, MechanicalN
angularVelocity += velocityLoss;
}
if (getEnergy() <= 0)
{
angularVelocity = torque = 0;
}
power = getEnergy() / deltaTime;
synchronized (connections)
@ -125,24 +139,26 @@ public class MechanicalNode extends Node<INodeProvider, TickingGrid, MechanicalN
int inversion = inverseRotation ? -1 : 1;
double applyTorque = inversion * adjacentMech.getTorque() / ratio * acceleration;
double targetTorque = inversion * adjacentMech.getTorque() / ratio;
double applyTorque = targetTorque * acceleration;
if (Math.abs(torque + applyTorque) < Math.abs(adjacentMech.getTorque() / ratio))
if (Math.abs(torque + applyTorque) < Math.abs(targetTorque))
{
torque += applyTorque;
}
else
else if (Math.abs(torque - applyTorque) > Math.abs(targetTorque))
{
torque -= applyTorque;
}
double applyVelocity = inversion * adjacentMech.getAngularVelocity() * ratio * acceleration;
double targetVelocity = inversion * adjacentMech.getAngularVelocity() * ratio;
double applyVelocity = targetVelocity * acceleration;
if (Math.abs(angularVelocity + applyVelocity) < Math.abs(adjacentMech.getAngularVelocity() * ratio))
if (Math.abs(angularVelocity + applyVelocity) < Math.abs(targetVelocity))
{
angularVelocity += applyVelocity;
}
else
else if (Math.abs(angularVelocity - applyVelocity) > Math.abs(targetVelocity))
{
angularVelocity -= applyVelocity;
}
@ -162,7 +178,9 @@ public class MechanicalNode extends Node<INodeProvider, TickingGrid, MechanicalN
}
/** Called when one revolution is made. */
/**
* Called when one revolution is made.
*/
protected void revolve()
{
@ -199,7 +217,9 @@ public class MechanicalNode extends Node<INodeProvider, TickingGrid, MechanicalN
return true;
}
/** The energy percentage loss due to resistance in seconds. */
/**
* The energy percentage loss due to resistance in seconds.
*/
public double getTorqueLoad()
{
return load;
@ -210,7 +230,9 @@ public class MechanicalNode extends Node<INodeProvider, TickingGrid, MechanicalN
return load;
}
/** Recache the connections. This is the default connection implementation. */
/**
* Recache the connections. This is the default connection implementation.
*/
@Override
public void doRecache()
{