1
0
Fork 0

More work on the external view panning.

This commit is contained in:
curt 2001-07-13 16:50:35 +00:00
parent 9944216573
commit 361fa84d18
2 changed files with 225 additions and 174 deletions

View file

@ -13,76 +13,76 @@
*/ */
#include "sgVec3Slider.hxx" #include "sgVec3Slider.hxx"
#include <simgear/sg_inlines.h>
class FloatSlider : public puSlider class FloatSlider : public puSlider
{ {
protected: protected:
float maxValue; float maxValue;
float origValue; float origValue;
float Adjust; float Adjust;
float MyValue; float MyValue;
float TmpValue; float TmpValue;
float SaveValue; float SaveValue;
char buf[8]; char buf[8];
char _title[32]; char _title[32];
char _text[16]; char _text[16];
public: public:
FloatSlider ( int x, int y, int sz, float f, const char *title, FloatSlider ( int x, int y, int sz, float f, const char *title,
float max = 100.0f ); float max = 90.0f );
~FloatSlider () {;} ~FloatSlider () {;}
static void adj( puObject *);
static void adj( puObject *); void updateText() {
sprintf( _text, "%05.2f", MyValue );
}
void updateText() { float get() { return( MyValue ); }
sprintf( _text, "%05.2f", MyValue ); void set() { MyValue = ((2.0*maxValue) * (TmpValue - 0.5f)) - maxValue; }
}
float get() { return( MyValue ); } float *getTmp() { return( &TmpValue ); }
void set() { MyValue = ((2.0*maxValue) * (TmpValue - 0.5f)) - maxValue; } void setTmp() { TmpValue += 0.5f; }
float *getTmp() { return( &TmpValue ); } // double the range from -max <-> max
void setTmp() { TmpValue += 0.5f; } void init( float f ) {
Adjust = 0.5f / maxValue;
setValue((f * Adjust) + 0.5f);
adj( this );
}
// double the range from -max <-> max void reinit() { init( origValue ); }
void init( float f ) { void cancel() { MyValue = TmpValue; }
Adjust = 0.5f / maxValue; void reset () { init( origValue ); }
setValue((f * Adjust) + 0.5f);
adj( this );
}
void reinit() { init( origValue ); }
void cancel() { MyValue = TmpValue; }
void reset () { init( origValue ); }
}; };
void FloatSlider::adj( puObject *hs ) void FloatSlider::adj( puObject *hs )
{ {
FloatSlider *slider = (FloatSlider *)hs->getUserData(); FloatSlider *slider = (FloatSlider *)hs->getUserData();
slider->getValue ( slider->getTmp() ); slider->getValue ( slider->getTmp() );
slider->setTmp(); slider->setTmp();
slider->set(); slider->set();
slider->updateText(); slider->updateText();
} }
FloatSlider::FloatSlider ( int x, int y, int sz, float f, const char *title, FloatSlider::FloatSlider ( int x, int y, int sz, float f, const char *title,
float max ) : puSlider( x, y, sz, FALSE ) float max ) : puSlider( x, y, sz, FALSE )
{ {
setUserData( this ); setUserData( this );
maxValue = max; maxValue = max;
origValue = f; origValue = f;
init(f); init(f);
setDelta ( 0.01 ); setDelta ( 0.01 );
setCBMode ( PUSLIDER_DELTA ) ; setCBMode ( PUSLIDER_DELTA ) ;
setCallback ( adj ) ; setCallback ( adj ) ;
strcpy ( _title, title); strcpy ( _title, title);
setLabel ( _title ); setLabel ( _title );
setLabelPlace ( PUPLACE_LEFT ); setLabelPlace ( PUPLACE_LEFT );
setLegend(_text); setLegend(_text);
// setLegendPlace( PUPLACE_RIGHT ); // setLegendPlace( PUPLACE_RIGHT );
} }
@ -90,193 +90,241 @@ FloatSlider::FloatSlider ( int x, int y, int sz, float f, const char *title,
class sgVec3Slider : public puDialogBox class sgVec3Slider : public puDialogBox
{ {
static void goAway(puObject *p_obj); static void goAway(puObject *p_obj);
static void reset(puObject *p_obj); static void reset(puObject *p_obj);
static void cancel(puObject *p_obj); static void cancel(puObject *p_obj);
protected: protected:
char Label[64]; char Label[64];
FloatSlider *HS0; FloatSlider *HS0;
FloatSlider *HS1; FloatSlider *HS1;
FloatSlider *HS2; FloatSlider *HS2;
puOneShot *OkButton; puOneShot *OkButton;
puOneShot *ResetButton; puOneShot *ResetButton;
puOneShot *CancelButton; puOneShot *CancelButton;
sgVec3 Vec, SaveVec; sgVec3 Vec, SaveVec;
public:
public:
sgVec3Slider ( int x, int y, sgVec3 vec, sgVec3Slider ( int x, int y, sgVec3 vec,
const char *title = "Vector Adjuster", const char *title = "Vector Adjuster",
const char *Xtitle = "X", const char *Xtitle = "Heading",
const char *Ytitle = "Y", const char *Ytitle = "Pitch",
const char *Ztitle = "Z" ); const char *Ztitle = "Radius" );
~sgVec3Slider () {;} ~sgVec3Slider () {;}
// ??? // ???
void setVec() { void setVec()
Vec[0] = HS2->get(); {
Vec[1] = HS1->get(); Vec3FromHeadingPitchRadius( Vec,
Vec[2] = HS0->get(); (HS0->get() + 90) * 2,
} HS1->get(),
HS2->get() );
}
sgVec3 *getVec() { setVec(); return &Vec; }; sgVec3 *getVec() { setVec(); return &Vec; };
sgVec3 *getStashVec() { return &SaveVec; } 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 *getHS0() { return HS0; }
FloatSlider *getHS1() { return HS1; } FloatSlider *getHS1() { return HS1; }
FloatSlider *getHS2() { return HS2; } FloatSlider *getHS2() { return HS2; }
static void adjust(puObject *p_obj); static void adjust(puObject *p_obj);
}; };
sgVec3Slider::sgVec3Slider ( int x, int y, sgVec3 vec, const char *title, sgVec3Slider::sgVec3Slider ( int x, int y, sgVec3 vec, const char *title,
const char *Xtitle, const char *Xtitle,
const char *Ytitle, const char *Ytitle,
const char *Ztitle ) const char *Ztitle ): puDialogBox ( x, y )
: puDialogBox ( x, y )
{ {
// int DialogX = x; puFont LegendFont, LabelFont;
// int DialogY = y; puGetDefaultFonts ( &LegendFont, &LabelFont );
int fudge = 20;
static const int DialogWidth = 230 + fudge;
sgCopyVec3(SaveVec, vec); int fudge = 20;
sgCopyVec3(Vec, vec);
strcpy( Label, title );
static const int nSliders = 3; int labelW = LabelFont.getStringWidth(Xtitle);
static const int slider_x = 10+fudge; labelW = SG_MAX2( labelW, LabelFont.getStringWidth(Ytitle));
int slider_y = 55; labelW = SG_MAX2( labelW, LabelFont.getStringWidth(Ztitle));
static const int slider_width = 210;
// static const int slider_title_x = 15; int DialogWidth = 300 + fudge + labelW;
// static const int slider_value_x = 160;
puFont LegendFont, LabelFont; sgCopyVec3(SaveVec, vec);
puGetDefaultFonts ( &LegendFont, &LabelFont ); sgCopyVec3(Vec, vec);
strcpy( Label, title );
int horiz_slider_height = puGetStringHeight (&LabelFont) + int nSliders = 3;
puGetStringDescender (&LabelFont) + int slider_x = 70+fudge;
PUSTR_TGAP + PUSTR_BGAP + 5; int slider_y = 55;
int slider_width = 240;
// HACKS int horiz_slider_height = puGetStringHeight (&LabelFont) +
setUserData( this ); puGetStringDescender (&LabelFont) +
horiz_slider_height += 10; PUSTR_TGAP + PUSTR_BGAP + 5;
new puFrame ( 0, 0, // HACKS
DialogWidth, setUserData( this );
85 + nSliders * horiz_slider_height ); horiz_slider_height += 10;
setLabelPlace( PUPLACE_DEFAULT /*PUPLACE_CENTERED*/ ); new puFrame ( 0, 0,
setLabel( Label ); DialogWidth,
85 + nSliders * horiz_slider_height );
HS2 = new FloatSlider ( slider_x, slider_y, slider_width, vec[2], Ztitle ); setLabelPlace( PUPLACE_DEFAULT /*PUPLACE_CENTERED*/ );
slider_y += horiz_slider_height; setLabel( Label );
HS1 = new FloatSlider ( slider_x, slider_y, slider_width, vec[1], Ytitle ); HS2 = new FloatSlider ( slider_x, slider_y, slider_width, vec[2], Ztitle );
slider_y += horiz_slider_height; slider_y += horiz_slider_height;
HS0 = new FloatSlider ( slider_x, slider_y, slider_width, vec[0], Xtitle ); HS1 = new FloatSlider ( slider_x, slider_y, slider_width, vec[1], Ytitle );
slider_y += horiz_slider_height;
OkButton = new puOneShot ( 10+fudge, 10, 60+fudge, 50 ); HS0 = new FloatSlider ( slider_x, slider_y, slider_width, vec[0], Xtitle );
OkButton-> setUserData( this );
OkButton-> setLegend ( gui_msg_OK );
OkButton-> makeReturnDefault ( TRUE );
OkButton-> setCallback ( goAway );
CancelButton = new puOneShot ( 70+fudge, 10, 150+fudge, 50 ); OkButton = new puOneShot ( 70+fudge, 10, 120+fudge, 50 );
CancelButton-> setUserData( this ); OkButton-> setUserData( this );
CancelButton-> setLegend ( gui_msg_CANCEL ); OkButton-> setLegend ( gui_msg_OK );
CancelButton-> setCallback ( cancel ); OkButton-> makeReturnDefault ( TRUE );
OkButton-> setCallback ( goAway );
ResetButton = new puOneShot ( 160+fudge, 10, 220+fudge, 50 ); CancelButton = new puOneShot ( 130+fudge, 10, 210+fudge, 50 );
ResetButton-> setUserData( this ); CancelButton-> setUserData( this );
ResetButton-> setLegend ( gui_msg_RESET ); CancelButton-> setLegend ( gui_msg_CANCEL );
ResetButton-> setCallback ( reset ); CancelButton-> setCallback ( cancel );
FG_FINALIZE_PUI_DIALOG( this ); 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 );
} }
void sgVec3Slider::goAway(puObject *p_obj) void sgVec3Slider::goAway(puObject *p_obj)
{ {
sgVec3Slider *me = (sgVec3Slider *)p_obj->getUserData(); sgVec3Slider *me = (sgVec3Slider *)p_obj->getUserData();
FG_POP_PUI_DIALOG( me ); FG_POP_PUI_DIALOG( me );
}; };
void sgVec3Slider::reset(puObject *p_obj) void sgVec3Slider::reset(puObject *p_obj)
{ {
sgVec3Slider *me = (sgVec3Slider *)p_obj->getUserData(); sgVec3Slider *me = (sgVec3Slider *)p_obj->getUserData();
me->HS0->reinit(); me->HS0->reinit();
me->HS1->reinit(); me->HS1->reinit();
me->HS2->reinit(); me->HS2->reinit();
}; };
void sgVec3Slider::cancel(puObject *p_obj) void sgVec3Slider::cancel(puObject *p_obj)
{ {
sgVec3Slider *me = (sgVec3Slider *)p_obj->getUserData(); sgVec3 vec;
sgVec3 vec; sgVec3Slider *me = (sgVec3Slider *)p_obj->getUserData();
sgVec3 *pvec = me -> getStashVec(); sgVec3 *pvec = me -> getStashVec();
sgCopyVec3( vec, *pvec ); sgCopyVec3( vec, *pvec );
me->HS0->init(vec[2]); me->HS0->init(vec[2]);
me->HS1->init(vec[1]); me->HS1->init(vec[1]);
me->HS2->init(vec[0]); me->HS2->init(vec[0]);
FG_POP_PUI_DIALOG( me ); me->setVec();
FG_POP_PUI_DIALOG( me );
}; };
void sgVec3Slider::adjust(puObject *p_obj) void sgVec3Slider::adjust(puObject *p_obj)
{ {
sgVec3Slider *me = (sgVec3Slider *)p_obj->getUserData(); sgVec3Slider *me = (sgVec3Slider *)p_obj->getUserData();
me -> getHS0() -> adj((puObject *)me -> getHS0()); me -> getHS0() -> adj((puObject *)me -> getHS0());
me -> getHS1() -> adj((puObject *)me -> getHS1()); me -> getHS1() -> adj((puObject *)me -> getHS1());
me -> getHS2() -> adj((puObject *)me -> getHS2()); me -> getHS2() -> adj((puObject *)me -> getHS2());
me -> setVec(); me -> setVec();
}; };
void sgVec3SliderAdjust( puObject *p_obj ) void sgVec3SliderAdjust( puObject *p_obj )
{ {
sgVec3Slider *me = (sgVec3Slider *)p_obj -> getUserData(); sgVec3Slider *me = (sgVec3Slider *)p_obj -> getUserData();
me -> adjust( me ); me -> adjust( me );
FG_PUSH_PUI_DIALOG( me ); FG_PUSH_PUI_DIALOG( me );
} }
// These are globals for now // These are globals for now
static puObject *PO_vec = 0; static puObject *PO_vec = 0;
void PilotOffsetInit() {
sgVec3 v;
sgSetVec3(v,0.0,0.0,20.0);
PilotOffsetInit(v);
}
void PilotOffsetInit( sgVec3 vec ) void PilotOffsetInit( sgVec3 vec )
{ {
// Only one of these things for now // Only one of these things for now
if( PO_vec == 0 ) { if( PO_vec == 0 ) {
sgVec3Slider *PO = new sgVec3Slider ( 200, 200, vec, "Pilot Offset" ); sgVec3Slider *PO = new sgVec3Slider ( 200, 200, vec, "Pilot Offset" );
PO_vec = PO; PO_vec = PO;
} }
} }
void PilotOffsetAdjust( puObject * ) void PilotOffsetAdjust( puObject * )
{ {
if( PO_vec == 0 ) { if( PO_vec == 0 ) {
sgVec3 v; PilotOffsetInit();
// we seem to need the ~quite zero terms ??? }
sgSetVec3(v,15,0.0001,0.0001); sgVec3Slider *me = (sgVec3Slider *)PO_vec -> getUserData();
PilotOffsetInit(v); me -> stashVec();
} me -> adjust( me );
sgVec3Slider *me = (sgVec3Slider *)PO_vec -> getUserData(); FG_PUSH_PUI_DIALOG( me );
me -> stashVec();
me -> adjust( me );
FG_PUSH_PUI_DIALOG( me );
} }
sgVec3 *PilotOffsetGet() sgVec3 *PilotOffsetGet()
{ {
if( PO_vec == 0 ) { if( PO_vec == 0 ) {
sgVec3 v; PilotOffsetInit();
// we seem to need the ~quite zero terms ??? }
sgSetVec3(v,25,0.0001,0.0001); sgVec3Slider *me = (sgVec3Slider *)PO_vec -> getUserData();
PilotOffsetInit(v); return( me -> getVec() );
} }
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
} }

View file

@ -14,8 +14,11 @@
#include <stdio.h> #include <stdio.h>
#include "gui.h" #include "gui.h"
void PilotOffsetInit();
void PilotOffsetInit( sgVec3 vec ); void PilotOffsetInit( sgVec3 vec );
void PilotOffsetAdjust( puObject * ); void PilotOffsetAdjust( puObject * );
void Vec3FromHeadingPitchRadius( sgVec3 vec3, float heading, float pitch, float radius );
//void PilotOffsetGet( float *po ); //void PilotOffsetGet( float *po );
sgVec3 *PilotOffsetGet(); sgVec3 *PilotOffsetGet();
#endif // _VEC3_SLIDER_H #endif // _VEC3_SLIDER_H