Skip to content

Commit 5d705c5

Browse files
committed
Fix implementation
Did not account for existing angle Add fatalError to Position3n as Matrix is not yet available
1 parent 5931747 commit 5d705c5

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

Sources/GameMath/3D Types (New)/Position3n.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,7 @@ public extension Position3n where Scalar: FloatingPoint {
117117
*/
118118
@inlinable
119119
func rotated(around anchor: Self = .zero, by rotation: Rotation3n<Scalar>) -> Self {
120-
let d = self.distance(from: anchor)
121-
return anchor.moved(d, toward: rotation.forward)
120+
fatalError("Not implemented")
122121
}
123122

124123
/** Rotates `self` around an anchor position.

Sources/GameMath/3D Types/Position3.swift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,14 @@ public extension Position3 {
157157
*/
158158
@inlinable
159159
func rotated(around anchor: Self = .zero, by rotation: Quaternion) -> Self {
160+
#if false
161+
// TODO: This implementation is less accurate, needs testing to see if there's any performance benefits
160162
let d = self.distance(from: anchor)
161-
return anchor.moved(d, toward: rotation.forward)
163+
let currentRotation = Quaternion(direction: Direction3(from: anchor, to: self))
164+
return anchor.moved(d, toward: (rotation * currentRotation).forward)
165+
#else
166+
return (Matrix4x4(position: anchor) * Matrix4x4(rotation: rotation)) * self
167+
#endif
162168
}
163169

164170
/** Rotates `self` around an anchor position.

0 commit comments

Comments
 (0)