More work on the external view panning.
This commit is contained in:
parent
9944216573
commit
361fa84d18
2 changed files with 225 additions and 174 deletions
|
@ -13,6 +13,7 @@
|
|||
*/
|
||||
|
||||
#include "sgVec3Slider.hxx"
|
||||
#include <simgear/sg_inlines.h>
|
||||
|
||||
class FloatSlider : public puSlider
|
||||
{
|
||||
|
@ -29,7 +30,7 @@ class FloatSlider : public puSlider
|
|||
char _text[16];
|
||||
public:
|
||||
FloatSlider ( int x, int y, int sz, float f, const char *title,
|
||||
float max = 100.0f );
|
||||
float max = 90.0f );
|
||||
|
||||
~FloatSlider () {;}
|
||||
|
||||
|
@ -53,7 +54,6 @@ class FloatSlider : public puSlider
|
|||
}
|
||||
|
||||
void reinit() { init( origValue ); }
|
||||
|
||||
void cancel() { MyValue = TmpValue; }
|
||||
void reset () { init( origValue ); }
|
||||
|
||||
|
@ -103,27 +103,34 @@ class sgVec3Slider : public puDialogBox
|
|||
puOneShot *ResetButton;
|
||||
puOneShot *CancelButton;
|
||||
sgVec3 Vec, SaveVec;
|
||||
|
||||
public:
|
||||
|
||||
sgVec3Slider ( int x, int y, sgVec3 vec,
|
||||
const char *title = "Vector Adjuster",
|
||||
const char *Xtitle = "X",
|
||||
const char *Ytitle = "Y",
|
||||
const char *Ztitle = "Z" );
|
||||
const char *Xtitle = "Heading",
|
||||
const char *Ytitle = "Pitch",
|
||||
const char *Ztitle = "Radius" );
|
||||
|
||||
~sgVec3Slider () {;}
|
||||
|
||||
// ???
|
||||
void setVec() {
|
||||
Vec[0] = HS2->get();
|
||||
Vec[1] = HS1->get();
|
||||
Vec[2] = HS0->get();
|
||||
void setVec()
|
||||
{
|
||||
Vec3FromHeadingPitchRadius( Vec,
|
||||
(HS0->get() + 90) * 2,
|
||||
HS1->get(),
|
||||
HS2->get() );
|
||||
}
|
||||
|
||||
sgVec3 *getVec() { setVec(); return &Vec; };
|
||||
|
||||
sgVec3 *getStashVec() { return &SaveVec; }
|
||||
void stashVec() { sgCopyVec3( SaveVec, Vec ); }
|
||||
void stashVec() {
|
||||
SaveVec[2] = HS0->get();
|
||||
SaveVec[1] = HS1->get();
|
||||
SaveVec[0] = HS2->get();
|
||||
}
|
||||
|
||||
FloatSlider *getHS0() { return HS0; }
|
||||
FloatSlider *getHS1() { return HS1; }
|
||||
|
@ -135,27 +142,27 @@ class sgVec3Slider : public puDialogBox
|
|||
sgVec3Slider::sgVec3Slider ( int x, int y, sgVec3 vec, const char *title,
|
||||
const char *Xtitle,
|
||||
const char *Ytitle,
|
||||
const char *Ztitle )
|
||||
: puDialogBox ( x, y )
|
||||
const char *Ztitle ): puDialogBox ( x, y )
|
||||
{
|
||||
// int DialogX = x;
|
||||
// int DialogY = y;
|
||||
puFont LegendFont, LabelFont;
|
||||
puGetDefaultFonts ( &LegendFont, &LabelFont );
|
||||
|
||||
int fudge = 20;
|
||||
static const int DialogWidth = 230 + fudge;
|
||||
|
||||
int labelW = LabelFont.getStringWidth(Xtitle);
|
||||
labelW = SG_MAX2( labelW, LabelFont.getStringWidth(Ytitle));
|
||||
labelW = SG_MAX2( labelW, LabelFont.getStringWidth(Ztitle));
|
||||
|
||||
int DialogWidth = 300 + fudge + labelW;
|
||||
|
||||
sgCopyVec3(SaveVec, vec);
|
||||
sgCopyVec3(Vec, vec);
|
||||
strcpy( Label, title );
|
||||
|
||||
static const int nSliders = 3;
|
||||
static const int slider_x = 10+fudge;
|
||||
int nSliders = 3;
|
||||
int slider_x = 70+fudge;
|
||||
int slider_y = 55;
|
||||
static const int slider_width = 210;
|
||||
// static const int slider_title_x = 15;
|
||||
// static const int slider_value_x = 160;
|
||||
|
||||
puFont LegendFont, LabelFont;
|
||||
puGetDefaultFonts ( &LegendFont, &LabelFont );
|
||||
int slider_width = 240;
|
||||
|
||||
int horiz_slider_height = puGetStringHeight (&LabelFont) +
|
||||
puGetStringDescender (&LabelFont) +
|
||||
|
@ -180,24 +187,23 @@ sgVec3Slider::sgVec3Slider ( int x, int y, sgVec3 vec, const char *title,
|
|||
|
||||
HS0 = new FloatSlider ( slider_x, slider_y, slider_width, vec[0], Xtitle );
|
||||
|
||||
OkButton = new puOneShot ( 10+fudge, 10, 60+fudge, 50 );
|
||||
OkButton = new puOneShot ( 70+fudge, 10, 120+fudge, 50 );
|
||||
OkButton-> setUserData( this );
|
||||
OkButton-> setLegend ( gui_msg_OK );
|
||||
OkButton-> makeReturnDefault ( TRUE );
|
||||
OkButton-> setCallback ( goAway );
|
||||
|
||||
CancelButton = new puOneShot ( 70+fudge, 10, 150+fudge, 50 );
|
||||
CancelButton = new puOneShot ( 130+fudge, 10, 210+fudge, 50 );
|
||||
CancelButton-> setUserData( this );
|
||||
CancelButton-> setLegend ( gui_msg_CANCEL );
|
||||
CancelButton-> setCallback ( cancel );
|
||||
|
||||
ResetButton = new puOneShot ( 160+fudge, 10, 220+fudge, 50 );
|
||||
ResetButton = new puOneShot ( 220+fudge, 10, 280+fudge, 50 );
|
||||
ResetButton-> setUserData( this );
|
||||
ResetButton-> setLegend ( gui_msg_RESET );
|
||||
ResetButton-> setCallback ( reset );
|
||||
|
||||
FG_FINALIZE_PUI_DIALOG( this );
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -217,13 +223,14 @@ void sgVec3Slider::reset(puObject *p_obj)
|
|||
|
||||
void sgVec3Slider::cancel(puObject *p_obj)
|
||||
{
|
||||
sgVec3Slider *me = (sgVec3Slider *)p_obj->getUserData();
|
||||
sgVec3 vec;
|
||||
sgVec3Slider *me = (sgVec3Slider *)p_obj->getUserData();
|
||||
sgVec3 *pvec = me -> getStashVec();
|
||||
sgCopyVec3( vec, *pvec );
|
||||
me->HS0->init(vec[2]);
|
||||
me->HS1->init(vec[1]);
|
||||
me->HS2->init(vec[0]);
|
||||
me->setVec();
|
||||
FG_POP_PUI_DIALOG( me );
|
||||
};
|
||||
|
||||
|
@ -246,6 +253,12 @@ void sgVec3SliderAdjust( puObject *p_obj )
|
|||
// These are globals for now
|
||||
static puObject *PO_vec = 0;
|
||||
|
||||
void PilotOffsetInit() {
|
||||
sgVec3 v;
|
||||
sgSetVec3(v,0.0,0.0,20.0);
|
||||
PilotOffsetInit(v);
|
||||
}
|
||||
|
||||
void PilotOffsetInit( sgVec3 vec )
|
||||
{
|
||||
// Only one of these things for now
|
||||
|
@ -258,10 +271,7 @@ void PilotOffsetInit( sgVec3 vec )
|
|||
void PilotOffsetAdjust( puObject * )
|
||||
{
|
||||
if( PO_vec == 0 ) {
|
||||
sgVec3 v;
|
||||
// we seem to need the ~quite zero terms ???
|
||||
sgSetVec3(v,15,0.0001,0.0001);
|
||||
PilotOffsetInit(v);
|
||||
PilotOffsetInit();
|
||||
}
|
||||
sgVec3Slider *me = (sgVec3Slider *)PO_vec -> getUserData();
|
||||
me -> stashVec();
|
||||
|
@ -272,11 +282,49 @@ void PilotOffsetAdjust( puObject * )
|
|||
sgVec3 *PilotOffsetGet()
|
||||
{
|
||||
if( PO_vec == 0 ) {
|
||||
sgVec3 v;
|
||||
// we seem to need the ~quite zero terms ???
|
||||
sgSetVec3(v,25,0.0001,0.0001);
|
||||
PilotOffsetInit(v);
|
||||
PilotOffsetInit();
|
||||
}
|
||||
sgVec3Slider *me = (sgVec3Slider *)PO_vec -> getUserData();
|
||||
return( me -> getVec() );
|
||||
}
|
||||
|
||||
|
||||
// Heading == longitude of point on sphere
|
||||
// Pitch == latitude of point on sphere
|
||||
// Radius == radius of sphere
|
||||
|
||||
#define MIN_VIEW_OFFSET 5.0
|
||||
void Vec3FromHeadingPitchRadius ( sgVec3 vec3, float heading, float pitch,
|
||||
float radius )
|
||||
{
|
||||
double ch, sh, cp, sp;
|
||||
|
||||
if ( heading == SG_ZERO )
|
||||
{
|
||||
ch = SGD_ONE ;
|
||||
sh = SGD_ZERO ;
|
||||
}
|
||||
else
|
||||
{
|
||||
sh = sin( (double)( heading * SG_DEGREES_TO_RADIANS )) ;
|
||||
ch = cos( (double)( heading * SG_DEGREES_TO_RADIANS )) ;
|
||||
}
|
||||
|
||||
if ( pitch == SG_ZERO )
|
||||
{
|
||||
cp = SGD_ONE ;
|
||||
sp = SGD_ZERO ;
|
||||
}
|
||||
else
|
||||
{
|
||||
sp = sin( (double)( pitch * SG_DEGREES_TO_RADIANS )) ;
|
||||
cp = cos( (double)( pitch * SG_DEGREES_TO_RADIANS )) ;
|
||||
}
|
||||
|
||||
if ( radius < MIN_VIEW_OFFSET )
|
||||
radius = MIN_VIEW_OFFSET ;
|
||||
|
||||
vec3[2] = (SGfloat)( ch * cp ) * radius ; // X
|
||||
vec3[1] = (SGfloat)( sh * cp ) * radius ; // Y
|
||||
vec3[0] = (SGfloat)( sp ) * radius ; // Z
|
||||
}
|
||||
|
|
|
@ -14,8 +14,11 @@
|
|||
#include <stdio.h>
|
||||
#include "gui.h"
|
||||
|
||||
void PilotOffsetInit();
|
||||
void PilotOffsetInit( sgVec3 vec );
|
||||
void PilotOffsetAdjust( puObject * );
|
||||
void Vec3FromHeadingPitchRadius( sgVec3 vec3, float heading, float pitch, float radius );
|
||||
//void PilotOffsetGet( float *po );
|
||||
sgVec3 *PilotOffsetGet();
|
||||
|
||||
#endif // _VEC3_SLIDER_H
|
||||
|
|
Loading…
Reference in a new issue