File tree Expand file tree Collapse file tree 1 file changed +8
-9
lines changed Expand file tree Collapse file tree 1 file changed +8
-9
lines changed Original file line number Diff line number Diff line change 1
1
import { useXRInputSourceEvent } from '@react-three/xr'
2
2
import { useState } from 'react'
3
3
import { Quaternion , Vector3 } from 'three'
4
-
5
4
import { Duck } from './duck.js'
6
5
import { hitTestMatrices } from './app.js'
7
6
7
+ const vectorHelper = new Vector3 ( )
8
+
8
9
export const Ducks = ( ) => {
9
10
const [ ducks , setDucks ] = useState < Array < { position : Vector3 ; quaternion : Quaternion } > > ( [ ] )
10
11
@@ -14,20 +15,18 @@ export const Ducks = () => {
14
15
( e ) => {
15
16
const matrix = hitTestMatrices [ e . inputSource . handedness ]
16
17
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 } ] )
24
23
}
25
24
} ,
26
25
27
26
[ ] ,
28
27
)
29
28
30
29
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 } />
32
31
) )
33
32
}
You can’t perform that action at this time.
0 commit comments