diff --git a/panda/src/tform/config_tform.cxx b/panda/src/tform/config_tform.cxx index 8b1922d84a..a25948b405 100644 --- a/panda/src/tform/config_tform.cxx +++ b/panda/src/tform/config_tform.cxx @@ -22,7 +22,9 @@ const double drive_forward_speed = config_tform.GetDouble("drive-forward-speed", const double drive_reverse_speed = config_tform.GetDouble("drive-reverse-speed", 10.0); const double drive_rotate_speed = config_tform.GetDouble("drive-rotate-speed", 80.0); const double drive_vertical_dead_zone = config_tform.GetDouble("drive-vertical-dead-zone", 0.1); +const double drive_vertical_center = config_tform.GetDouble("drive-vertical-center", 0.0); const double drive_horizontal_dead_zone = config_tform.GetDouble("drive-horizontal-dead-zone", 0.1); +const double drive_horizontal_center = config_tform.GetDouble("drive-horizontal-center", 0.0); const double drive_vertical_ramp_up_time = config_tform.GetDouble("drive-vertical-ramp-up-time", 0.0); const double drive_vertical_ramp_down_time = config_tform.GetDouble("drive-vertical-ramp-down-time", 0.0); const double drive_horizontal_ramp_up_time = config_tform.GetDouble("drive-horizontal-ramp-up-time", 0.0); diff --git a/panda/src/tform/config_tform.h b/panda/src/tform/config_tform.h index ecd281d2f4..fc9f9f491d 100644 --- a/panda/src/tform/config_tform.h +++ b/panda/src/tform/config_tform.h @@ -16,7 +16,9 @@ extern const double EXPCL_PANDA drive_forward_speed; extern const double EXPCL_PANDA drive_reverse_speed; extern const double EXPCL_PANDA drive_rotate_speed; extern const double EXPCL_PANDA drive_vertical_dead_zone; +extern const double EXPCL_PANDA drive_vertical_center; extern const double EXPCL_PANDA drive_horizontal_dead_zone; +extern const double EXPCL_PANDA drive_horizontal_center; extern const double EXPCL_PANDA drive_vertical_ramp_up_time; extern const double EXPCL_PANDA drive_vertical_ramp_down_time; extern const double EXPCL_PANDA drive_horizontal_ramp_up_time; diff --git a/panda/src/tform/driveInterface.cxx b/panda/src/tform/driveInterface.cxx index 119d76d14b..a5b5389d9b 100644 --- a/panda/src/tform/driveInterface.cxx +++ b/panda/src/tform/driveInterface.cxx @@ -107,6 +107,8 @@ DriveInterface(const string &name) : DataNode(name) { _rotate_speed = drive_rotate_speed; _vertical_dead_zone = drive_vertical_dead_zone; _horizontal_dead_zone = drive_horizontal_dead_zone; + _vertical_center = drive_vertical_center; + _horizontal_center = drive_horizontal_center; _vertical_ramp_up_time = drive_vertical_ramp_up_time; _vertical_ramp_down_time = drive_vertical_ramp_down_time; @@ -627,40 +629,46 @@ apply(double x, double y, bool any_button) { // First, how fast are we moving? This is based on the mouse's // vertical position. - - if (y >= _vertical_dead_zone) { + + float dead_zone_top = _vertical_center + _vertical_dead_zone; + float dead_zone_bottom = _vertical_center - _vertical_dead_zone; + + if (y >= dead_zone_top) { // Motion is forward. Compute the throttle value: the ratio of // the mouse pointer within the range of vertical movement. float throttle = - (min(y, 1.0) - _vertical_dead_zone) / - (1.0 - _vertical_dead_zone); + (min(y, 1.0) - dead_zone_top) / + (1.0 - dead_zone_top); _speed = throttle * _forward_speed; - } else if (y <= -_vertical_dead_zone) { + } else if (y <= dead_zone_bottom) { // Motion is backward. float throttle = - (max(y, -1.0) + _vertical_dead_zone) / - (-1.0 + _vertical_dead_zone); + (max(y, -1.0) - dead_zone_bottom) / + (-1.0 - dead_zone_bottom); _speed = -throttle * _reverse_speed; } // Now, what's our rotational velocity? This is based on the // mouse's horizontal position. - - if (x >= _horizontal_dead_zone) { + + float dead_zone_right = _horizontal_center + _horizontal_dead_zone; + float dead_zone_left = _horizontal_center - _horizontal_dead_zone; + + if (x >= dead_zone_right) { // Rotation is to the right. Compute the throttle value: the // ratio of the mouse pointer within the range of horizontal // movement. float throttle = - (min(x, 1.0) - _horizontal_dead_zone) / - (1.0 - _horizontal_dead_zone); + (min(x, 1.0) - dead_zone_right) / + (1.0 - dead_zone_right); _rot_speed = throttle * _rotate_speed; - } else if (x <= -_horizontal_dead_zone) { + } else if (x <= dead_zone_left) { // Rotation is to the left. float throttle = - (max(x, -1.0) + _horizontal_dead_zone) / - (-1.0 + _horizontal_dead_zone); + (max(x, -1.0) - dead_zone_left) / + (-1.0 - dead_zone_left); _rot_speed = -throttle * _rotate_speed; } diff --git a/panda/src/tform/driveInterface.h b/panda/src/tform/driveInterface.h index 7fae14e291..f8f8bb8596 100644 --- a/panda/src/tform/driveInterface.h +++ b/panda/src/tform/driveInterface.h @@ -98,6 +98,8 @@ private: float _rotate_speed; // degrees / sec, mouse all the way over float _vertical_dead_zone; // fraction of window size float _horizontal_dead_zone; // fraction of window size + float _vertical_center; // window units, 0 = center, -1 = bottom, 1 = top + float _horizontal_center; // window units, 0 = center, -1 = left, 1 = right // The time it takes to ramp up to full speed from a stop (or return // to a stop from full speed) when using the keyboard.