2001-01-08 20:55:16 +00:00
|
|
|
/**************************************************************************
|
|
|
|
* gui.cxx
|
|
|
|
*
|
|
|
|
* Written 1998 by Durk Talsma, started Juni, 1998. For the flight gear
|
|
|
|
* project.
|
|
|
|
*
|
|
|
|
* Additional mouse supported added by David Megginson, 1999.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License as
|
|
|
|
* published by the Free Software Foundation; either version 2 of the
|
|
|
|
* License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
*
|
|
|
|
* $Id$
|
|
|
|
**************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include <config.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <simgear/compiler.h>
|
|
|
|
|
2001-03-23 22:42:49 +00:00
|
|
|
#ifdef SG_MATH_EXCEPTION_CLASH
|
2001-01-08 20:55:16 +00:00
|
|
|
# include <math.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef HAVE_WINDOWS_H
|
|
|
|
# include <windows.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <GL/glut.h>
|
2001-05-15 22:30:39 +00:00
|
|
|
#include <GL/gl.h>
|
2001-01-08 20:55:16 +00:00
|
|
|
|
|
|
|
#if defined(FX) && defined(XMESA)
|
|
|
|
# include <GL/xmesa.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include STL_STRING
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include <simgear/constants.h>
|
|
|
|
#include <simgear/debug/logstream.hxx>
|
2001-03-25 14:20:12 +00:00
|
|
|
#include <simgear/misc/sg_path.hxx>
|
2001-01-08 20:55:16 +00:00
|
|
|
#include <simgear/screen/screen-dump.hxx>
|
|
|
|
|
|
|
|
#include <Include/general.hxx>
|
|
|
|
//#include <Include/fg_memory.h>
|
|
|
|
#include <Aircraft/aircraft.hxx>
|
|
|
|
#include <Airports/simple.hxx>
|
|
|
|
//#include <Autopilot/auto_gui.hxx>
|
|
|
|
#include <Autopilot/newauto.hxx>
|
|
|
|
#include <Cockpit/panel.hxx>
|
|
|
|
#include <Controls/controls.hxx>
|
|
|
|
#include <FDM/flight.hxx>
|
|
|
|
#include <Main/fg_init.hxx>
|
2001-01-13 22:06:39 +00:00
|
|
|
#include <Main/fg_props.hxx>
|
2001-07-22 19:51:16 +00:00
|
|
|
#include <Main/viewmgr.hxx>
|
2001-01-08 20:55:16 +00:00
|
|
|
|
|
|
|
#include "gui.h"
|
|
|
|
#include "gui_local.hxx"
|
|
|
|
|
2001-03-23 22:59:18 +00:00
|
|
|
SG_USING_STD(string);
|
2001-01-08 20:55:16 +00:00
|
|
|
|
2001-03-23 22:59:18 +00:00
|
|
|
#ifndef SG_HAVE_NATIVE_SGI_COMPILERS
|
|
|
|
SG_USING_STD(cout);
|
2001-01-08 20:55:16 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------
|
|
|
|
Mouse stuff
|
|
|
|
---------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
static int _mX = 0;
|
|
|
|
static int _mY = 0;
|
|
|
|
static int _savedX = 0;
|
|
|
|
static int _savedY = 0;
|
|
|
|
static int last_buttons = 0 ;
|
|
|
|
static int mouse_active = 0;
|
|
|
|
static int mouse_joystick_control = 0;
|
|
|
|
|
|
|
|
//static time_t mouse_off_time;
|
|
|
|
//static int mouse_timed_out;
|
|
|
|
|
|
|
|
// to allow returning to previous view
|
|
|
|
// on second left click in MOUSE_VIEW mode
|
|
|
|
// This has file scope so that it can be reset
|
|
|
|
// if the little rodent is moved NHV
|
2002-02-05 20:54:08 +00:00
|
|
|
static int _mVtoggle = 0;
|
2001-01-08 20:55:16 +00:00
|
|
|
|
|
|
|
// we break up the glutGetModifiers return mask
|
|
|
|
// once per loop and stash what we need in these
|
2002-02-05 20:54:08 +00:00
|
|
|
static int glut_active_shift = 0;
|
|
|
|
static int glut_active_ctrl = 0;
|
|
|
|
static int glut_active_alt = 0;
|
|
|
|
|
|
|
|
static int MOUSE_XSIZE = 0;
|
|
|
|
static int MOUSE_YSIZE = 0;
|
2001-01-08 20:55:16 +00:00
|
|
|
|
2002-03-06 15:54:25 +00:00
|
|
|
// 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
|
|
|
|
|
2001-01-08 20:55:16 +00:00
|
|
|
// uncomment following to
|
2001-07-16 04:44:49 +00:00
|
|
|
#define RESET_VIEW_ON_LEAVING_MOUSE_VIEW
|
2001-01-08 20:55:16 +00:00
|
|
|
|
|
|
|
/* --------------------------------------------------------------------
|
|
|
|
Support for mouse as control yoke (david@megginson.com)
|
|
|
|
|
|
|
|
- right button toggles between pointer and yoke
|
|
|
|
- horizontal drag with no buttons moves ailerons
|
|
|
|
- vertical drag with no buttons moves elevators
|
|
|
|
- horizontal drag with left button moves brakes (left=on)
|
|
|
|
- vertical drag with left button moves throttle (up=more)
|
|
|
|
- horizontal drag with middle button moves rudder
|
|
|
|
- vertical drag with middle button moves trim
|
|
|
|
|
|
|
|
For the *_sensitivity variables, a lower number means more sensitive.
|
|
|
|
|
|
|
|
TODO: figure out how to keep pointer from leaving window in yoke mode.
|
|
|
|
TODO: add thresholds and null zones
|
|
|
|
TODO: sensitivity should be configurable at user option.
|
|
|
|
TODO: allow differential braking (this will be useful if FlightGear
|
|
|
|
ever supports tail-draggers like the DC-3)
|
|
|
|
---------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
MouseMode mouse_mode = MOUSE_POINTER;
|
|
|
|
|
|
|
|
static double aileron_sensitivity = 1.0/500.0;
|
|
|
|
static double elevator_sensitivity = 1.0/500.0;
|
|
|
|
static double brake_sensitivity = 1.0/250.0;
|
|
|
|
static double throttle_sensitivity = 1.0/250.0;
|
|
|
|
static double rudder_sensitivity = 1.0/500.0;
|
|
|
|
static double trim_sensitivity = 1.0/1000.0;
|
|
|
|
|
2002-02-05 20:54:08 +00:00
|
|
|
void guiInitMouse(int width, int height)
|
|
|
|
{
|
|
|
|
MOUSE_XSIZE = width;
|
|
|
|
MOUSE_YSIZE = height;
|
|
|
|
}
|
|
|
|
|
2001-01-08 20:55:16 +00:00
|
|
|
static inline int guiGetMouseButton(void)
|
|
|
|
{
|
|
|
|
return last_buttons;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void guiGetMouse(int *x, int *y)
|
|
|
|
{
|
|
|
|
*x = _mX;
|
|
|
|
*y = _mY;
|
|
|
|
};
|
|
|
|
|
|
|
|
static inline int left_button( void ) {
|
|
|
|
return( last_buttons & (1 << GLUT_LEFT_BUTTON) );
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int middle_button( void ) {
|
|
|
|
return( last_buttons & (1 << GLUT_MIDDLE_BUTTON) );
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int right_button( void ) {
|
|
|
|
return( last_buttons & (1 << GLUT_RIGHT_BUTTON) );
|
|
|
|
}
|
|
|
|
|
2002-02-05 20:54:08 +00:00
|
|
|
static inline void set_goal_view_offset( float offset )
|
|
|
|
{
|
Major viewer-code overhaul from Jim Wilson:
Description:
This update includes the new viewer interface as proposed by David M. and
a first pass at cleaning up the viewer/view manager code by Jim W.
Note that I have dropped Main/viewer_lookat.?xx and Main/viewer_rph.?xx and
modified the Makefile.am accordingly.
Detail of work:
Overall:
The code reads a little easier. There are still some unnecessary bits in
there and I'd like to supplement the comments in the viewer.hxx with a tiny
bit on each interface group and what the groupings mean (similar but briefer
than what you emailed me the other day). I tried not to mess up the style,
but there is an occasional inconsistency. In general I wouldn't call it done
(especially since there's no tower yet! :)), but I'd like to get this out
there so others can comment, and test.
In Viewer:
The interface as you suggested has been implemented. Basically everything
seems to work as it did visually. There is no difference that I can see in
performance, although some things might be a tiny bit faster.
I've merged the lookat and rph (pilot view) code into the recalc for the
viewer. There is still some redundancy between the two, but a lot has been
removed. In some cases I've taken some code that we'd likely want to inline
anyway and left it in there in duplicate. You'll see that the code for both
looks a little cleaner. I need to take a closer look at the rotations in
particular. I've cleaned up a little there, but I suspect more can be done
to streamline this.
The external declaration to the Quat_mat in mouse.cxx has been removed. IMHO
the quat doesn't serve any intrinsic purpose in mouse.cxx, but I'm not about
to rip it out. It would seem that there more conventional ways to get
spherical data that are just as fast. In any case all the viewer was pulling
from the quat matrix was the pitch value so I modified mouse.cxx to output to
our pitchOffset input and that works fine.
I've changed the native values to degrees from radians where appropriate.
This required a conversion from degrees to radians in a couple modules that
access the interface. Perhaps we should add interface calls that do the
conversion, e.g. a getHeadingOffset_rad() to go along with the
getHeadingOffset_deg().
On the view_offset (now headingOffset) thing there are two entry points
because of the ability to instantly switch views or to scroll to a new view
angle (by hitting the numeric keys for example). This leaves an anomaly in
the interface which should be resolved by adding "goal" settings to the
interface, e.g. a setGoalHeadingOffset_deg(), setGoalPitchOffset_deg(), etc.
Other than these two issues, the next step here will be to look at some
further optimizations, and to write support code for a tower view. That
should be fairly simple at this point. I was considering creating a
"simulated tower view" or "pedestrian view" that defaulted to a position off
to the right of whereever the plane is at the moment you switch to the tower
view. This could be a fall back when we don't have an actual tower location
at hand (as would be the case with rural airports).
ViewManager:
Basically all I did here was neaten things up by ripping out excess crap and
made it compatible as is with the new interface.
The result is that viewmanager is now ready to be developed. The two
preexisting views are still hardcoded into the view manager. The next step
would be to design configuration xml (eg /sim/view[x]/config/blahblah) that
could be used to set up as many views as we want. If we want to take the easy
way out, we might want to insist that view[0] be a pilot-view and have
viewmanager check for that.
2002-03-20 17:43:28 +00:00
|
|
|
globals->get_current_view()->set_goal_view_offset(offset * SGD_RADIANS_TO_DEGREES);
|
2002-02-05 20:54:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void set_view_offset( float offset )
|
|
|
|
{
|
Major viewer-code overhaul from Jim Wilson:
Description:
This update includes the new viewer interface as proposed by David M. and
a first pass at cleaning up the viewer/view manager code by Jim W.
Note that I have dropped Main/viewer_lookat.?xx and Main/viewer_rph.?xx and
modified the Makefile.am accordingly.
Detail of work:
Overall:
The code reads a little easier. There are still some unnecessary bits in
there and I'd like to supplement the comments in the viewer.hxx with a tiny
bit on each interface group and what the groupings mean (similar but briefer
than what you emailed me the other day). I tried not to mess up the style,
but there is an occasional inconsistency. In general I wouldn't call it done
(especially since there's no tower yet! :)), but I'd like to get this out
there so others can comment, and test.
In Viewer:
The interface as you suggested has been implemented. Basically everything
seems to work as it did visually. There is no difference that I can see in
performance, although some things might be a tiny bit faster.
I've merged the lookat and rph (pilot view) code into the recalc for the
viewer. There is still some redundancy between the two, but a lot has been
removed. In some cases I've taken some code that we'd likely want to inline
anyway and left it in there in duplicate. You'll see that the code for both
looks a little cleaner. I need to take a closer look at the rotations in
particular. I've cleaned up a little there, but I suspect more can be done
to streamline this.
The external declaration to the Quat_mat in mouse.cxx has been removed. IMHO
the quat doesn't serve any intrinsic purpose in mouse.cxx, but I'm not about
to rip it out. It would seem that there more conventional ways to get
spherical data that are just as fast. In any case all the viewer was pulling
from the quat matrix was the pitch value so I modified mouse.cxx to output to
our pitchOffset input and that works fine.
I've changed the native values to degrees from radians where appropriate.
This required a conversion from degrees to radians in a couple modules that
access the interface. Perhaps we should add interface calls that do the
conversion, e.g. a getHeadingOffset_rad() to go along with the
getHeadingOffset_deg().
On the view_offset (now headingOffset) thing there are two entry points
because of the ability to instantly switch views or to scroll to a new view
angle (by hitting the numeric keys for example). This leaves an anomaly in
the interface which should be resolved by adding "goal" settings to the
interface, e.g. a setGoalHeadingOffset_deg(), setGoalPitchOffset_deg(), etc.
Other than these two issues, the next step here will be to look at some
further optimizations, and to write support code for a tower view. That
should be fairly simple at this point. I was considering creating a
"simulated tower view" or "pedestrian view" that defaulted to a position off
to the right of whereever the plane is at the moment you switch to the tower
view. This could be a fall back when we don't have an actual tower location
at hand (as would be the case with rural airports).
ViewManager:
Basically all I did here was neaten things up by ripping out excess crap and
made it compatible as is with the new interface.
The result is that viewmanager is now ready to be developed. The two
preexisting views are still hardcoded into the view manager. The next step
would be to design configuration xml (eg /sim/view[x]/config/blahblah) that
could be used to set up as many views as we want. If we want to take the easy
way out, we might want to insist that view[0] be a pilot-view and have
viewmanager check for that.
2002-03-20 17:43:28 +00:00
|
|
|
globals->get_current_view()->setHeadingOffset_deg(offset * SGD_RADIANS_TO_DEGREES);
|
|
|
|
}
|
|
|
|
|
|
|
|
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()->setPitchOffset_deg(tilt);
|
2002-02-05 20:54:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline float get_view_offset() {
|
Major viewer-code overhaul from Jim Wilson:
Description:
This update includes the new viewer interface as proposed by David M. and
a first pass at cleaning up the viewer/view manager code by Jim W.
Note that I have dropped Main/viewer_lookat.?xx and Main/viewer_rph.?xx and
modified the Makefile.am accordingly.
Detail of work:
Overall:
The code reads a little easier. There are still some unnecessary bits in
there and I'd like to supplement the comments in the viewer.hxx with a tiny
bit on each interface group and what the groupings mean (similar but briefer
than what you emailed me the other day). I tried not to mess up the style,
but there is an occasional inconsistency. In general I wouldn't call it done
(especially since there's no tower yet! :)), but I'd like to get this out
there so others can comment, and test.
In Viewer:
The interface as you suggested has been implemented. Basically everything
seems to work as it did visually. There is no difference that I can see in
performance, although some things might be a tiny bit faster.
I've merged the lookat and rph (pilot view) code into the recalc for the
viewer. There is still some redundancy between the two, but a lot has been
removed. In some cases I've taken some code that we'd likely want to inline
anyway and left it in there in duplicate. You'll see that the code for both
looks a little cleaner. I need to take a closer look at the rotations in
particular. I've cleaned up a little there, but I suspect more can be done
to streamline this.
The external declaration to the Quat_mat in mouse.cxx has been removed. IMHO
the quat doesn't serve any intrinsic purpose in mouse.cxx, but I'm not about
to rip it out. It would seem that there more conventional ways to get
spherical data that are just as fast. In any case all the viewer was pulling
from the quat matrix was the pitch value so I modified mouse.cxx to output to
our pitchOffset input and that works fine.
I've changed the native values to degrees from radians where appropriate.
This required a conversion from degrees to radians in a couple modules that
access the interface. Perhaps we should add interface calls that do the
conversion, e.g. a getHeadingOffset_rad() to go along with the
getHeadingOffset_deg().
On the view_offset (now headingOffset) thing there are two entry points
because of the ability to instantly switch views or to scroll to a new view
angle (by hitting the numeric keys for example). This leaves an anomaly in
the interface which should be resolved by adding "goal" settings to the
interface, e.g. a setGoalHeadingOffset_deg(), setGoalPitchOffset_deg(), etc.
Other than these two issues, the next step here will be to look at some
further optimizations, and to write support code for a tower view. That
should be fairly simple at this point. I was considering creating a
"simulated tower view" or "pedestrian view" that defaulted to a position off
to the right of whereever the plane is at the moment you switch to the tower
view. This could be a fall back when we don't have an actual tower location
at hand (as would be the case with rural airports).
ViewManager:
Basically all I did here was neaten things up by ripping out excess crap and
made it compatible as is with the new interface.
The result is that viewmanager is now ready to be developed. The two
preexisting views are still hardcoded into the view manager. The next step
would be to design configuration xml (eg /sim/view[x]/config/blahblah) that
could be used to set up as many views as we want. If we want to take the easy
way out, we might want to insist that view[0] be a pilot-view and have
viewmanager check for that.
2002-03-20 17:43:28 +00:00
|
|
|
return globals->get_current_view()->getHeadingOffset_deg() * SGD_DEGREES_TO_RADIANS;
|
2002-02-05 20:54:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline float get_goal_view_offset() {
|
Major viewer-code overhaul from Jim Wilson:
Description:
This update includes the new viewer interface as proposed by David M. and
a first pass at cleaning up the viewer/view manager code by Jim W.
Note that I have dropped Main/viewer_lookat.?xx and Main/viewer_rph.?xx and
modified the Makefile.am accordingly.
Detail of work:
Overall:
The code reads a little easier. There are still some unnecessary bits in
there and I'd like to supplement the comments in the viewer.hxx with a tiny
bit on each interface group and what the groupings mean (similar but briefer
than what you emailed me the other day). I tried not to mess up the style,
but there is an occasional inconsistency. In general I wouldn't call it done
(especially since there's no tower yet! :)), but I'd like to get this out
there so others can comment, and test.
In Viewer:
The interface as you suggested has been implemented. Basically everything
seems to work as it did visually. There is no difference that I can see in
performance, although some things might be a tiny bit faster.
I've merged the lookat and rph (pilot view) code into the recalc for the
viewer. There is still some redundancy between the two, but a lot has been
removed. In some cases I've taken some code that we'd likely want to inline
anyway and left it in there in duplicate. You'll see that the code for both
looks a little cleaner. I need to take a closer look at the rotations in
particular. I've cleaned up a little there, but I suspect more can be done
to streamline this.
The external declaration to the Quat_mat in mouse.cxx has been removed. IMHO
the quat doesn't serve any intrinsic purpose in mouse.cxx, but I'm not about
to rip it out. It would seem that there more conventional ways to get
spherical data that are just as fast. In any case all the viewer was pulling
from the quat matrix was the pitch value so I modified mouse.cxx to output to
our pitchOffset input and that works fine.
I've changed the native values to degrees from radians where appropriate.
This required a conversion from degrees to radians in a couple modules that
access the interface. Perhaps we should add interface calls that do the
conversion, e.g. a getHeadingOffset_rad() to go along with the
getHeadingOffset_deg().
On the view_offset (now headingOffset) thing there are two entry points
because of the ability to instantly switch views or to scroll to a new view
angle (by hitting the numeric keys for example). This leaves an anomaly in
the interface which should be resolved by adding "goal" settings to the
interface, e.g. a setGoalHeadingOffset_deg(), setGoalPitchOffset_deg(), etc.
Other than these two issues, the next step here will be to look at some
further optimizations, and to write support code for a tower view. That
should be fairly simple at this point. I was considering creating a
"simulated tower view" or "pedestrian view" that defaulted to a position off
to the right of whereever the plane is at the moment you switch to the tower
view. This could be a fall back when we don't have an actual tower location
at hand (as would be the case with rural airports).
ViewManager:
Basically all I did here was neaten things up by ripping out excess crap and
made it compatible as is with the new interface.
The result is that viewmanager is now ready to be developed. The two
preexisting views are still hardcoded into the view manager. The next step
would be to design configuration xml (eg /sim/view[x]/config/blahblah) that
could be used to set up as many views as we want. If we want to take the easy
way out, we might want to insist that view[0] be a pilot-view and have
viewmanager check for that.
2002-03-20 17:43:28 +00:00
|
|
|
return globals->get_current_view()->get_goal_view_offset() * SGD_DEGREES_TO_RADIANS;
|
2002-02-05 20:54:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void move_brake(float offset) {
|
|
|
|
globals->get_controls()->move_brake(FGControls::ALL_WHEELS, offset);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void move_throttle(float offset) {
|
|
|
|
globals->get_controls()->move_throttle(FGControls::ALL_ENGINES, offset);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void move_rudder(float offset) {
|
|
|
|
globals->get_controls()->move_rudder(offset);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void move_elevator_trim(float offset) {
|
|
|
|
globals->get_controls()->move_elevator_trim(offset);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void move_aileron(float offset) {
|
|
|
|
globals->get_controls()->move_aileron(offset);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void move_elevator(float offset) {
|
|
|
|
globals->get_controls()->move_elevator(offset);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline float get_aileron() {
|
|
|
|
return globals->get_controls()->get_aileron();
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline float get_elevator() {
|
|
|
|
return globals->get_controls()->get_elevator();
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline bool AP_HeadingEnabled() {
|
2002-03-13 16:31:21 +00:00
|
|
|
return globals->get_autopilot()->get_HeadingEnabled();
|
2002-02-05 20:54:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline bool AP_AltitudeEnabled() {
|
2002-03-13 16:31:21 +00:00
|
|
|
return globals->get_autopilot()->get_AltitudeEnabled();
|
2002-02-05 20:54:08 +00:00
|
|
|
}
|
|
|
|
|
2001-01-08 20:55:16 +00:00
|
|
|
void TurnCursorOn( void )
|
|
|
|
{
|
|
|
|
mouse_active = ~0;
|
2001-11-12 19:37:23 +00:00
|
|
|
#if defined(WIN32)
|
2001-01-08 20:55:16 +00:00
|
|
|
switch (mouse_mode) {
|
|
|
|
case MOUSE_POINTER:
|
|
|
|
glutSetCursor(GLUT_CURSOR_INHERIT);
|
|
|
|
break;
|
|
|
|
case MOUSE_YOKE:
|
|
|
|
glutSetCursor(GLUT_CURSOR_CROSSHAIR);
|
|
|
|
break;
|
|
|
|
case MOUSE_VIEW:
|
|
|
|
glutSetCursor(GLUT_CURSOR_LEFT_RIGHT);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#if defined(X_CURSOR_TWEAKS)
|
2002-02-05 20:54:08 +00:00
|
|
|
glutWarpPointer( MOUSE_XSIZE/2,
|
|
|
|
MOUSE_YSIZE/2);
|
2001-01-08 20:55:16 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void TurnCursorOff( void )
|
|
|
|
{
|
|
|
|
mouse_active = 0;
|
|
|
|
#if defined(WIN32_CURSOR_TWEAKS)
|
|
|
|
glutSetCursor(GLUT_CURSOR_NONE);
|
|
|
|
#elif defined(X_CURSOR_TWEAKS)
|
2002-02-05 20:54:08 +00:00
|
|
|
glutWarpPointer( MOUSE_XSIZE,
|
|
|
|
MOUSE_YSIZE);
|
2001-01-08 20:55:16 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void maybeToggleMouse( void )
|
|
|
|
{
|
2001-11-12 20:57:08 +00:00
|
|
|
#if defined(WIN32_CURSOR_TWEAKS_OFF)
|
2001-01-08 20:55:16 +00:00
|
|
|
static int first_time = ~0;
|
|
|
|
static int mouse_changed = 0;
|
|
|
|
|
|
|
|
if ( first_time ) {
|
|
|
|
if(!mouse_active) {
|
|
|
|
mouse_changed = ~mouse_changed;
|
|
|
|
TurnCursorOn();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if( mouse_mode != MOUSE_POINTER )
|
|
|
|
return;
|
|
|
|
if( mouse_changed ) {
|
|
|
|
mouse_changed = ~mouse_changed;
|
|
|
|
if(mouse_active) {
|
|
|
|
TurnCursorOff();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
first_time = ~first_time;
|
|
|
|
#endif // #ifdef WIN32
|
|
|
|
}
|
|
|
|
|
|
|
|
// Call with FALSE to init and TRUE to restore
|
|
|
|
void BusyCursor( int restore )
|
|
|
|
{
|
|
|
|
static GLenum cursor = (GLenum) 0;
|
|
|
|
if( restore ) {
|
|
|
|
glutSetCursor(cursor);
|
|
|
|
} else {
|
|
|
|
cursor = (GLenum) glutGet( (GLenum) GLUT_WINDOW_CURSOR );
|
|
|
|
#if defined(WIN32_CURSOR_TWEAKS)
|
|
|
|
TurnCursorOn();
|
|
|
|
#endif
|
|
|
|
glutSetCursor( GLUT_CURSOR_WAIT );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Center the view offsets
|
|
|
|
void CenterView( void ) {
|
2001-03-21 23:10:15 +00:00
|
|
|
if( mouse_mode == MOUSE_VIEW ) {
|
2001-01-08 20:55:16 +00:00
|
|
|
mouse_mode = MOUSE_POINTER;
|
2002-02-05 20:54:08 +00:00
|
|
|
_savedX = MOUSE_XSIZE/2;
|
|
|
|
_savedY = MOUSE_YSIZE/2;
|
2001-01-08 20:55:16 +00:00
|
|
|
_mVtoggle = 0;
|
|
|
|
Quat0();
|
|
|
|
build_rotmatrix(GuiQuat_mat, curGuiQuat);
|
|
|
|
glutSetCursor(GLUT_CURSOR_INHERIT);
|
|
|
|
|
|
|
|
// Is this necessary ??
|
|
|
|
if( !gui_menu_on ) TurnCursorOff();
|
|
|
|
|
|
|
|
glutWarpPointer( _savedX, _savedY );
|
|
|
|
}
|
2002-02-05 20:54:08 +00:00
|
|
|
set_goal_view_offset(0.0);
|
|
|
|
set_view_offset(0.0);
|
2001-01-08 20:55:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-02-05 20:54:08 +00:00
|
|
|
//#define TRANSLATE_HUD
|
|
|
|
// temporary hack until pitch_offset is added to view pipeline
|
|
|
|
void fgTranslateHud( void ) {
|
|
|
|
#ifdef TRANSLATE_HUD
|
|
|
|
if(mouse_mode == MOUSE_VIEW) {
|
|
|
|
|
|
|
|
int ww = MOUSE_XSIZE;
|
|
|
|
int wh = MOUSE_YSIZE;
|
|
|
|
|
|
|
|
float y = 4*(_mY-(wh/2));// * ((wh/SGD_PI)*SG_RADIANS_TO_DEGREES);
|
|
|
|
|
|
|
|
float x = get_view_offset() * SG_RADIANS_TO_DEGREES;
|
|
|
|
|
|
|
|
if( x < -180 ) x += 360;
|
|
|
|
else if( x > 180 ) x -= 360;
|
|
|
|
|
|
|
|
x *= ww/90.0;
|
|
|
|
// x *= ww/180.0;
|
|
|
|
// x *= ww/360.0;
|
|
|
|
|
|
|
|
// glTranslatef( x*ww/640, y*wh/480, 0 );
|
|
|
|
glTranslatef( x*640/ww, y*480/wh, 0 );
|
|
|
|
}
|
|
|
|
#endif // TRANSLATE_HUD
|
|
|
|
}
|
|
|
|
|
2001-01-08 20:55:16 +00:00
|
|
|
void guiMotionFunc ( int x, int y )
|
|
|
|
{
|
|
|
|
int ww, wh, need_warp = 0;
|
|
|
|
float W, H;
|
|
|
|
double offset;
|
|
|
|
|
2002-02-05 20:54:08 +00:00
|
|
|
ww = MOUSE_XSIZE;
|
|
|
|
wh = MOUSE_YSIZE;
|
2001-11-12 20:57:08 +00:00
|
|
|
|
2001-01-08 20:55:16 +00:00
|
|
|
if (mouse_mode == MOUSE_POINTER) {
|
2001-11-12 20:57:08 +00:00
|
|
|
// TURN MENU ON IF MOUSE AT TOP
|
2002-02-05 20:54:08 +00:00
|
|
|
if( y < 1 ) {
|
2001-11-12 20:57:08 +00:00
|
|
|
if( !gui_menu_on )
|
|
|
|
guiToggleMenu();
|
|
|
|
}
|
|
|
|
// TURN MENU OFF IF MOUSE AT BOTTOM
|
2002-02-05 20:54:08 +00:00
|
|
|
else if( y > wh-2 ) {
|
2001-11-12 20:57:08 +00:00
|
|
|
if( gui_menu_on )
|
|
|
|
guiToggleMenu();
|
|
|
|
}
|
2002-02-08 17:18:50 +00:00
|
|
|
puMouse ( x, y ) ;
|
2001-01-08 20:55:16 +00:00
|
|
|
glutPostRedisplay () ;
|
|
|
|
} else {
|
|
|
|
if( x == _mX && y == _mY)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// reset left click MOUSE_VIEW toggle feature
|
|
|
|
_mVtoggle = 0;
|
|
|
|
|
|
|
|
switch (mouse_mode) {
|
|
|
|
case MOUSE_YOKE:
|
|
|
|
if( !mouse_joystick_control ) {
|
|
|
|
mouse_joystick_control = 1;
|
2001-01-13 22:06:39 +00:00
|
|
|
fgSetString("/sim/control-mode", "mouse");
|
2001-01-08 20:55:16 +00:00
|
|
|
} else {
|
|
|
|
if ( left_button() ) {
|
2002-02-05 20:54:08 +00:00
|
|
|
move_brake( (_mX - x) * brake_sensitivity);
|
|
|
|
move_throttle((_mY - y) * throttle_sensitivity);
|
2001-01-08 20:55:16 +00:00
|
|
|
} else if ( right_button() ) {
|
2002-02-05 20:54:08 +00:00
|
|
|
if( ! AP_HeadingEnabled() ) {
|
|
|
|
move_rudder((x - _mX) * rudder_sensitivity);
|
2001-01-08 20:55:16 +00:00
|
|
|
}
|
2002-02-05 20:54:08 +00:00
|
|
|
if( ! AP_AltitudeEnabled() ) {
|
|
|
|
move_elevator_trim((_mY - y) * trim_sensitivity);
|
2001-01-08 20:55:16 +00:00
|
|
|
}
|
|
|
|
} else {
|
2002-02-05 20:54:08 +00:00
|
|
|
if( ! AP_HeadingEnabled() ) {
|
|
|
|
move_aileron((x - _mX) * aileron_sensitivity);
|
2001-01-08 20:55:16 +00:00
|
|
|
}
|
2002-02-05 20:54:08 +00:00
|
|
|
if( ! AP_AltitudeEnabled() ) {
|
|
|
|
move_elevator((_mY - y) * elevator_sensitivity);
|
2001-01-08 20:55:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Keep the mouse in the window.
|
|
|
|
if (x < 5 || x > ww-5 || y < 5 || y > wh-5) {
|
|
|
|
x = ww / 2;
|
|
|
|
y = wh / 2;
|
|
|
|
need_warp = 1;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MOUSE_VIEW:
|
|
|
|
if( y <= 0 ) {
|
2002-03-06 15:54:25 +00:00
|
|
|
#define CONTRAINED_MOUSE_VIEW_Y
|
|
|
|
#ifdef CONTRAINED_MOUSE_VIEW_Y
|
2001-01-08 20:55:16 +00:00
|
|
|
y = 1;
|
2002-03-06 15:54:25 +00:00
|
|
|
#else
|
|
|
|
y = wh-2;
|
|
|
|
#endif // CONTRAINED_MOUSE_VIEW_Y
|
2001-01-08 20:55:16 +00:00
|
|
|
need_warp = 1;
|
|
|
|
} else if( y >= wh-1) {
|
2002-03-06 15:54:25 +00:00
|
|
|
#ifdef CONTRAINED_MOUSE_VIEW_Y
|
2001-01-08 20:55:16 +00:00
|
|
|
y = wh-2;
|
2002-03-06 15:54:25 +00:00
|
|
|
#else
|
|
|
|
y = 1;
|
|
|
|
#endif // CONTRAINED_MOUSE_VIEW_Y
|
2001-01-08 20:55:16 +00:00
|
|
|
need_warp = 1;
|
|
|
|
}
|
|
|
|
// wrap MOUSE_VIEW mode cursor x position
|
|
|
|
if ( x <= 0 ) {
|
|
|
|
need_warp = 1;
|
|
|
|
x = ww-2;
|
|
|
|
} else if ( x >= ww-1 ) {
|
|
|
|
need_warp = 1;
|
|
|
|
x = 1;
|
|
|
|
}
|
2002-03-06 15:54:25 +00:00
|
|
|
// try to get SGD_PI movement in each half of screen
|
|
|
|
// do spherical pan
|
|
|
|
W = ww;
|
|
|
|
H = wh;
|
|
|
|
if( middle_button() ) {
|
|
|
|
trackball(lastGuiQuat,
|
|
|
|
(2.0f * _mX - W) / W,
|
|
|
|
0, //(H - 2.0f * y) / H, // 3
|
|
|
|
(2.0f * x - W) / W,
|
|
|
|
0 //(H - 2.0f * _mY) / H // 1
|
|
|
|
);
|
|
|
|
x = _mX;
|
|
|
|
y = _mY;
|
|
|
|
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);
|
Major viewer-code overhaul from Jim Wilson:
Description:
This update includes the new viewer interface as proposed by David M. and
a first pass at cleaning up the viewer/view manager code by Jim W.
Note that I have dropped Main/viewer_lookat.?xx and Main/viewer_rph.?xx and
modified the Makefile.am accordingly.
Detail of work:
Overall:
The code reads a little easier. There are still some unnecessary bits in
there and I'd like to supplement the comments in the viewer.hxx with a tiny
bit on each interface group and what the groupings mean (similar but briefer
than what you emailed me the other day). I tried not to mess up the style,
but there is an occasional inconsistency. In general I wouldn't call it done
(especially since there's no tower yet! :)), but I'd like to get this out
there so others can comment, and test.
In Viewer:
The interface as you suggested has been implemented. Basically everything
seems to work as it did visually. There is no difference that I can see in
performance, although some things might be a tiny bit faster.
I've merged the lookat and rph (pilot view) code into the recalc for the
viewer. There is still some redundancy between the two, but a lot has been
removed. In some cases I've taken some code that we'd likely want to inline
anyway and left it in there in duplicate. You'll see that the code for both
looks a little cleaner. I need to take a closer look at the rotations in
particular. I've cleaned up a little there, but I suspect more can be done
to streamline this.
The external declaration to the Quat_mat in mouse.cxx has been removed. IMHO
the quat doesn't serve any intrinsic purpose in mouse.cxx, but I'm not about
to rip it out. It would seem that there more conventional ways to get
spherical data that are just as fast. In any case all the viewer was pulling
from the quat matrix was the pitch value so I modified mouse.cxx to output to
our pitchOffset input and that works fine.
I've changed the native values to degrees from radians where appropriate.
This required a conversion from degrees to radians in a couple modules that
access the interface. Perhaps we should add interface calls that do the
conversion, e.g. a getHeadingOffset_rad() to go along with the
getHeadingOffset_deg().
On the view_offset (now headingOffset) thing there are two entry points
because of the ability to instantly switch views or to scroll to a new view
angle (by hitting the numeric keys for example). This leaves an anomaly in
the interface which should be resolved by adding "goal" settings to the
interface, e.g. a setGoalHeadingOffset_deg(), setGoalPitchOffset_deg(), etc.
Other than these two issues, the next step here will be to look at some
further optimizations, and to write support code for a tower view. That
should be fairly simple at this point. I was considering creating a
"simulated tower view" or "pedestrian view" that defaulted to a position off
to the right of whereever the plane is at the moment you switch to the tower
view. This could be a fall back when we don't have an actual tower location
at hand (as would be the case with rural airports).
ViewManager:
Basically all I did here was neaten things up by ripping out excess crap and
made it compatible as is with the new interface.
The result is that viewmanager is now ready to be developed. The two
preexisting views are still hardcoded into the view manager. The next step
would be to design configuration xml (eg /sim/view[x]/config/blahblah) that
could be used to set up as many views as we want. If we want to take the easy
way out, we might want to insist that view[0] be a pilot-view and have
viewmanager check for that.
2002-03-20 17:43:28 +00:00
|
|
|
set_goal_view_tilt(asin( GuiQuat_mat[1][2]) * SGD_RADIANS_TO_DEGREES );
|
2002-03-06 15:54:25 +00:00
|
|
|
#ifdef NO_SMOOTH_MOUSE_VIEW
|
|
|
|
set_view_offset(offset);
|
Major viewer-code overhaul from Jim Wilson:
Description:
This update includes the new viewer interface as proposed by David M. and
a first pass at cleaning up the viewer/view manager code by Jim W.
Note that I have dropped Main/viewer_lookat.?xx and Main/viewer_rph.?xx and
modified the Makefile.am accordingly.
Detail of work:
Overall:
The code reads a little easier. There are still some unnecessary bits in
there and I'd like to supplement the comments in the viewer.hxx with a tiny
bit on each interface group and what the groupings mean (similar but briefer
than what you emailed me the other day). I tried not to mess up the style,
but there is an occasional inconsistency. In general I wouldn't call it done
(especially since there's no tower yet! :)), but I'd like to get this out
there so others can comment, and test.
In Viewer:
The interface as you suggested has been implemented. Basically everything
seems to work as it did visually. There is no difference that I can see in
performance, although some things might be a tiny bit faster.
I've merged the lookat and rph (pilot view) code into the recalc for the
viewer. There is still some redundancy between the two, but a lot has been
removed. In some cases I've taken some code that we'd likely want to inline
anyway and left it in there in duplicate. You'll see that the code for both
looks a little cleaner. I need to take a closer look at the rotations in
particular. I've cleaned up a little there, but I suspect more can be done
to streamline this.
The external declaration to the Quat_mat in mouse.cxx has been removed. IMHO
the quat doesn't serve any intrinsic purpose in mouse.cxx, but I'm not about
to rip it out. It would seem that there more conventional ways to get
spherical data that are just as fast. In any case all the viewer was pulling
from the quat matrix was the pitch value so I modified mouse.cxx to output to
our pitchOffset input and that works fine.
I've changed the native values to degrees from radians where appropriate.
This required a conversion from degrees to radians in a couple modules that
access the interface. Perhaps we should add interface calls that do the
conversion, e.g. a getHeadingOffset_rad() to go along with the
getHeadingOffset_deg().
On the view_offset (now headingOffset) thing there are two entry points
because of the ability to instantly switch views or to scroll to a new view
angle (by hitting the numeric keys for example). This leaves an anomaly in
the interface which should be resolved by adding "goal" settings to the
interface, e.g. a setGoalHeadingOffset_deg(), setGoalPitchOffset_deg(), etc.
Other than these two issues, the next step here will be to look at some
further optimizations, and to write support code for a tower view. That
should be fairly simple at this point. I was considering creating a
"simulated tower view" or "pedestrian view" that defaulted to a position off
to the right of whereever the plane is at the moment you switch to the tower
view. This could be a fall back when we don't have an actual tower location
at hand (as would be the case with rural airports).
ViewManager:
Basically all I did here was neaten things up by ripping out excess crap and
made it compatible as is with the new interface.
The result is that viewmanager is now ready to be developed. The two
preexisting views are still hardcoded into the view manager. The next step
would be to design configuration xml (eg /sim/view[x]/config/blahblah) that
could be used to set up as many views as we want. If we want to take the easy
way out, we might want to insist that view[0] be a pilot-view and have
viewmanager check for that.
2002-03-20 17:43:28 +00:00
|
|
|
set_view_tilt(asin( GuiQuat_mat[1][2]) * SGD_RADIANS_TO_DEGREES );
|
2002-03-06 15:54:25 +00:00
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2001-01-08 20:55:16 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if( need_warp)
|
|
|
|
glutWarpPointer(x, y);
|
|
|
|
|
|
|
|
// Record the new mouse position.
|
|
|
|
_mX = x;
|
|
|
|
_mY = y;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void guiMouseFunc(int button, int updown, int x, int y)
|
|
|
|
{
|
|
|
|
int glutModifiers;
|
|
|
|
|
|
|
|
// private MOUSE_VIEW state variables
|
|
|
|
// to allow alternate left clicks in MOUSE_VIEW mode
|
|
|
|
// to toggle between current offsets and straight ahead
|
|
|
|
// uses _mVtoggle
|
|
|
|
static int _mVx, _mVy, _Vx, _Vy;
|
|
|
|
static float _quat[4];
|
|
|
|
static double _view_offset;
|
|
|
|
|
|
|
|
// general purpose variables
|
|
|
|
double offset;
|
|
|
|
|
|
|
|
glutModifiers = glutGetModifiers();
|
|
|
|
glut_active_shift = glutModifiers & GLUT_ACTIVE_SHIFT;
|
|
|
|
glut_active_ctrl = glutModifiers & GLUT_ACTIVE_CTRL;
|
|
|
|
glut_active_alt = glutModifiers & GLUT_ACTIVE_ALT;
|
|
|
|
|
|
|
|
// Was the left button pressed?
|
|
|
|
if (updown == GLUT_DOWN ) {
|
|
|
|
if( button == GLUT_LEFT_BUTTON)
|
|
|
|
{
|
|
|
|
switch (mouse_mode) {
|
|
|
|
case MOUSE_POINTER:
|
|
|
|
break;
|
|
|
|
case MOUSE_YOKE:
|
|
|
|
break;
|
|
|
|
case MOUSE_VIEW:
|
|
|
|
if(_mVtoggle) {
|
|
|
|
// resume previous view offsets
|
|
|
|
_mX = _mVx;
|
|
|
|
_mY = _mVy;
|
|
|
|
x = _Vx;
|
|
|
|
y = _Vy;
|
2002-02-05 20:54:08 +00:00
|
|
|
sgCopyVec4(curGuiQuat, _quat);
|
|
|
|
set_goal_view_offset(_view_offset);
|
Major viewer-code overhaul from Jim Wilson:
Description:
This update includes the new viewer interface as proposed by David M. and
a first pass at cleaning up the viewer/view manager code by Jim W.
Note that I have dropped Main/viewer_lookat.?xx and Main/viewer_rph.?xx and
modified the Makefile.am accordingly.
Detail of work:
Overall:
The code reads a little easier. There are still some unnecessary bits in
there and I'd like to supplement the comments in the viewer.hxx with a tiny
bit on each interface group and what the groupings mean (similar but briefer
than what you emailed me the other day). I tried not to mess up the style,
but there is an occasional inconsistency. In general I wouldn't call it done
(especially since there's no tower yet! :)), but I'd like to get this out
there so others can comment, and test.
In Viewer:
The interface as you suggested has been implemented. Basically everything
seems to work as it did visually. There is no difference that I can see in
performance, although some things might be a tiny bit faster.
I've merged the lookat and rph (pilot view) code into the recalc for the
viewer. There is still some redundancy between the two, but a lot has been
removed. In some cases I've taken some code that we'd likely want to inline
anyway and left it in there in duplicate. You'll see that the code for both
looks a little cleaner. I need to take a closer look at the rotations in
particular. I've cleaned up a little there, but I suspect more can be done
to streamline this.
The external declaration to the Quat_mat in mouse.cxx has been removed. IMHO
the quat doesn't serve any intrinsic purpose in mouse.cxx, but I'm not about
to rip it out. It would seem that there more conventional ways to get
spherical data that are just as fast. In any case all the viewer was pulling
from the quat matrix was the pitch value so I modified mouse.cxx to output to
our pitchOffset input and that works fine.
I've changed the native values to degrees from radians where appropriate.
This required a conversion from degrees to radians in a couple modules that
access the interface. Perhaps we should add interface calls that do the
conversion, e.g. a getHeadingOffset_rad() to go along with the
getHeadingOffset_deg().
On the view_offset (now headingOffset) thing there are two entry points
because of the ability to instantly switch views or to scroll to a new view
angle (by hitting the numeric keys for example). This leaves an anomaly in
the interface which should be resolved by adding "goal" settings to the
interface, e.g. a setGoalHeadingOffset_deg(), setGoalPitchOffset_deg(), etc.
Other than these two issues, the next step here will be to look at some
further optimizations, and to write support code for a tower view. That
should be fairly simple at this point. I was considering creating a
"simulated tower view" or "pedestrian view" that defaulted to a position off
to the right of whereever the plane is at the moment you switch to the tower
view. This could be a fall back when we don't have an actual tower location
at hand (as would be the case with rural airports).
ViewManager:
Basically all I did here was neaten things up by ripping out excess crap and
made it compatible as is with the new interface.
The result is that viewmanager is now ready to be developed. The two
preexisting views are still hardcoded into the view manager. The next step
would be to design configuration xml (eg /sim/view[x]/config/blahblah) that
could be used to set up as many views as we want. If we want to take the easy
way out, we might want to insist that view[0] be a pilot-view and have
viewmanager check for that.
2002-03-20 17:43:28 +00:00
|
|
|
set_goal_view_tilt(0.0);
|
2001-01-08 20:55:16 +00:00
|
|
|
#ifdef NO_SMOOTH_MOUSE_VIEW
|
2002-02-05 20:54:08 +00:00
|
|
|
set_view_offset(_view_offset);
|
2001-01-08 20:55:16 +00:00
|
|
|
#endif
|
|
|
|
} else {
|
|
|
|
// center view
|
|
|
|
_mVx = _mX;
|
|
|
|
_mVy = _mY;
|
|
|
|
_Vx = x;
|
|
|
|
_Vy = y;
|
2002-02-05 20:54:08 +00:00
|
|
|
sgCopyVec4(_quat,curGuiQuat);
|
|
|
|
x = MOUSE_XSIZE/2;
|
|
|
|
y = MOUSE_YSIZE/2;
|
2001-01-08 20:55:16 +00:00
|
|
|
Quat0();
|
2002-02-05 20:54:08 +00:00
|
|
|
_view_offset = get_goal_view_offset();
|
|
|
|
set_goal_view_offset(0.0);
|
Major viewer-code overhaul from Jim Wilson:
Description:
This update includes the new viewer interface as proposed by David M. and
a first pass at cleaning up the viewer/view manager code by Jim W.
Note that I have dropped Main/viewer_lookat.?xx and Main/viewer_rph.?xx and
modified the Makefile.am accordingly.
Detail of work:
Overall:
The code reads a little easier. There are still some unnecessary bits in
there and I'd like to supplement the comments in the viewer.hxx with a tiny
bit on each interface group and what the groupings mean (similar but briefer
than what you emailed me the other day). I tried not to mess up the style,
but there is an occasional inconsistency. In general I wouldn't call it done
(especially since there's no tower yet! :)), but I'd like to get this out
there so others can comment, and test.
In Viewer:
The interface as you suggested has been implemented. Basically everything
seems to work as it did visually. There is no difference that I can see in
performance, although some things might be a tiny bit faster.
I've merged the lookat and rph (pilot view) code into the recalc for the
viewer. There is still some redundancy between the two, but a lot has been
removed. In some cases I've taken some code that we'd likely want to inline
anyway and left it in there in duplicate. You'll see that the code for both
looks a little cleaner. I need to take a closer look at the rotations in
particular. I've cleaned up a little there, but I suspect more can be done
to streamline this.
The external declaration to the Quat_mat in mouse.cxx has been removed. IMHO
the quat doesn't serve any intrinsic purpose in mouse.cxx, but I'm not about
to rip it out. It would seem that there more conventional ways to get
spherical data that are just as fast. In any case all the viewer was pulling
from the quat matrix was the pitch value so I modified mouse.cxx to output to
our pitchOffset input and that works fine.
I've changed the native values to degrees from radians where appropriate.
This required a conversion from degrees to radians in a couple modules that
access the interface. Perhaps we should add interface calls that do the
conversion, e.g. a getHeadingOffset_rad() to go along with the
getHeadingOffset_deg().
On the view_offset (now headingOffset) thing there are two entry points
because of the ability to instantly switch views or to scroll to a new view
angle (by hitting the numeric keys for example). This leaves an anomaly in
the interface which should be resolved by adding "goal" settings to the
interface, e.g. a setGoalHeadingOffset_deg(), setGoalPitchOffset_deg(), etc.
Other than these two issues, the next step here will be to look at some
further optimizations, and to write support code for a tower view. That
should be fairly simple at this point. I was considering creating a
"simulated tower view" or "pedestrian view" that defaulted to a position off
to the right of whereever the plane is at the moment you switch to the tower
view. This could be a fall back when we don't have an actual tower location
at hand (as would be the case with rural airports).
ViewManager:
Basically all I did here was neaten things up by ripping out excess crap and
made it compatible as is with the new interface.
The result is that viewmanager is now ready to be developed. The two
preexisting views are still hardcoded into the view manager. The next step
would be to design configuration xml (eg /sim/view[x]/config/blahblah) that
could be used to set up as many views as we want. If we want to take the easy
way out, we might want to insist that view[0] be a pilot-view and have
viewmanager check for that.
2002-03-20 17:43:28 +00:00
|
|
|
set_goal_view_tilt(0.0);
|
2001-01-08 20:55:16 +00:00
|
|
|
#ifdef NO_SMOOTH_MOUSE_VIEW
|
2002-02-05 20:54:08 +00:00
|
|
|
set_view_offset(0.0);
|
Major viewer-code overhaul from Jim Wilson:
Description:
This update includes the new viewer interface as proposed by David M. and
a first pass at cleaning up the viewer/view manager code by Jim W.
Note that I have dropped Main/viewer_lookat.?xx and Main/viewer_rph.?xx and
modified the Makefile.am accordingly.
Detail of work:
Overall:
The code reads a little easier. There are still some unnecessary bits in
there and I'd like to supplement the comments in the viewer.hxx with a tiny
bit on each interface group and what the groupings mean (similar but briefer
than what you emailed me the other day). I tried not to mess up the style,
but there is an occasional inconsistency. In general I wouldn't call it done
(especially since there's no tower yet! :)), but I'd like to get this out
there so others can comment, and test.
In Viewer:
The interface as you suggested has been implemented. Basically everything
seems to work as it did visually. There is no difference that I can see in
performance, although some things might be a tiny bit faster.
I've merged the lookat and rph (pilot view) code into the recalc for the
viewer. There is still some redundancy between the two, but a lot has been
removed. In some cases I've taken some code that we'd likely want to inline
anyway and left it in there in duplicate. You'll see that the code for both
looks a little cleaner. I need to take a closer look at the rotations in
particular. I've cleaned up a little there, but I suspect more can be done
to streamline this.
The external declaration to the Quat_mat in mouse.cxx has been removed. IMHO
the quat doesn't serve any intrinsic purpose in mouse.cxx, but I'm not about
to rip it out. It would seem that there more conventional ways to get
spherical data that are just as fast. In any case all the viewer was pulling
from the quat matrix was the pitch value so I modified mouse.cxx to output to
our pitchOffset input and that works fine.
I've changed the native values to degrees from radians where appropriate.
This required a conversion from degrees to radians in a couple modules that
access the interface. Perhaps we should add interface calls that do the
conversion, e.g. a getHeadingOffset_rad() to go along with the
getHeadingOffset_deg().
On the view_offset (now headingOffset) thing there are two entry points
because of the ability to instantly switch views or to scroll to a new view
angle (by hitting the numeric keys for example). This leaves an anomaly in
the interface which should be resolved by adding "goal" settings to the
interface, e.g. a setGoalHeadingOffset_deg(), setGoalPitchOffset_deg(), etc.
Other than these two issues, the next step here will be to look at some
further optimizations, and to write support code for a tower view. That
should be fairly simple at this point. I was considering creating a
"simulated tower view" or "pedestrian view" that defaulted to a position off
to the right of whereever the plane is at the moment you switch to the tower
view. This could be a fall back when we don't have an actual tower location
at hand (as would be the case with rural airports).
ViewManager:
Basically all I did here was neaten things up by ripping out excess crap and
made it compatible as is with the new interface.
The result is that viewmanager is now ready to be developed. The two
preexisting views are still hardcoded into the view manager. The next step
would be to design configuration xml (eg /sim/view[x]/config/blahblah) that
could be used to set up as many views as we want. If we want to take the easy
way out, we might want to insist that view[0] be a pilot-view and have
viewmanager check for that.
2002-03-20 17:43:28 +00:00
|
|
|
set_view_tilt(0.0);
|
2001-01-08 20:55:16 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
glutWarpPointer( x , y);
|
|
|
|
build_rotmatrix(GuiQuat_mat, curGuiQuat);
|
|
|
|
_mVtoggle = ~_mVtoggle;
|
|
|
|
break;
|
|
|
|
}
|
2002-02-05 20:54:08 +00:00
|
|
|
} else if ( button == GLUT_RIGHT_BUTTON) {
|
2001-01-08 20:55:16 +00:00
|
|
|
switch (mouse_mode) {
|
2002-02-05 20:54:08 +00:00
|
|
|
|
2001-01-08 20:55:16 +00:00
|
|
|
case MOUSE_POINTER:
|
2002-02-05 20:54:08 +00:00
|
|
|
SG_LOG( SG_INPUT, SG_INFO, "Mouse in yoke mode" );
|
|
|
|
|
2001-01-08 20:55:16 +00:00
|
|
|
mouse_mode = MOUSE_YOKE;
|
|
|
|
mouse_joystick_control = 0;
|
|
|
|
_savedX = x;
|
|
|
|
_savedY = y;
|
|
|
|
// start with zero point in center of screen
|
2002-02-05 20:54:08 +00:00
|
|
|
_mX = MOUSE_XSIZE/2;
|
|
|
|
_mY = MOUSE_YSIZE/2;
|
2001-01-08 20:55:16 +00:00
|
|
|
|
|
|
|
// try to have the MOUSE_YOKE position
|
|
|
|
// reflect the current stick position
|
2002-02-05 20:54:08 +00:00
|
|
|
x = _mX - (int)(get_aileron() * aileron_sensitivity);
|
|
|
|
y = _mY - (int)(get_elevator() * elevator_sensitivity);
|
2001-01-08 20:55:16 +00:00
|
|
|
|
|
|
|
glutSetCursor(GLUT_CURSOR_CROSSHAIR);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MOUSE_YOKE:
|
2002-02-05 20:54:08 +00:00
|
|
|
SG_LOG( SG_INPUT, SG_INFO, "Mouse in view mode" );
|
|
|
|
|
2001-01-08 20:55:16 +00:00
|
|
|
mouse_mode = MOUSE_VIEW;
|
2001-11-12 20:57:08 +00:00
|
|
|
fgSetString("/sim/control-mode", "joystick");
|
2002-02-05 20:54:08 +00:00
|
|
|
|
|
|
|
// recenter cursor and reset
|
|
|
|
x = MOUSE_XSIZE/2;
|
|
|
|
y = MOUSE_YSIZE/2;
|
2001-01-08 20:55:16 +00:00
|
|
|
_mVtoggle = 0;
|
2002-02-05 20:54:08 +00:00
|
|
|
// #ifndef RESET_VIEW_ON_LEAVING_MOUSE_VIEW
|
2001-01-08 20:55:16 +00:00
|
|
|
Quat0();
|
|
|
|
build_rotmatrix(GuiQuat_mat, curGuiQuat);
|
2002-02-05 20:54:08 +00:00
|
|
|
// #endif
|
2001-01-08 20:55:16 +00:00
|
|
|
glutSetCursor(GLUT_CURSOR_LEFT_RIGHT);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MOUSE_VIEW:
|
2002-02-05 20:54:08 +00:00
|
|
|
SG_LOG( SG_INPUT, SG_INFO, "Mouse in pointer mode" );
|
|
|
|
|
2001-01-08 20:55:16 +00:00
|
|
|
mouse_mode = MOUSE_POINTER;
|
|
|
|
x = _savedX;
|
|
|
|
y = _savedY;
|
|
|
|
#ifdef RESET_VIEW_ON_LEAVING_MOUSE_VIEW
|
|
|
|
Quat0();
|
|
|
|
build_rotmatrix(GuiQuat_mat, curGuiQuat);
|
2002-02-05 20:54:08 +00:00
|
|
|
set_goal_view_offset(0.0);
|
Major viewer-code overhaul from Jim Wilson:
Description:
This update includes the new viewer interface as proposed by David M. and
a first pass at cleaning up the viewer/view manager code by Jim W.
Note that I have dropped Main/viewer_lookat.?xx and Main/viewer_rph.?xx and
modified the Makefile.am accordingly.
Detail of work:
Overall:
The code reads a little easier. There are still some unnecessary bits in
there and I'd like to supplement the comments in the viewer.hxx with a tiny
bit on each interface group and what the groupings mean (similar but briefer
than what you emailed me the other day). I tried not to mess up the style,
but there is an occasional inconsistency. In general I wouldn't call it done
(especially since there's no tower yet! :)), but I'd like to get this out
there so others can comment, and test.
In Viewer:
The interface as you suggested has been implemented. Basically everything
seems to work as it did visually. There is no difference that I can see in
performance, although some things might be a tiny bit faster.
I've merged the lookat and rph (pilot view) code into the recalc for the
viewer. There is still some redundancy between the two, but a lot has been
removed. In some cases I've taken some code that we'd likely want to inline
anyway and left it in there in duplicate. You'll see that the code for both
looks a little cleaner. I need to take a closer look at the rotations in
particular. I've cleaned up a little there, but I suspect more can be done
to streamline this.
The external declaration to the Quat_mat in mouse.cxx has been removed. IMHO
the quat doesn't serve any intrinsic purpose in mouse.cxx, but I'm not about
to rip it out. It would seem that there more conventional ways to get
spherical data that are just as fast. In any case all the viewer was pulling
from the quat matrix was the pitch value so I modified mouse.cxx to output to
our pitchOffset input and that works fine.
I've changed the native values to degrees from radians where appropriate.
This required a conversion from degrees to radians in a couple modules that
access the interface. Perhaps we should add interface calls that do the
conversion, e.g. a getHeadingOffset_rad() to go along with the
getHeadingOffset_deg().
On the view_offset (now headingOffset) thing there are two entry points
because of the ability to instantly switch views or to scroll to a new view
angle (by hitting the numeric keys for example). This leaves an anomaly in
the interface which should be resolved by adding "goal" settings to the
interface, e.g. a setGoalHeadingOffset_deg(), setGoalPitchOffset_deg(), etc.
Other than these two issues, the next step here will be to look at some
further optimizations, and to write support code for a tower view. That
should be fairly simple at this point. I was considering creating a
"simulated tower view" or "pedestrian view" that defaulted to a position off
to the right of whereever the plane is at the moment you switch to the tower
view. This could be a fall back when we don't have an actual tower location
at hand (as would be the case with rural airports).
ViewManager:
Basically all I did here was neaten things up by ripping out excess crap and
made it compatible as is with the new interface.
The result is that viewmanager is now ready to be developed. The two
preexisting views are still hardcoded into the view manager. The next step
would be to design configuration xml (eg /sim/view[x]/config/blahblah) that
could be used to set up as many views as we want. If we want to take the easy
way out, we might want to insist that view[0] be a pilot-view and have
viewmanager check for that.
2002-03-20 17:43:28 +00:00
|
|
|
set_goal_view_tilt(0.0);
|
2001-01-08 20:55:16 +00:00
|
|
|
#ifdef NO_SMOOTH_MOUSE_VIEW
|
2002-02-05 20:54:08 +00:00
|
|
|
set_view_offset(0.0);
|
Major viewer-code overhaul from Jim Wilson:
Description:
This update includes the new viewer interface as proposed by David M. and
a first pass at cleaning up the viewer/view manager code by Jim W.
Note that I have dropped Main/viewer_lookat.?xx and Main/viewer_rph.?xx and
modified the Makefile.am accordingly.
Detail of work:
Overall:
The code reads a little easier. There are still some unnecessary bits in
there and I'd like to supplement the comments in the viewer.hxx with a tiny
bit on each interface group and what the groupings mean (similar but briefer
than what you emailed me the other day). I tried not to mess up the style,
but there is an occasional inconsistency. In general I wouldn't call it done
(especially since there's no tower yet! :)), but I'd like to get this out
there so others can comment, and test.
In Viewer:
The interface as you suggested has been implemented. Basically everything
seems to work as it did visually. There is no difference that I can see in
performance, although some things might be a tiny bit faster.
I've merged the lookat and rph (pilot view) code into the recalc for the
viewer. There is still some redundancy between the two, but a lot has been
removed. In some cases I've taken some code that we'd likely want to inline
anyway and left it in there in duplicate. You'll see that the code for both
looks a little cleaner. I need to take a closer look at the rotations in
particular. I've cleaned up a little there, but I suspect more can be done
to streamline this.
The external declaration to the Quat_mat in mouse.cxx has been removed. IMHO
the quat doesn't serve any intrinsic purpose in mouse.cxx, but I'm not about
to rip it out. It would seem that there more conventional ways to get
spherical data that are just as fast. In any case all the viewer was pulling
from the quat matrix was the pitch value so I modified mouse.cxx to output to
our pitchOffset input and that works fine.
I've changed the native values to degrees from radians where appropriate.
This required a conversion from degrees to radians in a couple modules that
access the interface. Perhaps we should add interface calls that do the
conversion, e.g. a getHeadingOffset_rad() to go along with the
getHeadingOffset_deg().
On the view_offset (now headingOffset) thing there are two entry points
because of the ability to instantly switch views or to scroll to a new view
angle (by hitting the numeric keys for example). This leaves an anomaly in
the interface which should be resolved by adding "goal" settings to the
interface, e.g. a setGoalHeadingOffset_deg(), setGoalPitchOffset_deg(), etc.
Other than these two issues, the next step here will be to look at some
further optimizations, and to write support code for a tower view. That
should be fairly simple at this point. I was considering creating a
"simulated tower view" or "pedestrian view" that defaulted to a position off
to the right of whereever the plane is at the moment you switch to the tower
view. This could be a fall back when we don't have an actual tower location
at hand (as would be the case with rural airports).
ViewManager:
Basically all I did here was neaten things up by ripping out excess crap and
made it compatible as is with the new interface.
The result is that viewmanager is now ready to be developed. The two
preexisting views are still hardcoded into the view manager. The next step
would be to design configuration xml (eg /sim/view[x]/config/blahblah) that
could be used to set up as many views as we want. If we want to take the easy
way out, we might want to insist that view[0] be a pilot-view and have
viewmanager check for that.
2002-03-20 17:43:28 +00:00
|
|
|
set_view_tilt(0.0);
|
2001-11-12 19:37:23 +00:00
|
|
|
#endif // NO_SMOOTH_MOUSE_VIEW
|
|
|
|
#endif // RESET_VIEW_ON_LEAVING_MOUSE_VIEW
|
2001-01-08 20:55:16 +00:00
|
|
|
glutSetCursor(GLUT_CURSOR_INHERIT);
|
|
|
|
|
2001-11-12 19:37:23 +00:00
|
|
|
#if defined(WIN32_CURSOR_TWEAKS_OFF)
|
2001-01-08 20:55:16 +00:00
|
|
|
if(!gui_menu_on)
|
|
|
|
TurnCursorOff();
|
2001-11-12 19:37:23 +00:00
|
|
|
#endif // WIN32_CURSOR_TWEAKS_OFF
|
2001-01-08 20:55:16 +00:00
|
|
|
break;
|
2001-11-12 19:37:23 +00:00
|
|
|
} // end switch (mouse_mode)
|
2001-01-08 20:55:16 +00:00
|
|
|
glutWarpPointer( x, y );
|
|
|
|
} // END RIGHT BUTTON
|
|
|
|
} // END UPDOWN == GLUT_DOWN
|
|
|
|
|
|
|
|
// Note which button is pressed.
|
|
|
|
if ( updown == GLUT_DOWN ) {
|
|
|
|
last_buttons |= ( 1 << button ) ;
|
|
|
|
} else {
|
|
|
|
last_buttons &= ~( 1 << button ) ;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we're in pointer mode, let PUI
|
|
|
|
// know what's going on.
|
|
|
|
if (mouse_mode == MOUSE_POINTER) {
|
|
|
|
if (!puMouse (button, updown, x,y)) {
|
2001-06-13 16:41:02 +00:00
|
|
|
if ( current_panel != NULL ) {
|
|
|
|
current_panel->doMouseAction(button, updown, x, y);
|
|
|
|
}
|
2001-01-08 20:55:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Register the new position (if it
|
|
|
|
// hasn't been registered already).
|
|
|
|
_mX = x;
|
|
|
|
_mY = y;
|
|
|
|
|
|
|
|
glutPostRedisplay ();
|
|
|
|
}
|
|
|
|
|
Major viewer-code overhaul from Jim Wilson:
Description:
This update includes the new viewer interface as proposed by David M. and
a first pass at cleaning up the viewer/view manager code by Jim W.
Note that I have dropped Main/viewer_lookat.?xx and Main/viewer_rph.?xx and
modified the Makefile.am accordingly.
Detail of work:
Overall:
The code reads a little easier. There are still some unnecessary bits in
there and I'd like to supplement the comments in the viewer.hxx with a tiny
bit on each interface group and what the groupings mean (similar but briefer
than what you emailed me the other day). I tried not to mess up the style,
but there is an occasional inconsistency. In general I wouldn't call it done
(especially since there's no tower yet! :)), but I'd like to get this out
there so others can comment, and test.
In Viewer:
The interface as you suggested has been implemented. Basically everything
seems to work as it did visually. There is no difference that I can see in
performance, although some things might be a tiny bit faster.
I've merged the lookat and rph (pilot view) code into the recalc for the
viewer. There is still some redundancy between the two, but a lot has been
removed. In some cases I've taken some code that we'd likely want to inline
anyway and left it in there in duplicate. You'll see that the code for both
looks a little cleaner. I need to take a closer look at the rotations in
particular. I've cleaned up a little there, but I suspect more can be done
to streamline this.
The external declaration to the Quat_mat in mouse.cxx has been removed. IMHO
the quat doesn't serve any intrinsic purpose in mouse.cxx, but I'm not about
to rip it out. It would seem that there more conventional ways to get
spherical data that are just as fast. In any case all the viewer was pulling
from the quat matrix was the pitch value so I modified mouse.cxx to output to
our pitchOffset input and that works fine.
I've changed the native values to degrees from radians where appropriate.
This required a conversion from degrees to radians in a couple modules that
access the interface. Perhaps we should add interface calls that do the
conversion, e.g. a getHeadingOffset_rad() to go along with the
getHeadingOffset_deg().
On the view_offset (now headingOffset) thing there are two entry points
because of the ability to instantly switch views or to scroll to a new view
angle (by hitting the numeric keys for example). This leaves an anomaly in
the interface which should be resolved by adding "goal" settings to the
interface, e.g. a setGoalHeadingOffset_deg(), setGoalPitchOffset_deg(), etc.
Other than these two issues, the next step here will be to look at some
further optimizations, and to write support code for a tower view. That
should be fairly simple at this point. I was considering creating a
"simulated tower view" or "pedestrian view" that defaulted to a position off
to the right of whereever the plane is at the moment you switch to the tower
view. This could be a fall back when we don't have an actual tower location
at hand (as would be the case with rural airports).
ViewManager:
Basically all I did here was neaten things up by ripping out excess crap and
made it compatible as is with the new interface.
The result is that viewmanager is now ready to be developed. The two
preexisting views are still hardcoded into the view manager. The next step
would be to design configuration xml (eg /sim/view[x]/config/blahblah) that
could be used to set up as many views as we want. If we want to take the easy
way out, we might want to insist that view[0] be a pilot-view and have
viewmanager check for that.
2002-03-20 17:43:28 +00:00
|
|
|
|
|
|
|
|