Skip to content

Commit

Permalink
feat(components): Mark Current section
Browse files Browse the repository at this point in the history
Mark current section in navigation section with red
  • Loading branch information
alimoezzi committed Mar 13, 2022
1 parent cc82bf1 commit b0faad2
Showing 1 changed file with 26 additions and 3 deletions.
29 changes: 26 additions & 3 deletions src/components/Cursor/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,18 @@ export function Cursor({
icons,
sections,
p = new THREE.Vector3(),
dom
dom,
frustum = new THREE.Frustum(),
cameraViewProjectionMatrix = new THREE.Matrix4(),
bbox = new THREE.Box3()
}) {
const outer = useRef()
const [hovered, hover] = useState()
const [pos] = useState(() => new THREE.Vector2())
const ref = useRef()
const clicked = useRef()
const [currentSection, setCurrentSection] = useState(sections[0]?.section)
const clickSound = new Audio('/sound/type.mp3')
const color = hovered ? 'rgb(100 116 139)' : '#fff'

useEffect(() => {
Expand Down Expand Up @@ -70,8 +75,21 @@ export function Cursor({
// onPointerOver={(e) => (e.stopPropagation(), hover(e.object))} onPointerOut={(e) => hover(null)}
<group
ref={ref}
onWheel={() => {
onWheel={(e) => {
clicked.current = null
sections.map(({ section, objName }) => {
if (objName) {
e.camera.updateMatrixWorld() // make sure the camera matrix is updated
e.camera.matrixWorldInverse.copy(e.camera.matrixWorld).invert()
cameraViewProjectionMatrix.multiplyMatrices(e.camera.projectionMatrix, e.camera.matrixWorldInverse)
frustum.setFromProjectionMatrix(cameraViewProjectionMatrix)
bbox.setFromObject(ref.current.getObjectByName(objName))
if (frustum.intersectsBox(bbox)) {
setCurrentSection(section)
}
}
return false
})
}}>
{children}
{/* Everything we'll put into the tunnels "In" will be projected
Expand Down Expand Up @@ -127,10 +145,15 @@ export function Cursor({
onMouseEnter={() => hover(true)}
onMouseLeave={() => hover(false)}
onClick={() => {
clickSound.play()
clicked.current = ref.current.getObjectByName(objName)
setCurrentSection(section)
// api.refresh(clicked.current).fit()
}}>
<div className='font-mono text-base hover:text-white text-zinc-500 hover:underline underline-offset-4 decoration-3'>
<div
className={`font-mono text-base hover:text-white ${
currentSection === section ? 'text-red-500' : 'text-zinc-500'
} hover:underline underline-offset-4 decoration-3`}>
{section}
</div>
</div>
Expand Down

0 comments on commit b0faad2

Please sign in to comment.