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
use super::*;
use crate::*;
use bevy::prelude::*;

#[derive(Bundle)]
pub struct OrbitCameraBundle {
	name:Name,
	camera: Camera3dBundle,
	parent: CameraParent,
	view_type: CameraViewType,
	controller: OrbitController,
	transform_controller: input::TransformController,
}

impl Default for OrbitCameraBundle {
	fn default() -> Self { Self::new(Vec3::new(2., 3., 5.)) }
}
impl OrbitCameraBundle {
	pub fn new(position: Vec3) -> Self {
		let radius = position.length();
		Self {
			name: "Orbit Camera".into(),
			camera: Camera3dBundle {
				transform: Transform::from_translation(position)
					.looking_at(Vec3::ZERO, Vec3::Y),
				..default()
			},
			parent: CameraParent,
			view_type: CameraViewType::Orbit,
			controller: OrbitController {
				radius,
				..default()
			},
			transform_controller: input::TransformController::default(),
		}
	}
}