-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathControlsPanel.tsx
More file actions
130 lines (126 loc) · 3.85 KB
/
ControlsPanel.tsx
File metadata and controls
130 lines (126 loc) · 3.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
import React, { RefObject } from 'react';
import './ControlsPanel.css'; // Make sure to import the CSS file
interface ControlsPanelProps {
miniCanvasRef: RefObject<HTMLCanvasElement>;
launchAngle: number;
setLaunchAngle: (value: number) => void;
initialVelocity: number;
setInitialVelocity: (value: number) => void;
timeScale: number;
setTimeScale: (value: number) => void;
startSimulation: () => void;
pauseSimulation: () => void;
resetSimulation: () => void;
simulationState: {
isRunning: boolean;
time: number;
positionX: number;
positionY: number;
velocityX: number;
velocityY: number;
};
EARTH_RADIUS: number;
}
const scrollToTop = () => {
window.scrollTo({
top: 0,
behavior: 'smooth'
});
};
const ControlsPanel: React.FC<ControlsPanelProps> = ({
miniCanvasRef,
launchAngle,
setLaunchAngle,
initialVelocity,
setInitialVelocity,
timeScale,
setTimeScale,
startSimulation,
pauseSimulation,
resetSimulation,
simulationState,
EARTH_RADIUS
}) => {
return (
<div className="controls-panel">
<h2>Mission Control</h2>
<canvas style={{ display: 'none' }} ref={miniCanvasRef} width={250} height={250} />
<div className="control-group">
<label>Launch Angle: {launchAngle}°</label>
<input type="range" min={1} max={179} value={launchAngle} onChange={(e) => setLaunchAngle(Number(e.target.value))} />
</div>
<div className="control-group">
<label>Initial Velocity: {initialVelocity} m/s</label>
<input
type="range"
min={500}
max={12000}
step={100}
value={initialVelocity}
onChange={(e) => setInitialVelocity(Number(e.target.value))}
/>
</div>
<div className="control-group">
<label>Time Scale: {timeScale}x</label>
<input
type="range"
min={0.1}
max={50}
step={0.1}
value={timeScale}
onChange={(e) => setTimeScale(Number(e.target.value))}
/>
</div>
<div className="button-group">
<button
onClick={() => {
startSimulation();
scrollToTop();
}}
disabled={simulationState.isRunning}
className={`button button-start ${simulationState.isRunning ? 'disabled' : ''}`}
>
Start
</button>
<button
onClick={pauseSimulation}
disabled={!simulationState.isRunning}
className={`button button-pause ${!simulationState.isRunning ? 'disabled' : ''}`}
>
Pause
</button>
<button onClick={resetSimulation} className="button button-reset">
Reset
</button>
</div>
<div className="simulation-status">
<p>Time: {simulationState.time.toLocaleString('en-US', { minimumFractionDigits: 2, maximumFractionDigits: 2 })} s</p>
<p>
Altitude:{' '}
{(Math.sqrt(simulationState.positionX ** 2 + simulationState.positionY ** 2) - EARTH_RADIUS).toLocaleString('en-US', {
minimumFractionDigits: 2,
maximumFractionDigits: 2
})}{' '}
m
</p>
<p>
Velocity:{' '}
{Math.sqrt(simulationState.velocityX ** 2 + simulationState.velocityY ** 2).toLocaleString('en-US', {
minimumFractionDigits: 2,
maximumFractionDigits: 2
})}{' '}
m/s
</p>
<p>
Angle:{' '}
{((Math.atan2(simulationState.positionY, simulationState.positionX) * 180) / Math.PI).toLocaleString('en-US', {
minimumFractionDigits: 2,
maximumFractionDigits: 2
})}
°
</p>
</div>
</div>
);
};
export default ControlsPanel;