Skip to content

Sensitivity Sliders #1166

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions fission/src/systems/preferences/PreferenceTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ export type GlobalPreference =
| "ZoomSensitivity"
| "PitchSensitivity"
| "YawSensitivity"
| "SceneRotationSensitivity"
| "ViewCubeRotationSensitivity"
| "ReportAnalytics"
| "UseMetric"
| "RenderScoringZones"
Expand All @@ -32,6 +34,8 @@ export const DefaultGlobalPreferences: { [key: string]: unknown } = {
ZoomSensitivity: 15,
PitchSensitivity: 10,
YawSensitivity: 3,
SceneRotationSensitivity: 0.5,
ViewCubeRotationSensitivity: 0.025,
ReportAnalytics: false,
UseMetric: false,
RenderScoringZones: true,
Expand Down
9 changes: 5 additions & 4 deletions fission/src/systems/scene/CameraControls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import ScreenInteractionHandler, {
PRIMARY_MOUSE_INTERACTION,
SECONDARY_MOUSE_INTERACTION,
} from "./ScreenInteractionHandler"
import PreferencesSystem from "@/systems/preferences/PreferencesSystem"

export type CameraControlsType = "Orbit"

Expand Down Expand Up @@ -43,8 +44,6 @@ const CO_MAX_PHI = Math.PI / 2.1
const CO_MIN_PHI = -Math.PI / 2.1

const CO_SENSITIVITY_ZOOM = 4.0
const CO_SENSITIVITY_PHI = 0.5
const CO_SENSITIVITY_THETA = 0.5

const CO_DEFAULT_ZOOM = 3.5
const CO_DEFAULT_PHI = -Math.PI / 6.0
Expand Down Expand Up @@ -264,8 +263,10 @@ export class CustomOrbitControls extends CameraControls {
}
: { theta: 0, phi: 0, r: 0 }

this._coords.theta += omega.theta * deltaT * CO_SENSITIVITY_THETA
this._coords.phi += omega.phi * deltaT * CO_SENSITIVITY_PHI
this._coords.theta +=
omega.theta * deltaT * PreferencesSystem.getGlobalPreference<number>("SceneRotationSensitivity")
this._coords.phi +=
omega.phi * deltaT * PreferencesSystem.getGlobalPreference<number>("SceneRotationSensitivity")
this._coords.r += omega.r * deltaT * CO_SENSITIVITY_ZOOM * Math.pow(this._coords.r, 1.4)

this._coords.phi = Math.min(CO_MAX_PHI, Math.max(CO_MIN_PHI, this._coords.phi))
Expand Down
5 changes: 3 additions & 2 deletions fission/src/ui/components/ViewCube.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import { Box } from "@mui/material"
import World from "@/systems/World"
import { CustomOrbitControls } from "@/systems/scene/CameraControls"
import PreferencesSystem from "@/systems/preferences/PreferencesSystem"

interface ViewCubeProps {
size?: number
Expand Down Expand Up @@ -67,7 +68,7 @@
const deltaX = event.clientX - lastMousePos.x
const deltaY = event.clientY - lastMousePos.y

const sensitivity = 0.025
const sensitivity = PreferencesSystem.getGlobalPreference<number>("ViewCubeRotationSensitivity")

const controls = World.SceneRenderer.currentCameraControls
if (controls instanceof CustomOrbitControls) {
Expand Down Expand Up @@ -588,7 +589,7 @@
cancelAnimationFrame(animationFrameId)
}
if (containerRef.current && renderer.domElement) {
containerRef.current.removeChild(renderer.domElement)

Check warning on line 592 in fission/src/ui/components/ViewCube.tsx

View workflow job for this annotation

GitHub Actions / ESLint Format Validation

The ref value 'containerRef.current' will likely have changed by the time this effect cleanup function runs. If this ref points to a node rendered by React, copy 'containerRef.current' to a variable inside the effect, and use that variable in the cleanup function
}
renderer.dispose()
}
Expand Down Expand Up @@ -821,7 +822,7 @@
const deltaX = event.clientX - lastMousePos.x
const deltaY = event.clientY - lastMousePos.y

const sensitivity = 0.004
const sensitivity = PreferencesSystem.getGlobalPreference<number>("ViewCubeRotationSensitivity")

const controls = World.SceneRenderer.currentCameraControls
if (controls instanceof CustomOrbitControls) {
Expand Down
31 changes: 31 additions & 0 deletions fission/src/ui/modals/configuring/SettingsModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ const SettingsModal: React.FC<ModalPropsImpl> = ({ modalId }) => {
PreferencesSystem.getGlobalPreference<boolean>("MuteAllSound")
)
const [sfxVolume, setSFXVolume] = useState<number>(PreferencesSystem.getGlobalPreference<number>("SFXVolume"))
const [sceneRotationSensitivity, setSceneRotationSensitivity] = useState<number>(
PreferencesSystem.getGlobalPreference<number>("SceneRotationSensitivity")
)
const [viewCubeRotationSensitivity, setViewCubeRotationSensitivity] = useState<number>(
PreferencesSystem.getGlobalPreference<number>("ViewCubeRotationSensitivity") * 60
)

const saveSettings = () => {
PreferencesSystem.setGlobalPreference<boolean>("ReportAnalytics", reportAnalytics)
Expand All @@ -63,6 +69,8 @@ const SettingsModal: React.FC<ModalPropsImpl> = ({ modalId }) => {
PreferencesSystem.setGlobalPreference<boolean>("ShowViewCube", showViewCube)
PreferencesSystem.setGlobalPreference<boolean>("MuteAllSound", muteAllSound)
PreferencesSystem.setGlobalPreference<number>("SFXVolume", sfxVolume)
PreferencesSystem.setGlobalPreference<number>("SceneRotationSensitivity", sceneRotationSensitivity)
PreferencesSystem.setGlobalPreference<number>("ViewCubeRotationSensitivity", viewCubeRotationSensitivity / 60)

SoundPlayer.changeVolume() // Apply the new sound volume

Expand Down Expand Up @@ -126,6 +134,29 @@ const SettingsModal: React.FC<ModalPropsImpl> = ({ modalId }) => {
onChange={(_, value) => setYawSensitivity(value as number)}
tooltipText="Moving the camera left and right."
/>*/}
{Spacer(5)}
<Label size={LabelSize.Medium}>Camera Settings</Label>
<Slider
min={0.1}
max={2.0}
value={sceneRotationSensitivity}
label={"Scene Rotation Sensitivity"}
format={{ maximumFractionDigits: 2 }}
onChange={(_, value) => setSceneRotationSensitivity(value as number)}
step={0.1}
tooltipText="Controls how fast the scene rotates when dragging with the mouse."
/>
{Spacer(2)}
<Slider
min={0.06}
max={6.0}
value={viewCubeRotationSensitivity}
label={"ViewCube Rotation Sensitivity"}
format={{ maximumFractionDigits: 2 }}
onChange={(_, value) => setViewCubeRotationSensitivity(value as number)}
step={0.06}
tooltipText="Controls how fast the view changes when dragging on the view cube."
/>
{Spacer(10)}
<Label size={LabelSize.Medium}>Preferences</Label>
<Box display="flex" flexDirection={"column"}>
Expand Down
Loading