feat: Add target parameter to setCameraView function for improved camera control
This commit is contained in:
parent
c1a7fe3015
commit
617d29f2e3
|
@ -6,6 +6,7 @@ interface SetCameraViewProps {
|
|||
position: THREE.Vector3 | { x: number; y: number; z: number };
|
||||
rotation: THREE.Euler | { x: number; y: number; z: number };
|
||||
username?: string;
|
||||
target?: THREE.Vector3 | { x: number; y: number; z: number };
|
||||
}
|
||||
|
||||
export default async function setCameraView({
|
||||
|
@ -14,6 +15,7 @@ export default async function setCameraView({
|
|||
position,
|
||||
rotation,
|
||||
username,
|
||||
target
|
||||
}: SetCameraViewProps) {
|
||||
if (!controls || !camera) return;
|
||||
|
||||
|
@ -22,22 +24,7 @@ export default async function setCameraView({
|
|||
? position
|
||||
: new THREE.Vector3(position.x, position.y, position.z);
|
||||
|
||||
// Normalize rotation
|
||||
const newRotation = rotation instanceof THREE.Euler
|
||||
? rotation
|
||||
: new THREE.Euler(rotation.x, rotation.y, rotation.z);
|
||||
|
||||
// Update camera position and rotation
|
||||
// camera.position.copy(newPosition);
|
||||
// camera.rotation.copy(newRotation);
|
||||
|
||||
// If your controls need to update the target, you can optionally adjust it too
|
||||
if (controls.setTarget) {
|
||||
// Setting a basic target slightly forward from new position based on rotation
|
||||
const cameraDirection = new THREE.Vector3(0, 0, -1).applyEuler(newRotation);
|
||||
const targetPosition = new THREE.Vector3().copy(newPosition).add(cameraDirection);
|
||||
|
||||
// controls.setTarget(targetPosition.x, targetPosition.y, targetPosition.z);
|
||||
controls?.setLookAt(...newPosition.toArray(), newPosition.x, 0, newPosition.z, true);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue