|
| 1 | +import { useState } from 'react'; |
| 2 | +import styles from './ARControls.module.scss'; |
| 3 | + |
| 4 | +const ARControls = () => { |
| 5 | + const [isExpanded, setIsExpanded] = useState(false); |
| 6 | + const [rotationValue, setRotationValue] = useState(0); |
| 7 | + const [positionX, setPositionX] = useState(0); |
| 8 | + const [positionZ, setPositionZ] = useState(0); |
| 9 | + const [height, setHeight] = useState(0); |
| 10 | + |
| 11 | + const updateStreetContainer = (rotation, x, z, y) => { |
| 12 | + const streetContainer = document.getElementById('street-container'); |
| 13 | + if (streetContainer) { |
| 14 | + streetContainer.setAttribute('rotation', `0 ${rotation} 0`); |
| 15 | + streetContainer.setAttribute('position', `${x} ${y} ${z}`); |
| 16 | + } else { |
| 17 | + console.log('street-container element not found'); |
| 18 | + } |
| 19 | + }; |
| 20 | + |
| 21 | + const handleRotationChange = (event) => { |
| 22 | + const newRotation = parseFloat(event.target.value); |
| 23 | + setRotationValue(newRotation); |
| 24 | + updateStreetContainer(newRotation, positionX, positionZ, height); |
| 25 | + }; |
| 26 | + |
| 27 | + const handlePositionXChange = (event) => { |
| 28 | + const newX = parseFloat(event.target.value); |
| 29 | + setPositionX(newX); |
| 30 | + updateStreetContainer(rotationValue, newX, positionZ, height); |
| 31 | + }; |
| 32 | + |
| 33 | + const handlePositionZChange = (event) => { |
| 34 | + const newZ = parseFloat(event.target.value); |
| 35 | + setPositionZ(newZ); |
| 36 | + updateStreetContainer(rotationValue, positionX, newZ, height); |
| 37 | + }; |
| 38 | + |
| 39 | + const handleHeightChange = (event) => { |
| 40 | + const newHeight = parseFloat(event.target.value); |
| 41 | + setHeight(newHeight); |
| 42 | + updateStreetContainer(rotationValue, positionX, positionZ, newHeight); |
| 43 | + }; |
| 44 | + |
| 45 | + const toggleExpanded = () => { |
| 46 | + setIsExpanded(!isExpanded); |
| 47 | + }; |
| 48 | + |
| 49 | + if (!isExpanded) { |
| 50 | + return ( |
| 51 | + <button |
| 52 | + className={styles.toggleButton} |
| 53 | + onClick={toggleExpanded} |
| 54 | + title="AR Scene Adjustments" |
| 55 | + > |
| 56 | + 🎯 |
| 57 | + </button> |
| 58 | + ); |
| 59 | + } |
| 60 | + |
| 61 | + return ( |
| 62 | + <div className={styles.arControls}> |
| 63 | + <div className={styles.header}> |
| 64 | + <span className={styles.title}>AR Scene Adjustments</span> |
| 65 | + <button |
| 66 | + className={styles.closeButton} |
| 67 | + onClick={toggleExpanded} |
| 68 | + title="Collapse" |
| 69 | + > |
| 70 | + ✕ |
| 71 | + </button> |
| 72 | + </div> |
| 73 | + |
| 74 | + <div className={styles.controlGroup}> |
| 75 | + <label className={styles.label}>Rotation: {rotationValue}°</label> |
| 76 | + <input |
| 77 | + type="range" |
| 78 | + min="-180" |
| 79 | + max="180" |
| 80 | + step="5" |
| 81 | + value={rotationValue} |
| 82 | + onInput={handleRotationChange} |
| 83 | + className={styles.slider} |
| 84 | + /> |
| 85 | + </div> |
| 86 | + |
| 87 | + <div className={styles.controlGroup}> |
| 88 | + <label className={styles.label}>Position X: {positionX}m</label> |
| 89 | + <input |
| 90 | + type="range" |
| 91 | + min="-50" |
| 92 | + max="50" |
| 93 | + step="1" |
| 94 | + value={positionX} |
| 95 | + onInput={handlePositionXChange} |
| 96 | + className={styles.slider} |
| 97 | + /> |
| 98 | + </div> |
| 99 | + |
| 100 | + <div className={styles.controlGroup}> |
| 101 | + <label className={styles.label}>Position Z: {positionZ}m</label> |
| 102 | + <input |
| 103 | + type="range" |
| 104 | + min="-50" |
| 105 | + max="50" |
| 106 | + step="1" |
| 107 | + value={positionZ} |
| 108 | + onInput={handlePositionZChange} |
| 109 | + className={styles.slider} |
| 110 | + /> |
| 111 | + </div> |
| 112 | + |
| 113 | + <div className={styles.controlGroup}> |
| 114 | + <label className={styles.label}>Height: {height}m</label> |
| 115 | + <input |
| 116 | + type="range" |
| 117 | + min="-5" |
| 118 | + max="5" |
| 119 | + step="0.1" |
| 120 | + value={height} |
| 121 | + onInput={handleHeightChange} |
| 122 | + className={styles.slider} |
| 123 | + /> |
| 124 | + </div> |
| 125 | + </div> |
| 126 | + ); |
| 127 | +}; |
| 128 | + |
| 129 | +export default ARControls; |
0 commit comments