1
0
Fork 0

Patch from Andy Ross to allow virtual panel to tilt with mouse view:

OK, attached is a replacement for mouse.cxx that works the view using
the view-offset/tilt interface, rather than the (kinda odd) GuiQuat
stuff.  It's kind of a hack job, as I left the hooks to GuiQuat in in
other places for fear of breaking something.  Still, it removed more
code from mouse.cxx than it added, which has to count for some
elegance points.
This commit is contained in:
david 2002-03-06 13:53:18 +00:00
parent 0bdc1b1699
commit 9ae5ad236e

View file

@ -107,11 +107,6 @@ static int glut_active_alt = 0;
static int MOUSE_XSIZE = 0; static int MOUSE_XSIZE = 0;
static int MOUSE_YSIZE = 0; static int MOUSE_YSIZE = 0;
// uncomment this for view to exactly follow mouse in MOUSE_VIEW mode
// else smooth out the view panning to .01 radian per frame
// see view_offset smoothing mechanism in main.cxx
#define NO_SMOOTH_MOUSE_VIEW
// uncomment following to // uncomment following to
#define RESET_VIEW_ON_LEAVING_MOUSE_VIEW #define RESET_VIEW_ON_LEAVING_MOUSE_VIEW
@ -191,6 +186,20 @@ static inline float get_goal_view_offset() {
return globals->get_current_view()->get_goal_view_offset(); return globals->get_current_view()->get_goal_view_offset();
} }
static inline void set_goal_view_tilt( float tilt )
{
globals->get_current_view()->set_goal_view_tilt(tilt);
}
static inline void set_view_tilt( float tilt )
{
globals->get_current_view()->set_view_tilt(tilt);
}
static inline float get_view_tilt() {
return globals->get_current_view()->get_view_tilt();
}
static inline void move_brake(float offset) { static inline void move_brake(float offset) {
globals->get_controls()->move_brake(FGControls::ALL_WHEELS, offset); globals->get_controls()->move_brake(FGControls::ALL_WHEELS, offset);
} }
@ -416,19 +425,10 @@ void guiMotionFunc ( int x, int y )
case MOUSE_VIEW: case MOUSE_VIEW:
if( y <= 0 ) { if( y <= 0 ) {
#define CONTRAINED_MOUSE_VIEW_Y
#ifdef CONTRAINED_MOUSE_VIEW_Y
y = 1; y = 1;
#else
y = wh-2;
#endif // CONTRAINED_MOUSE_VIEW_Y
need_warp = 1; need_warp = 1;
} else if( y >= wh-1) { } else if( y >= wh-1) {
#ifdef CONTRAINED_MOUSE_VIEW_Y
y = wh-2; y = wh-2;
#else
y = 1;
#endif // CONTRAINED_MOUSE_VIEW_Y
need_warp = 1; need_warp = 1;
} }
// wrap MOUSE_VIEW mode cursor x position // wrap MOUSE_VIEW mode cursor x position
@ -439,49 +439,20 @@ void guiMotionFunc ( int x, int y )
need_warp = 1; need_warp = 1;
x = 1; x = 1;
} }
// try to get SGD_PI movement in each half of screen
// do spherical pan {
W = ww; float scale = SGD_PI / MOUSE_XSIZE;
H = wh; float dx = (_mX - x) * scale;
if( middle_button() ) { float dy = (_mY - y) * scale;
trackball(lastGuiQuat,
(2.0f * _mX - W) / W, float newOffset = get_view_offset() + dx;
0, //(H - 2.0f * y) / H, // 3 set_goal_view_offset(newOffset);
(2.0f * x - W) / W, set_view_offset(newOffset);
0 //(H - 2.0f * _mY) / H // 1
); float newTilt = get_view_tilt() + dy;
x = _mX; set_goal_view_tilt(newTilt);
y = _mY; set_view_tilt(newTilt);
need_warp = 1; }
} else {
trackball(lastGuiQuat,
0, //(2.0f * _mX - W) / W, // 0
(H - 2.0f * y) / H, // 3
0, //(2.0f * x - W) / W, // 2
(H - 2.0f * _mY) / H // 1
);
}
add_quats(lastGuiQuat, curGuiQuat, curGuiQuat);
build_rotmatrix(GuiQuat_mat, curGuiQuat);
// do horizontal pan
// this could be done in above quat
// but requires redoing view pipeline
offset = get_goal_view_offset();
offset += ((_mX - x) * SGD_2PI / W );
while (offset < 0.0) {
offset += SGD_2PI;
}
while (offset > SGD_2PI) {
offset -= SGD_2PI;
}
set_goal_view_offset(offset);
#ifdef NO_SMOOTH_MOUSE_VIEW
set_view_offset(offset);
#endif
break;
default:
break; break;
} }
} }