static struct normalized_coords accelerator_filter_x230(struct motion_filter *filter, const struct normalized_coords *unaccelerated, void *data, uint64_t time) { struct pointer_accelerator *accel = (struct pointer_accelerator *) filter; double accel_factor; /* unitless factor */ struct normalized_coords accelerated; double velocity; /* units/us */ feed_trackers(accel, unaccelerated, time); velocity = calculate_velocity(accel, time); accel_factor = calculate_acceleration(accel, data, velocity, accel->last_velocity, time); accel->last_velocity = velocity; accelerated.x = accel_factor * unaccelerated->x; accelerated.y = accel_factor * unaccelerated->y; return accelerated; }
void TWCloudDrift::check_velocities(int time) { if(debug_enabled()) debug_printf(DL_DEBUG, "Updating velocity"); // Obtain the current location and velocity SService<IObjectSrv> obj_srv(g_pScriptManager); cScrVec position; obj_srv -> Position(position, ObjId()); SService<IPhysSrv> phys_srv(g_pScriptManager); cScrVec velocity; phys_srv -> GetVelocity(ObjId(), velocity); // And the initial location const mxs_vector *location = start_position; // Recalculate any velocities that need changing if(driftrange.x && minrates.x && maxrates.x) velocity.x = calculate_velocity(location -> x, driftrange.x, minrates.x, maxrates.x, position.x, velocity.x); if(driftrange.y && minrates.y && maxrates.y) velocity.y = calculate_velocity(location -> y, driftrange.y, minrates.y, maxrates.y, position.y, velocity.y); if(driftrange.z && minrates.z && maxrates.z) velocity.z = calculate_velocity(location -> z, driftrange.z, minrates.z, maxrates.z, position.z, velocity.z); phys_srv -> SetVelocity(ObjId(), velocity); if(debug_enabled()) debug_printf(DL_DEBUG, "Pos/Vel,%d,%.3f,%.3f,%.3f,%.3f,%.3f,%.3f", time, position.x, position.y, position.z, velocity.x, velocity.y, velocity.z); // This shouldn't be needed, but check anyway if(update_timer) { cancel_timed_message(update_timer); } // And schedule the next update. update_timer = set_timed_message("CheckVelocity", refresh, kSTM_OneShot); }
static inline double calculate_acceleration_factor(struct pointer_accelerator *accel, const struct normalized_coords *unaccelerated, void *data, uint64_t time) { double velocity; /* units/us */ double accel_factor; feed_trackers(accel, unaccelerated, time); velocity = calculate_velocity(accel, time); accel_factor = calculate_acceleration(accel, data, velocity, accel->last_velocity, time); accel->last_velocity = velocity; return accel_factor; }
static struct normalized_coords accelerator_filter_x230(struct motion_filter *filter, const struct device_float_coords *raw, void *data, uint64_t time) { struct pointer_accelerator *accel = (struct pointer_accelerator *) filter; double accel_factor; /* unitless factor */ struct normalized_coords accelerated; struct device_float_coords delta_normalized; struct normalized_coords unaccelerated; double velocity; /* units/us */ /* This filter is a "do not touch me" filter. So the hack here is * just to replicate the old behavior before filters switched to * device-native dpi: * 1) convert from device-native to 1000dpi normalized * 2) run all calculation on 1000dpi-normalized data * 3) apply accel factor no normalized data */ unaccelerated = normalize_for_dpi(raw, accel->dpi); delta_normalized.x = unaccelerated.x; delta_normalized.y = unaccelerated.y; feed_trackers(accel, &delta_normalized, time); velocity = calculate_velocity(accel, time); accel_factor = calculate_acceleration(accel, data, velocity, accel->last_velocity, time); accel->last_velocity = velocity; accelerated.x = accel_factor * delta_normalized.x; accelerated.y = accel_factor * delta_normalized.y; return accelerated; }
static void accelerator_filter(struct weston_motion_filter *filter, struct weston_motion_params *motion, void *data, uint32_t time) { struct pointer_accelerator *accel = (struct pointer_accelerator *) filter; double velocity; double accel_value; feed_trackers(accel, motion->dx, motion->dy, time); velocity = calculate_velocity(accel, time); accel_value = calculate_acceleration(accel, data, velocity, time); motion->dx = accel_value * motion->dx; motion->dy = accel_value * motion->dy; apply_softening(accel, motion); accel->last_dx = motion->dx; accel->last_dy = motion->dy; accel->last_velocity = velocity; }
static struct normalized_coords accelerator_filter(struct motion_filter *filter, const struct normalized_coords *unaccelerated, void *data, uint64_t time) { struct pointer_accelerator *accel = (struct pointer_accelerator *) filter; double velocity; /* units/ms */ double accel_value; /* unitless factor */ struct normalized_coords accelerated; struct normalized_coords unnormalized; double dpi_factor = accel->dpi_factor; /* For low-dpi mice, use device units, everything else uses 1000dpi normalized */ dpi_factor = min(1.0, dpi_factor); unnormalized.x = unaccelerated->x * dpi_factor; unnormalized.y = unaccelerated->y * dpi_factor; feed_trackers(accel, &unnormalized, time); velocity = calculate_velocity(accel, time); accel_value = calculate_acceleration(accel, data, velocity, accel->last_velocity, time); accelerated.x = accel_value * unnormalized.x; accelerated.y = accel_value * unnormalized.y; accel->last = unnormalized; accel->last_velocity = velocity; return accelerated; }
// catch-all function to update macroscopic properties of a node void Node::update_macroscopic_properties(void) { calculate_density(); calculate_velocity(); calculate_feq(); }