Skip to content

Commit a49edb5

Browse files
committed
fix duck rotation in hit test example
1 parent eceaeef commit a49edb5

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

examples/hit-testing/src/ducks.tsx

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import { useXRInputSourceEvent } from '@react-three/xr'
22
import { useState } from 'react'
33
import { Quaternion, Vector3 } from 'three'
4-
54
import { Duck } from './duck.js'
65
import { hitTestMatrices } from './app.js'
76

7+
const vectorHelper = new Vector3()
8+
89
export const Ducks = () => {
910
const [ducks, setDucks] = useState<Array<{ position: Vector3; quaternion: Quaternion }>>([])
1011

@@ -14,20 +15,18 @@ export const Ducks = () => {
1415
(e) => {
1516
const matrix = hitTestMatrices[e.inputSource.handedness]
1617
if (matrix) {
17-
setDucks((ducks) => [
18-
...ducks,
19-
{
20-
position: new Vector3().setFromMatrixPosition(matrix),
21-
quaternion: new Quaternion().setFromRotationMatrix(matrix),
22-
},
23-
])
18+
const position = new Vector3()
19+
const quaternion = new Quaternion()
20+
21+
matrix.decompose(position, quaternion, vectorHelper)
22+
setDucks((ducks) => [...ducks, { position, quaternion }])
2423
}
2524
},
2625

2726
[],
2827
)
2928

3029
return ducks.map((item, index) => (
31-
<Duck key={index} position={item.position} quaternion={item.quaternion.invert()} scale={0.2} />
30+
<Duck key={index} position={item.position} quaternion={item.quaternion} scale={0.2} />
3231
))
3332
}

0 commit comments

Comments
 (0)