Skip to content

Commit

Permalink
Wire up some stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
janhohenheim committed Aug 18, 2024
1 parent 266a105 commit 192fb61
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 35 deletions.
15 changes: 2 additions & 13 deletions src/interaction/hold/on_hold.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,15 @@ pub(super) fn on_hold(
trigger: Trigger<OnAdd, Holding>,
mut commands: Commands,
mut q_actor: Query<(&mut AvianPickupActorState, &mut GrabParams, &Holding)>,
mut q_prop: Query<(
Option<&PreferredPickupRotation>,
Option<&PreferredPickupDistance>,
Option<&PickupMass>,
&mut Mass,
&Rotation,
)>,
mut q_prop: Query<(Option<&PickupMass>, &mut Mass)>,
) {
let actor = trigger.entity();
let (mut state, mut grab, holding) = q_actor.get_mut(actor).unwrap();
let prop = holding.0;
*state = AvianPickupActorState::Holding(prop);
// Safety: All props are rigid bodies, so they are guaranteed to have a
// `Rotation` and `Rotation`.
let (preferred_rotation, preferred_distance, pickup_mass, mut mass, rotation) =
q_prop.get_mut(prop).unwrap();
let target_rotation = preferred_rotation
.map(|preferred| preferred.0)
.unwrap_or(rotation.0);
let target_distance = preferred_distance.copied().unwrap_or_default().0;
let (pickup_mass, mut mass) = q_prop.get_mut(prop).unwrap();
let new_mass = pickup_mass.copied().unwrap_or_default().0;
commands.entity(prop).insert(NonPickupMass(mass.0));
mass.0 = new_mass;
Expand Down
19 changes: 6 additions & 13 deletions src/interaction/hold/simulate.rs
Original file line number Diff line number Diff line change
@@ -1,32 +1,25 @@
use super::{GrabParams, ShadowParams};
use crate::prelude::*;
use crate::{prelude::*, verb::Holding};

/// Basically GrabController::Simulate
pub(super) fn simulate(
time: Res<Time>,
mut q_object: Query<(
mut q_prop: Query<(
&Mass,
&mut LinearVelocity,
&mut AngularVelocity,
&GlobalTransform,
)>,
mut q_actor: Query<(
&AvianPickupActorState,
&GlobalTransform,
&mut GrabParams,
&ShadowParams,
)>,
mut q_actor: Query<(&GlobalTransform, &mut GrabParams, &ShadowParams, &Holding)>,
) {
for (&state, transform, mut grab, shadow) in q_actor.iter_mut() {
let AvianPickupActorState::Holding(entity) = state else {
continue;
};
for (transform, mut grab, shadow, holding) in q_actor.iter_mut() {
let prop = holding.0;
let _transform = transform.compute_transform();
let dt = time.delta_seconds();

// Unwrap cannot fail: rigid bodies are guarateed to have a
// `Mass`, `LinearVelocity`, `AngularVelocity`, and `GlobalTransform`
let (mass, mut velocity, mut angvel, object_transform) = q_object.get_mut(entity).unwrap();
let (mass, mut velocity, mut angvel, object_transform) = q_prop.get_mut(prop).unwrap();
let object_transform = object_transform.compute_transform();

// imo InContactWithHeavyObject will always be false,
Expand Down
36 changes: 27 additions & 9 deletions src/interaction/hold/update.rs
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
use bevy::prelude::*;

use super::{GrabParams, ShadowParams};
use crate::prelude::*;
use crate::{prelude::*, verb::Holding};

/// CGrabController::ComputeError(),
pub(super) fn update_error(
q_prop: Query<&Position>,
mut q_actor: Query<(&AvianPickupActorState, &mut GrabParams, &ShadowParams)>,
mut q_actor: Query<(&mut GrabParams, &ShadowParams, &Holding)>,
) {
for (&state, mut grab, shadow) in q_actor.iter_mut() {
let AvianPickupActorState::Holding(prop_entity) = state else {
continue;
};
for (mut grab, shadow, holding) in q_actor.iter_mut() {
let prop = holding.0;
if grab.error_time <= 0.0 {
continue;
}
// Safety: All props are rigid bodies, so they are guaranteed to have a
// `Position`.
let position = q_prop.get(prop_entity).unwrap();
let position = q_prop.get(prop).unwrap();
let mut error = (position.0 - shadow.target_position).length();
if grab.error_time > 1.0 {
grab.error_time = 1.0;
Expand All @@ -35,8 +33,28 @@ pub(super) fn update_error(

/// CGrabController::UpdateObject
pub(super) fn update_object(
_q_prop: Query<&Position>,
_q_actor: Query<(&AvianPickupActorState, &mut GrabParams, &ShadowParams)>,
mut q_prop: Query<(
Option<&PreferredPickupRotation>,
Option<&PreferredPickupDistance>,
Option<&PickupMass>,
&Position,
&Rotation,
)>,
mut q_actor: Query<(
&AvianPickupActorState,
&mut GrabParams,
&ShadowParams,
&Holding,
)>,
) {
let _max_error = 0.3048; // 12 inches in the source engine
for (_state, _grab, _shadow, holding) in q_actor.iter_mut() {
let prop = holding.0;
let (preferred_rotation, preferred_distance, _pickup_mass, _position, rotation) =
q_prop.get_mut(prop).unwrap();
let _target_rotation = preferred_rotation
.map(|preferred| preferred.0)
.unwrap_or(rotation.0);
let _target_distance = preferred_distance.copied().unwrap_or_default().0;
}
}

0 comments on commit 192fb61

Please sign in to comment.