Fixed mechanical grid accelerating system due to friction
This commit is contained in:
parent
e9afa8c070
commit
a273ca3975
6 changed files with 42 additions and 32 deletions
|
@ -4,5 +4,11 @@
|
|||
"sounds": [
|
||||
"hammer"
|
||||
]
|
||||
},
|
||||
"gearCrank": {
|
||||
"category": "ambient",
|
||||
"sounds": [
|
||||
"gearCrank"
|
||||
]
|
||||
}
|
||||
}
|
|
@ -61,7 +61,7 @@ class TileMotor extends SpatialTile(Material.iron) with TIO with TElectric with
|
|||
nodes.add(electricNode)
|
||||
nodes.add(mechNode)
|
||||
|
||||
electricNode.resistance = 1
|
||||
electricNode.resistance = 10
|
||||
|
||||
def toggleGearRatio() = (gearRatio + 1) % 3
|
||||
|
||||
|
@ -71,18 +71,6 @@ class TileMotor extends SpatialTile(Material.iron) with TIO with TElectric with
|
|||
updateConnections()
|
||||
}
|
||||
|
||||
def updateConnections()
|
||||
{
|
||||
electricNode.connectionMask = ForgeDirection.VALID_DIRECTIONS.filter(getIO(_) > 0).map(d => 1 << d.ordinal()).foldLeft(0)(_ | _)
|
||||
electricNode.positiveTerminals.clear()
|
||||
electricNode.negativeTerminals.clear()
|
||||
electricNode.positiveTerminals.addAll(getInputDirections())
|
||||
electricNode.negativeTerminals.addAll(getOutputDirections())
|
||||
electricNode.reconstruct()
|
||||
notifyChange()
|
||||
markUpdate()
|
||||
}
|
||||
|
||||
override def update()
|
||||
{
|
||||
super.update()
|
||||
|
@ -103,8 +91,8 @@ class TileMotor extends SpatialTile(Material.iron) with TIO with TElectric with
|
|||
* emfMax = NBAw for direct current
|
||||
* where w = angular velocity
|
||||
*/
|
||||
val inducedEmf = TileMotor.motorConstant * mechNode.angularVelocity // * Math.sin(mechNode.angularVelocity * System.currentTimeMillis() / 1000d)
|
||||
electricNode.generateVoltage(inducedEmf * -1)
|
||||
val inducedEmf = TileMotor.motorConstant * mechNode.angularVelocity
|
||||
electricNode.generateVoltage(inducedEmf)
|
||||
}
|
||||
|
||||
override def setIO(dir: ForgeDirection, ioType: Int)
|
||||
|
@ -120,6 +108,18 @@ class TileMotor extends SpatialTile(Material.iron) with TIO with TElectric with
|
|||
}
|
||||
}
|
||||
|
||||
def updateConnections()
|
||||
{
|
||||
electricNode.connectionMask = ForgeDirection.VALID_DIRECTIONS.filter(getIO(_) > 0).map(d => 1 << d.ordinal()).foldLeft(0)(_ | _)
|
||||
electricNode.positiveTerminals.clear()
|
||||
electricNode.negativeTerminals.clear()
|
||||
electricNode.positiveTerminals.addAll(getInputDirections())
|
||||
electricNode.negativeTerminals.addAll(getOutputDirections())
|
||||
electricNode.reconstruct()
|
||||
notifyChange()
|
||||
markUpdate()
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
override def renderDynamic(pos: Vector3, frame: Float, pass: Int): Unit =
|
||||
{
|
||||
|
|
|
@ -20,25 +20,25 @@ class NodeGear(parent: PartGear) extends NodeMechanical(parent: PartGear)
|
|||
{
|
||||
override def angleDisplacement = if (gear.getMultiBlock.isConstructed) Math.PI / 36 else Math.PI / 12
|
||||
|
||||
protected def gear = getParent.asInstanceOf[PartGear]
|
||||
|
||||
override def inertia: Double =
|
||||
{
|
||||
gear.tier match
|
||||
{
|
||||
case 0 => 8
|
||||
case 0 => 50
|
||||
case 1 => 20
|
||||
case 2 => 15
|
||||
}
|
||||
}
|
||||
|
||||
protected def gear = getParent.asInstanceOf[PartGear]
|
||||
|
||||
override def friction: Double =
|
||||
{
|
||||
gear.tier match
|
||||
{
|
||||
case 0 => 2
|
||||
case 1 => 3
|
||||
case 2 => 1
|
||||
case 0 => 1
|
||||
case 1 => 1.5
|
||||
case 2 => 1.3
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -51,7 +51,7 @@ class GridMechanical extends GridNode[NodeMechanical] with IUpdate
|
|||
n =>
|
||||
{
|
||||
n.torque = 0
|
||||
n.angularVelocity -= n.angularVelocity * deltaTime * n.friction
|
||||
n.angularVelocity -= Math.min(Math.abs(n.angularVelocity) * deltaTime * n.friction, Math.abs(n.angularVelocity)) * Math.signum(n.angularVelocity)
|
||||
}
|
||||
)
|
||||
|
||||
|
|
|
@ -50,15 +50,6 @@ class NodeMechanical(parent: INodeProvider) extends NodeGrid[NodeMechanical](par
|
|||
return prevAngle
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the angular velocity of the mechanical device from a specific side
|
||||
*
|
||||
* @return Angular velocity in meters per second
|
||||
*/
|
||||
override def angularVelocity = _angularVelocity
|
||||
|
||||
def angularVelocity_=(newVel: Double) = _angularVelocity = newVel
|
||||
|
||||
/**
|
||||
* Sets the mechanical node's angle based on its connections
|
||||
*/
|
||||
|
@ -67,7 +58,6 @@ class NodeMechanical(parent: INodeProvider) extends NodeGrid[NodeMechanical](par
|
|||
connections.foreach(
|
||||
n =>
|
||||
{
|
||||
val diff = Math.round((n.prevAngle - prevAngle) * angleDisplacement)
|
||||
n.prevAngle = (prevAngle + angleDisplacement) % (Math.PI * 2)
|
||||
}
|
||||
)
|
||||
|
@ -98,6 +88,15 @@ class NodeMechanical(parent: INodeProvider) extends NodeGrid[NodeMechanical](par
|
|||
|
||||
override def toString = "NodeMechanical [" + connections.size() + " Torque: " + BigDecimal(torque).setScale(2, BigDecimal.RoundingMode.HALF_UP) + " Velocity: " + BigDecimal(angularVelocity).setScale(2, BigDecimal.RoundingMode.HALF_UP) + "]"
|
||||
|
||||
/**
|
||||
* Gets the angular velocity of the mechanical device from a specific side
|
||||
*
|
||||
* @return Angular velocity in meters per second
|
||||
*/
|
||||
override def angularVelocity = _angularVelocity
|
||||
|
||||
def angularVelocity_=(newVel: Double) = _angularVelocity = newVel
|
||||
|
||||
/**
|
||||
* Gets the torque of the mechanical device from a specific side
|
||||
*
|
||||
|
|
|
@ -19,6 +19,11 @@ class NodeTurbine(parent: TileTurbine) extends NodeMechanical(parent)
|
|||
*/
|
||||
override def inertia = 100 * parent.multiBlockRadius * parent.multiBlockRadius
|
||||
|
||||
/**
|
||||
* Friction is a factor that decelerates the mechanical system based on angular velocity.
|
||||
*/
|
||||
override def friction: Double = 3
|
||||
|
||||
/**
|
||||
* Moment of inertia = m * r * r
|
||||
* Where "m" is the mass and "r" is the radius of the object.
|
||||
|
|
Loading…
Reference in a new issue