-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Quaternions kinda working, but qmake & qunmake are acting weird
- Loading branch information
1 parent
07881ef
commit f091e13
Showing
9 changed files
with
167 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
common/src/main/java/dev/kineticcat/complexhex/casting/arithmetic/quaternion/OpQunmake.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package dev.kineticcat.complexhex.casting.arithmetic.quaternion | ||
|
||
import at.petrak.hexcasting.api.casting.arithmetic.operator.Operator | ||
import at.petrak.hexcasting.api.casting.arithmetic.operator.OperatorBasic | ||
import at.petrak.hexcasting.api.casting.castables.ConstMediaAction | ||
import at.petrak.hexcasting.api.casting.asActionResult | ||
import at.petrak.hexcasting.api.casting.eval.CastingEnvironment | ||
import at.petrak.hexcasting.api.casting.getDouble | ||
import at.petrak.hexcasting.api.casting.iota.DoubleIota | ||
import at.petrak.hexcasting.api.casting.iota.Iota | ||
import at.petrak.hexcasting.api.casting.iota.Vec3Iota | ||
import dev.kineticcat.complexhex.api.casting.iota.ComplexHexIotaTypes | ||
import dev.kineticcat.complexhex.api.casting.iota.QuaternionIota | ||
import dev.kineticcat.complexhex.stuff.Quaternion | ||
import net.minecraft.world.phys.Vec3 | ||
import kotlin.math.sign | ||
|
||
object OpQunmake : OperatorBasic(1, QuaternionArithmetic.ACCEPTS_Q) { | ||
override fun apply(iotas: Iterable<Iota>, env: CastingEnvironment): Iterable<Iota> { | ||
val it = iotas.iterator() | ||
val Q = Operator.downcast(it.next(), ComplexHexIotaTypes.QUATERNION).quaternion | ||
return listOf(DoubleIota(Q.a), Vec3Iota(Vec3(Q.b, Q.c, Q.d))) | ||
} | ||
|
||
} |
90 changes: 90 additions & 0 deletions
90
...main/java/dev/kineticcat/complexhex/casting/arithmetic/quaternion/QuaternionArithmetic.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
package dev.kineticcat.complexhex.casting.arithmetic.quaternion | ||
|
||
import at.petrak.hexcasting.api.casting.arithmetic.Arithmetic | ||
import at.petrak.hexcasting.api.casting.arithmetic.Arithmetic.* | ||
import at.petrak.hexcasting.api.casting.arithmetic.engine.InvalidOperatorException | ||
import at.petrak.hexcasting.api.casting.arithmetic.operator.Operator | ||
import at.petrak.hexcasting.api.casting.arithmetic.operator.OperatorBinary | ||
import at.petrak.hexcasting.api.casting.arithmetic.operator.OperatorUnary | ||
import at.petrak.hexcasting.api.casting.arithmetic.predicates.IotaMultiPredicate | ||
import at.petrak.hexcasting.api.casting.arithmetic.predicates.IotaPredicate | ||
import at.petrak.hexcasting.api.casting.iota.DoubleIota | ||
import at.petrak.hexcasting.api.casting.iota.Iota | ||
import at.petrak.hexcasting.api.casting.math.HexPattern | ||
import at.petrak.hexcasting.common.lib.hex.HexIotaTypes | ||
import dev.kineticcat.complexhex.Complexhex | ||
import dev.kineticcat.complexhex.api.casting.iota.ComplexHexIotaTypes | ||
import dev.kineticcat.complexhex.api.casting.iota.QuaternionIota | ||
import dev.kineticcat.complexhex.casting.ComplexhexPatternRegistry.* | ||
import dev.kineticcat.complexhex.stuff.Quaternion | ||
import net.minecraft.world.phys.Vec3 | ||
import org.apache.logging.log4j.LogManager | ||
|
||
object QuaternionArithmetic : Arithmetic { | ||
val LOGGER = LogManager.getLogger(Complexhex.MOD_ID) | ||
|
||
private val Q_PREDICATE = IotaPredicate.ofType(ComplexHexIotaTypes.QUATERNION) | ||
private val D_PREDICATE = IotaPredicate.ofType(HexIotaTypes.DOUBLE) | ||
private val V_PREDICATE = IotaPredicate.ofType(HexIotaTypes.VEC3) | ||
public val ACCEPTS_Q: IotaMultiPredicate = IotaMultiPredicate.all(Q_PREDICATE) | ||
private val ACCEPTS_QD: IotaMultiPredicate = IotaMultiPredicate.pair(Q_PREDICATE, D_PREDICATE) | ||
private val ACCEPTS_DQ: IotaMultiPredicate = IotaMultiPredicate.pair(D_PREDICATE, Q_PREDICATE) | ||
private val ACCEPTS_QQorQD: IotaMultiPredicate = IotaMultiPredicate.either(ACCEPTS_Q, ACCEPTS_QD) | ||
private val ACCEPTS_DV: IotaMultiPredicate = IotaMultiPredicate.pair(D_PREDICATE, V_PREDICATE) | ||
override fun arithName() = "quaternion_maths" | ||
private val OPS = listOf( | ||
ADD, | ||
SUB, | ||
MUL, | ||
DIV, | ||
QMUL, | ||
QINVERT, | ||
QA, | ||
QB, | ||
QC, | ||
QD, | ||
QMAKE, | ||
QUNMAKE | ||
) | ||
override fun opTypes() = OPS | ||
|
||
override fun getOperator(pattern: HexPattern?): Operator { | ||
LOGGER.info(pattern) | ||
return when (pattern) { | ||
ADD -> QQorQDbinaryQ( { a, b -> a.add(b) }, { a, b -> a.add(b) } ) | ||
SUB -> QQorQDbinaryQ( { a, b -> a.sub(b) }, { a, b -> a.sub(b) } ) | ||
MUL -> QDbinaryQ { a, b -> a.mul(b) } | ||
DIV -> QDbinaryQ { a, b -> a.div(b) } | ||
QMUL -> QQbinaryQ { a, b -> a.mul(b) } | ||
QINVERT -> QunaryQ { a -> a.inverse() } | ||
QA -> QunaryD { a -> a.a } | ||
QB -> QunaryD { a -> a.b } | ||
QC -> QunaryD { a -> a.c } | ||
QD -> QunaryD { a -> a.d } | ||
QMAKE -> DVbinaryQ { d, v -> Quaternion(d, v.x, v.y, v.z) } | ||
QUNMAKE -> OpQunmake | ||
else -> throw InvalidOperatorException("$pattern is not a valid operator in quaternion arithmetic") | ||
} | ||
} | ||
|
||
fun QunaryQ(op: (Quaternion) -> (Quaternion)) = OperatorUnary(ACCEPTS_Q) | ||
{i: Iota -> op(Operator.downcast(i, ComplexHexIotaTypes.QUATERNION).quaternion).asIota() } | ||
fun QunaryD(op: (Quaternion) -> (Double)) = OperatorUnary(ACCEPTS_Q) | ||
{i: Iota -> DoubleIota(op(Operator.downcast(i, ComplexHexIotaTypes.QUATERNION).quaternion))} | ||
fun QQbinaryQ(op: (Quaternion, Quaternion) -> (Quaternion)) = OperatorBinary(ACCEPTS_Q) | ||
{i: Iota, j: Iota -> op(Operator.downcast(i, ComplexHexIotaTypes.QUATERNION).quaternion, Operator.downcast(j, ComplexHexIotaTypes.QUATERNION).quaternion).asIota() } | ||
private fun QDbinaryQ(op: (Quaternion, Double) -> (Quaternion)) = OperatorBinary(ACCEPTS_QD) | ||
{i: Iota, j: Iota -> op(Operator.downcast(i, ComplexHexIotaTypes.QUATERNION).quaternion, Operator.downcast(j, HexIotaTypes.DOUBLE).double).asIota() } | ||
private fun QQorQDbinaryQ(opA:(Quaternion, Quaternion) -> (Quaternion), opB:(Quaternion, Double) -> (Quaternion)) = OperatorBinary(ACCEPTS_QQorQD) | ||
{i: Iota, j:Iota -> if (j is QuaternionIota) { | ||
opA(Operator.downcast(i, ComplexHexIotaTypes.QUATERNION).quaternion, Operator.downcast(j, ComplexHexIotaTypes.QUATERNION).quaternion).asIota() | ||
} else if (j is DoubleIota) { | ||
opB(Operator.downcast(i, ComplexHexIotaTypes.QUATERNION).quaternion, Operator.downcast(j, HexIotaTypes.DOUBLE).double).asIota() | ||
} else { | ||
throw InvalidOperatorException("i did an oopsie, report this pls :3 (${j::class})") | ||
} | ||
} | ||
private fun DVbinaryQ(op: (Double, Vec3) -> Quaternion) = OperatorBinary(ACCEPTS_DV) | ||
{i: Iota, j:Iota -> op(Operator.downcast(i, HexIotaTypes.DOUBLE).double, Operator.downcast(j, HexIotaTypes.VEC3).vec3).asIota()} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 2 additions & 8 deletions
10
common/src/main/resources/assets/complexhex/lang/en_us.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,7 @@ | ||
{ | ||
"item.complexhex.dummy_item": "Dummy Item", | ||
"hexcasting.action.complexhex:congrats": "Congrats", | ||
"hexcasting.action.complexhex:signum": "Signum Purification", | ||
"hexcasting.action.book.complexhex:congrats": "Dum. Spell Actn.", | ||
"hexcasting.action.book.complexhex:const/complex/i": "Constant Imagination", | ||
"complexhex.entry.complex_spells": "Dummy Spells", | ||
"complexhex.entry.complex_actions": "Complexities", | ||
"complexhex.page.complex_spells.congrats": "Accepts a player entity, tells them they are doing a good job and makes them look up.", | ||
"complexhex.page.complex_actions.const.i": "Pushes 0 + 1i to the stack", | ||
"text.complexhex.congrats": "Good job, %1$s!", | ||
"text.complexhex.congrats.player": "a Player" | ||
|
||
|
||
} |