Fixed mechanical grid accelerating system due to friction

This commit is contained in:
Calclavia 2015-01-23 19:22:17 +08:00
parent e9afa8c070
commit a273ca3975
6 changed files with 42 additions and 32 deletions

View file

@ -4,5 +4,11 @@
"sounds": [ "sounds": [
"hammer" "hammer"
] ]
},
"gearCrank": {
"category": "ambient",
"sounds": [
"gearCrank"
]
} }
} }

View file

@ -61,7 +61,7 @@ class TileMotor extends SpatialTile(Material.iron) with TIO with TElectric with
nodes.add(electricNode) nodes.add(electricNode)
nodes.add(mechNode) nodes.add(mechNode)
electricNode.resistance = 1 electricNode.resistance = 10
def toggleGearRatio() = (gearRatio + 1) % 3 def toggleGearRatio() = (gearRatio + 1) % 3
@ -71,18 +71,6 @@ class TileMotor extends SpatialTile(Material.iron) with TIO with TElectric with
updateConnections() 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() override def update()
{ {
super.update() super.update()
@ -103,8 +91,8 @@ class TileMotor extends SpatialTile(Material.iron) with TIO with TElectric with
* emfMax = NBAw for direct current * emfMax = NBAw for direct current
* where w = angular velocity * where w = angular velocity
*/ */
val inducedEmf = TileMotor.motorConstant * mechNode.angularVelocity // * Math.sin(mechNode.angularVelocity * System.currentTimeMillis() / 1000d) val inducedEmf = TileMotor.motorConstant * mechNode.angularVelocity
electricNode.generateVoltage(inducedEmf * -1) electricNode.generateVoltage(inducedEmf)
} }
override def setIO(dir: ForgeDirection, ioType: Int) 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) @SideOnly(Side.CLIENT)
override def renderDynamic(pos: Vector3, frame: Float, pass: Int): Unit = override def renderDynamic(pos: Vector3, frame: Float, pass: Int): Unit =
{ {

View file

@ -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 override def angleDisplacement = if (gear.getMultiBlock.isConstructed) Math.PI / 36 else Math.PI / 12
protected def gear = getParent.asInstanceOf[PartGear]
override def inertia: Double = override def inertia: Double =
{ {
gear.tier match gear.tier match
{ {
case 0 => 8 case 0 => 50
case 1 => 20 case 1 => 20
case 2 => 15 case 2 => 15
} }
} }
protected def gear = getParent.asInstanceOf[PartGear]
override def friction: Double = override def friction: Double =
{ {
gear.tier match gear.tier match
{ {
case 0 => 2 case 0 => 1
case 1 => 3 case 1 => 1.5
case 2 => 1 case 2 => 1.3
} }
} }

View file

@ -51,7 +51,7 @@ class GridMechanical extends GridNode[NodeMechanical] with IUpdate
n => n =>
{ {
n.torque = 0 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)
} }
) )

View file

@ -50,15 +50,6 @@ class NodeMechanical(parent: INodeProvider) extends NodeGrid[NodeMechanical](par
return prevAngle 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 * Sets the mechanical node's angle based on its connections
*/ */
@ -67,7 +58,6 @@ class NodeMechanical(parent: INodeProvider) extends NodeGrid[NodeMechanical](par
connections.foreach( connections.foreach(
n => n =>
{ {
val diff = Math.round((n.prevAngle - prevAngle) * angleDisplacement)
n.prevAngle = (prevAngle + angleDisplacement) % (Math.PI * 2) 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) + "]" 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 * Gets the torque of the mechanical device from a specific side
* *

View file

@ -19,6 +19,11 @@ class NodeTurbine(parent: TileTurbine) extends NodeMechanical(parent)
*/ */
override def inertia = 100 * parent.multiBlockRadius * parent.multiBlockRadius 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 * Moment of inertia = m * r * r
* Where "m" is the mass and "r" is the radius of the object. * Where "m" is the mass and "r" is the radius of the object.