Skip to content

Commit

Permalink
Auto rotate camera
Browse files Browse the repository at this point in the history
  • Loading branch information
tijszwinkels committed Nov 24, 2024
1 parent 792f2e5 commit ee1cd53
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 3 deletions.
12 changes: 12 additions & 0 deletions src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ function App() {
const params = new URLSearchParams(window.location.search);
return params.get('fade') !== 'false';
});
const [autoRotate, setAutoRotate] = useState(() => {
const params = new URLSearchParams(window.location.search);
return params.get('rotate') !== 'false';
});
const [onlySelectedWords, setOnlySelectedWords] = useState(() => {
const params = new URLSearchParams(window.location.search);
return params.get('onlySelected') === 'true';
Expand Down Expand Up @@ -231,6 +235,11 @@ function App() {
updateURL({ fade: enabled ? null : 'false' });
};

const handleAutoRotateChange = (enabled) => {
setAutoRotate(enabled);
updateURL({ rotate: enabled ? null : 'false' });
};

const handleOnlySelectedWordsChange = (enabled) => {
setOnlySelectedWords(enabled);
updateURL({ onlySelected: enabled ? 'true' : null });
Expand All @@ -254,6 +263,7 @@ function App() {
marbleSize={marbleSize}
fadeEnabled={fadeEnabled}
selectedWords={selectedWords}
autoRotate={autoRotate}
/>
</div>
</div>
Expand All @@ -268,6 +278,8 @@ function App() {
onFractionChange={handleFractionChange}
fadeEnabled={fadeEnabled}
onFadeChange={handleFadeChange}
autoRotate={autoRotate}
onAutoRotateChange={handleAutoRotateChange}
onlySelectedWords={onlySelectedWords}
onOnlySelectedWordsChange={handleOnlySelectedWordsChange}
selectedWords={selectedWords}
Expand Down
6 changes: 6 additions & 0 deletions src/components/Config.css
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,17 @@
gap: 8px;
cursor: pointer;
user-select: none;
flex: 1;
min-width: 120px;
font-size: 0.9em;
}

.config-checkbox {
width: 16px;
height: 16px;
margin: 0;
cursor: pointer;
flex-shrink: 0;
}

.config-controls {
Expand Down Expand Up @@ -73,5 +77,7 @@

.checkbox-group {
display: flex;
flex-wrap: wrap;
gap: 12px;
padding: 4px 0;
}
17 changes: 16 additions & 1 deletion src/components/Config.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ function Config({
fraction,
onFractionChange,
onlySelectedWords,
onOnlySelectedWordsChange
onOnlySelectedWordsChange,
autoRotate,
onAutoRotateChange
}) {
const handleTimeoutSliderChange = (e) => {
const value = parseInt(e.target.value, 10);
Expand Down Expand Up @@ -57,6 +59,10 @@ function Config({
onOnlySelectedWordsChange(e.target.checked);
};

const handleAutoRotateChange = (e) => {
onAutoRotateChange(e.target.checked);
};

return (
<div className="config-container">
<h3>Configuration</h3>
Expand Down Expand Up @@ -138,6 +144,15 @@ function Config({
/>
Enable Fade Effect
</label>
<label className="checkbox-label">
<input
type="checkbox"
checked={autoRotate}
onChange={handleAutoRotateChange}
className="config-checkbox"
/>
Auto-Rotate Camera
</label>
<label className="checkbox-label">
<input
type="checkbox"
Expand Down
9 changes: 7 additions & 2 deletions src/components/MarblesDisplay.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ function Vase() {
);
}

function MarblesDisplay({ messages, timeout = 60, marbleSize = 0.5, fadeEnabled = true, selectedWords }) {
function MarblesDisplay({ messages, timeout = 60, marbleSize = 0.5, fadeEnabled = true, selectedWords, autoRotate = true }) {
const [marbles, setMarbles] = useState([]);
const marbleCountRef = useRef(0);

Expand Down Expand Up @@ -260,7 +260,12 @@ function MarblesDisplay({ messages, timeout = 60, marbleSize = 0.5, fadeEnabled
/>
))}
</Physics>
<OrbitControls enablePan={true} target={[0, 4, 0]} />
<OrbitControls
enablePan={true}
target={[0, 4, 0]}
autoRotate={autoRotate}
autoRotateSpeed={1}
/>
</Canvas>
</div>
);
Expand Down
4 changes: 4 additions & 0 deletions src/components/RightPanel.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ function RightPanel({
hiddenWords,
onlySelectedWords,
onOnlySelectedWordsChange,
autoRotate,
onAutoRotateChange,
onAddCustomWord,
isCollapsed,
onCollapsedChange
Expand Down Expand Up @@ -58,6 +60,8 @@ function RightPanel({
onFractionChange={onFractionChange}
onlySelectedWords={onlySelectedWords}
onOnlySelectedWordsChange={onOnlySelectedWordsChange}
autoRotate={autoRotate}
onAutoRotateChange={onAutoRotateChange}
/>
</div>
</div>
Expand Down

0 comments on commit ee1cd53

Please sign in to comment.