Skip to content

Commit

Permalink
Fixed the scale messing up the rotation of scoring zones
Browse files Browse the repository at this point in the history
  • Loading branch information
LucaHaverty committed Jul 17, 2024
1 parent 22ec16f commit 067baf3
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions fission/src/ui/panels/configuring/scoring/ZoneConfigPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,15 @@ function save(
return
}

const gizmoTransformation = gizmo.mesh.matrixWorld
const robotTransformation = JoltMat44_ThreeMatrix4(World.PhysicsSystem.GetBody(nodeBodyId).GetWorldTransform())
const deltaTransformation = gizmoTransformation.premultiply(robotTransformation.invert())
// This step seems useless, but keeps the scale from messing up the rotation
const translation = new THREE.Vector3(0, 0, 0)
const rotation = new THREE.Quaternion(0, 0, 0, 1)
const scale = new THREE.Vector3(1, 1, 1)
gizmo.mesh.matrixWorld.decompose(translation, rotation, scale)

const gizmoTransformation = new THREE.Matrix4().compose(translation, rotation, scale)
const fieldTransformation = JoltMat44_ThreeMatrix4(World.PhysicsSystem.GetBody(nodeBodyId).GetWorldTransform())
const deltaTransformation = gizmoTransformation.premultiply(fieldTransformation.invert())

const zone = SelectedZone.zone

Expand Down Expand Up @@ -152,9 +158,15 @@ const ZoneConfigPanel: React.FC<PanelPropsImpl> = ({ panelId, openLocation, side
const fieldTransformation = JoltMat44_ThreeMatrix4(World.PhysicsSystem.GetBody(nodeBodyId).GetWorldTransform())
const gizmoTransformation = deltaTransformation.premultiply(fieldTransformation)

gizmo.mesh.position.setFromMatrixPosition(gizmoTransformation)
gizmo.mesh.rotation.setFromRotationMatrix(gizmoTransformation)
gizmo.mesh.scale.setFromMatrixScale(gizmoTransformation)
// This step seems useless, but keeps the scale from messing up the rotation
const translation = new THREE.Vector3(0, 0, 0)
const rotation = new THREE.Quaternion(0, 0, 0, 1)
const scale = new THREE.Vector3(1, 1, 1)
gizmoTransformation.decompose(translation, rotation, scale)

gizmo.mesh.position.set(translation.x, translation.y, translation.z)
gizmo.mesh.rotation.setFromQuaternion(rotation)
gizmo.mesh.scale.set(scale.x, scale.y, scale.z)

setTransformGizmo(gizmo)

Expand Down

0 comments on commit 067baf3

Please sign in to comment.