Skip to content

Commit

Permalink
Test and update readme examples
Browse files Browse the repository at this point in the history
  • Loading branch information
h3r2tic committed Feb 25, 2024
1 parent 48d621c commit 836dffb
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 9 deletions.
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ While cameras are a complex topic in gamedev, this crate only provides the basic
<https://user-images.githubusercontent.com/16522064/125960266-fc96b302-6d6b-4976-b38c-b6f4fdb8e09b.mp4>

```rust
let mut camera = CameraRig::builder()
let mut camera: CameraRig = CameraRig::builder()
.with(YawPitch::new().yaw_degrees(45.0).pitch_degrees(-30.0))
.with(Smooth::new_rotation(1.5))
.with(Arm::new(Vec3::Z * 4.0))
Expand All @@ -39,7 +39,7 @@ camera.update(time_delta_seconds);
<https://user-images.githubusercontent.com/16522064/125960227-7ee05c04-f47a-4c32-b494-cc36dc70ab63.mp4>

```rust
let mut camera = CameraRig::builder()
let mut camera: CameraRig = CameraRig::builder()
.with(Position::new(car.position))
.with(Rotation::new(car.rotation))
.with(Smooth::new_position(1.25).predictive(true))
Expand All @@ -54,24 +54,24 @@ let mut camera = CameraRig::builder()

// ...

camera.driver_mut::<Position>().position = car.position;
camera.driver_mut::<Rotation>().rotation = car.rotation;
camera.driver_mut::<LookAt>().target = car.position + Vec3::Y;
camera.driver_mut::<Position>().position = car.position.into();
camera.driver_mut::<Rotation>().rotation = car.rotation.into();
camera.driver_mut::<LookAt>().target = (car.position + Vec3::Y).into();
```

---

<https://user-images.githubusercontent.com/16522064/125986386-60cb9d26-06a2-4d3f-9377-56c982fbc7f9.mp4>

```rust
let mut camera = CameraRig::builder()
let mut camera: CameraRig = CameraRig::builder()
.with(Position::new(Vec3::Y * 3.0))
.with(LookAt::new(car.position))
.build();

// ...

camera.driver_mut::<LookAt>().target = car.position;
camera.driver_mut::<LookAt>().target = car.position.into();
camera.update(time_delta_seconds);
```

Expand All @@ -80,7 +80,7 @@ camera.update(time_delta_seconds);
<https://user-images.githubusercontent.com/16522064/125986405-a06f6572-702a-4c1a-a6c7-edf5ba2ed815.mp4>

```rust
let mut camera = CameraRig::builder()
let mut camera: CameraRig = CameraRig::builder()
.with(Position::new(Vec3::Y))
.with(YawPitch::new())
.with(Smooth::new_position_rotation(1.0, 1.0))
Expand Down
2 changes: 1 addition & 1 deletion crates-io.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ While cameras are a complex topic in gamedev, this crate only provides the basic
![orbit camera example](https://oxn9dw.db.files.1drv.com/y4m_cv-3paMLNbYajhGOWPvn172gkHhrOUzmaPXUo8JgZgiFYrygLrt9IrUXXcsoTNf2naYm4Qg-V5JzRSRgwK3-u0bj348uKXUYq8k6ntGWiYpDPMl61P-v42YSFL7lr-IMedLAGheJP54tRBzElRwz4bSzxHdHPJIkXYuBbzmAFEhbX1yHl8uHTGedeHUgnJj0qbMI7fgH9VXNUKzUVaZpw/orbit.gif?download&psid=1)

```rust
let mut camera = CameraRig::builder()
let mut camera: CameraRig = CameraRig::builder()
.with(YawPitch::new().yaw_degrees(45.0).pitch_degrees(-30.0))
.with(Smooth::new_rotation(1.5))
.with(Arm::new(Vec3::Z * 4.0))
Expand Down
98 changes: 98 additions & 0 deletions src/prelude.rs
Original file line number Diff line number Diff line change
@@ -1 +1,99 @@
pub use crate::{drivers::*, handedness::*, rig::CameraRig};

#[test]
fn orbit_example_compile_test() {
use glam::Vec3;

let mut camera: CameraRig = CameraRig::builder()
.with(YawPitch::new().yaw_degrees(45.0).pitch_degrees(-30.0))
.with(Smooth::new_rotation(1.5))
.with(Arm::new(Vec3::Z * 4.0))
.build();

// ...

fn was_key_pressed(_: char) -> bool {
true
}

let camera_driver = camera.driver_mut::<YawPitch>();
if was_key_pressed('Z') {
camera_driver.rotate_yaw_pitch(-90.0, 0.0);
}
if was_key_pressed('X') {
camera_driver.rotate_yaw_pitch(90.0, 0.0);
}

let time_delta_seconds = 1.0 / 60.0;
camera.update(time_delta_seconds);
}

#[test]
fn follow_example_compile_test() {
use glam::{Quat, Vec3};

#[derive(Default)]
struct Car {
position: Vec3,
rotation: Quat,
}

let car = Car::default();

let mut camera: CameraRig = CameraRig::builder()
.with(Position::new(car.position))
.with(Rotation::new(car.rotation))
.with(Smooth::new_position(1.25).predictive(true))
.with(Arm::new(Vec3::new(0.0, 1.5, -3.5)))
.with(Smooth::new_position(2.5))
.with(
LookAt::new(car.position + Vec3::Y)
.tracking_smoothness(1.25)
.tracking_predictive(true),
)
.build();

// ...

camera.driver_mut::<Position>().position = car.position.into();
camera.driver_mut::<Rotation>().rotation = car.rotation.into();
camera.driver_mut::<LookAt>().target = (car.position + Vec3::Y).into();
}

#[test]
fn lookat_example_compile_test() {
use glam::Vec3;

let mut camera: CameraRig = CameraRig::builder()
.with(Position::new(Vec3::Y * 3.0))
.with(LookAt::new(Vec3::ZERO))
.build();

// ...

let time_delta_seconds = 1.0 / 60.0;
camera.driver_mut::<LookAt>().target = Vec3::X.into();
camera.update(time_delta_seconds);
}

#[test]
fn free_example_compile_test() {
use glam::Vec3;

let mut camera: CameraRig = CameraRig::builder()
.with(Position::new(Vec3::Y))
.with(YawPitch::new())
.with(Smooth::new_position_rotation(1.0, 1.0))
.build();

// ...

let move_vec = Vec3::new(0.1, 0.2, 0.3);
let time_delta_seconds = 1.0 / 60.0;

camera.driver_mut::<YawPitch>().rotate_yaw_pitch(-0.3, -0.2);
camera
.driver_mut::<Position>()
.translate(move_vec * time_delta_seconds);
camera.update(time_delta_seconds);
}

0 comments on commit 836dffb

Please sign in to comment.