Skip to content

Commit

Permalink
Format fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Stermere committed Jul 29, 2024
1 parent 8e09489 commit 69d62fe
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import io.github.axisangles.ktmath.Vector3
import kotlin.math.*

/**
* Represents a function that applies a rotational constraint to a direction vector.
* Represents a function that applies a rotational constraint.
*/
typealias ConstraintFunction = (Quaternion, Bone, Float, Float) -> Quaternion
typealias ConstraintFunction = (inputRotation: Quaternion, thisBone: Bone, limit1: Float, limit2: Float) -> Quaternion

/**
* Represents the rotational limits of a Bone relative to its parent
Expand Down Expand Up @@ -103,7 +103,7 @@ class Constraint(
}

// Constraint function for TwistSwingConstraint
val twistSwingConstraint: ConstraintFunction =
private val twistSwingConstraint: ConstraintFunction =
{ rotation: Quaternion, thisBone: Bone, swingRad: Float, twistRad: Float ->
if (thisBone.parent == null) {
rotation
Expand All @@ -121,7 +121,7 @@ class Constraint(
}

// Constraint function for a hinge constraint with min and max angles
val hingeConstraint: ConstraintFunction =
private val hingeConstraint: ConstraintFunction =
{ rotation: Quaternion, thisBone: Bone, min: Float, max: Float ->
if (thisBone.parent == null) {
rotation
Expand All @@ -138,7 +138,7 @@ class Constraint(
}

// Constraint function for CompleteConstraint
val completeConstraint: ConstraintFunction = { _: Quaternion, thisBone: Bone, _: Float, _: Float ->
private val completeConstraint: ConstraintFunction = { _: Quaternion, thisBone: Bone, _: Float, _: Float ->
thisBone.getGlobalRotation()
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
package dev.slimevr.tracking.processor.skeleton

import dev.slimevr.tracking.processor.Bone
import dev.slimevr.tracking.processor.Constraint
import dev.slimevr.tracking.processor.Constraint.Companion.ConstraintType
import dev.slimevr.tracking.trackers.Tracker
import io.github.axisangles.ktmath.Quaternion
import io.github.axisangles.ktmath.Vector3
import kotlin.math.acos
import kotlin.math.cos
import kotlin.math.sin
import kotlin.math.*

/*
* This class implements a chain of Bones
Expand Down Expand Up @@ -42,7 +40,7 @@ class IKChain(
*/
private fun prepBones() {
for (i in 0..<bones.size) {
if (bones[i].rotationConstraint.allowModifications && bones[i].rotationConstraint.constraintType != Constraint.Companion.ConstraintType.COMPLETE) {
if (bones[i].rotationConstraint.allowModifications && bones[i].rotationConstraint.constraintType != ConstraintType.COMPLETE) {
bones[i].setRotationRaw(rotations[i])
}
}
Expand All @@ -66,7 +64,7 @@ class IKChain(
val angle = baseAngle * IKSolver.DAMPENING_FACTOR * if (currentBone.rotationConstraint.allowModifications) 1f else IKSolver.STATIC_DAMPENING

val sinHalfAngle = sin(angle / 2)
val adjustment = Quaternion(cos(angle / 2), cross.x * sinHalfAngle, cross.y * sinHalfAngle, cross.z * sinHalfAngle)
val adjustment = Quaternion(cos(angle / 2), cross * sinHalfAngle)
val correctedRot = (adjustment * currentBone.getGlobalRotation()).unit()

rotations[i] = setBoneRotation(currentBone, correctedRot, useConstraints)
Expand Down Expand Up @@ -99,7 +97,6 @@ class IKChain(
* Resets the chain to its default state
*/
fun resetChain() {
// prepBones()
distToTargetSqr = Float.POSITIVE_INFINITY

for (child in children) {
Expand Down Expand Up @@ -134,7 +131,7 @@ class IKChain(
* returns the constrained rotation
*/
private fun setBoneRotation(bone: Bone, rotation: Quaternion, useConstraints: Boolean): Quaternion {
val newRotation = if (useConstraints || bone.rotationConstraint.constraintType == Constraint.Companion.ConstraintType.COMPLETE) {
val newRotation = if (useConstraints || bone.rotationConstraint.constraintType == ConstraintType.COMPLETE) {
bone.rotationConstraint.applyConstraint(rotation, bone)
} else {
rotation
Expand Down

0 comments on commit 69d62fe

Please sign in to comment.